diff options
| author | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2018-11-29 01:55:59 +0300 |
|---|---|---|
| committer | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2018-11-29 01:55:59 +0300 |
| commit | 59a8c3062c3d1ee5e3778b959142c8094c9abc83 (patch) | |
| tree | 3666acb28bdbe244bbe7ec69b8d030de836da6e3 | |
| parent | minor style changes (diff) | |
| download | gitbatch-59a8c3062c3d1ee5e3778b959142c8094c9abc83.tar.gz | |
show remote commits added
| -rw-r--r-- | pkg/git/branch.go | 31 | ||||
| -rw-r--r-- | pkg/git/commit.go | 27 | ||||
| -rw-r--r-- | pkg/git/git-commands.go | 27 | ||||
| -rw-r--r-- | pkg/gui/commitsview.go | 12 |
4 files changed, 71 insertions, 26 deletions
diff --git a/pkg/git/branch.go b/pkg/git/branch.go index 138ff62..b1d0204 100644 --- a/pkg/git/branch.go +++ b/pkg/git/branch.go @@ -5,6 +5,7 @@ import ( "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/plumbing" "strings" + "regexp" ) type Branch struct { @@ -112,24 +113,24 @@ func (entity *RepoEntity) RefreshPushPull() { entity.Branch.Pushables, entity.Branch.Pullables = UpstreamDifferenceCount(entity.AbsPath) } -func (entity *RepoEntity) PushDiffsToUpstream() error { - hashes := UpstreamPushDiffs(entity.AbsPath) - if hashes != "?" { - sliced := strings.Split(hashes, "\n") - for _, s := range sliced { - GitShow(entity.AbsPath, s) - } - } - return nil -} - -func (entity *RepoEntity) PullDiffsToUpstream() error { +func (entity *RepoEntity) pullDiffsToUpstream() ([]*Commit, error) { + remoteCommits := make([]*Commit, 0) hashes := UpstreamPullDiffs(entity.AbsPath) + re := regexp.MustCompile(`\r?\n`) if hashes != "?" { sliced := strings.Split(hashes, "\n") for _, s := range sliced { - GitShow(entity.AbsPath, s) + if len(s) == 40 { + commit := &Commit{ + Hash: s, + Author: GitShowEmail(entity.AbsPath, s), + Message: re.ReplaceAllString(GitShowBody(entity.AbsPath, s), " "), + Time: GitShowDate(entity.AbsPath, s), + CommitType: RemoteCommit, + } + remoteCommits = append(remoteCommits, commit) + } } } - return nil -}
\ No newline at end of file + return remoteCommits, nil +} diff --git a/pkg/git/commit.go b/pkg/git/commit.go index 9027958..2021a0c 100644 --- a/pkg/git/commit.go +++ b/pkg/git/commit.go @@ -2,7 +2,6 @@ package git import ( "regexp" - "time" "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/plumbing" @@ -17,13 +16,16 @@ type Commit struct { Hash string Author string Message string - Time time.Time + Time string + CommitType CommitType } -func newCommit(hash, author, message string, time time.Time) (commit *Commit) { - commit = &Commit{hash, author, message, time} - return commit -} +type CommitType string + +const ( + LocalCommit CommitType = "local" + RemoteCommit CommitType = "remote" +) func (entity *RepoEntity) NextCommit() error { currentCommitIndex := 0 @@ -56,11 +58,20 @@ func (entity *RepoEntity) loadCommits() error { return err } defer cIter.Close() - + rmcs, err := entity.pullDiffsToUpstream() + for _, rmc := range rmcs { + entity.Commits = append(entity.Commits, rmc) + } // ... just iterates over the commits err = cIter.ForEach(func(c *object.Commit) error { re := regexp.MustCompile(`\r?\n`) - commit := newCommit(re.ReplaceAllString(c.Hash.String(), " "), c.Author.Email, re.ReplaceAllString(c.Message, " "), c.Author.When) + commit := &Commit{ + Hash: re.ReplaceAllString(c.Hash.String(), " "), + Author: c.Author.Email, + Message: re.ReplaceAllString(c.Message, " "), + Time: c.Author.When.String(), + CommitType: LocalCommit, + } entity.Commits = append(entity.Commits, commit) return nil diff --git a/pkg/git/git-commands.go b/pkg/git/git-commands.go index 1dbb73c..82dad46 100644 --- a/pkg/git/git-commands.go +++ b/pkg/git/git-commands.go @@ -50,6 +50,33 @@ func GitShow(repoPath, hash string) string { return diff } +func GitShowEmail(repoPath, hash string) string { + args := []string{"show", "--quiet", "--pretty=format:%ae", hash} + diff, err := command.RunCommandWithOutput(repoPath, "git", args) + if err != nil { + return "?" + } + return diff +} + +func GitShowBody(repoPath, hash string) string { + args := []string{"show", "--quiet", "--pretty=format:%B", hash} + diff, err := command.RunCommandWithOutput(repoPath, "git", args) + if err != nil { + return err.Error() + } + return diff +} + +func GitShowDate(repoPath, hash string) string { + args := []string{"show", "--quiet", "--pretty=format:%ai", hash} + diff, err := command.RunCommandWithOutput(repoPath, "git", args) + if err != nil { + return "?" + } + return diff +} + func (entity *RepoEntity) FetchWithGit(remote string) error { args := []string{"fetch", remote} _, err := command.RunCommandWithOutput(entity.AbsPath, "git", args) diff --git a/pkg/gui/commitsview.go b/pkg/gui/commitsview.go index 81c81bd..113bdbe 100644 --- a/pkg/gui/commitsview.go +++ b/pkg/gui/commitsview.go @@ -20,12 +20,18 @@ func (gui *Gui) updateCommits(g *gocui.Gui, entity *git.RepoEntity) error { currentindex := 0 totalcommits := len(entity.Commits) for i, c := range entity.Commits { + var body string = "" + if c.CommitType == git.LocalCommit { + body = cyan.Sprint(c.Hash[:git.Hashlimit])+" "+c.Message + } else { + body = yellow.Sprint(c.Hash[:git.Hashlimit])+" "+c.Message + } if c.Hash == entity.Commit.Hash { currentindex = i - fmt.Fprintln(out, selectionIndicator+green.Sprint(c.Hash[:git.Hashlimit])+" "+c.Message) + fmt.Fprintln(out, selectionIndicator+body) continue } - fmt.Fprintln(out, tab+cyan.Sprint(c.Hash[:git.Hashlimit])+" "+c.Message) + fmt.Fprintln(out, tab+body) } if err = gui.smartAnchorRelativeToLine(out, currentindex, totalcommits); err != nil { return err @@ -66,7 +72,7 @@ func (gui *Gui) showCommitDetail(g *gocui.Gui, v *gocui.View) error { return err } commit := entity.Commit - commitDetail := "Hash: " + cyan.Sprint(commit.Hash) + "\n" + "Author: " + commit.Author + "\n" + commit.Time.String() + "\n" + "\n" + "\t\t" + commit.Message + "\n" + commitDetail := "Hash: " + cyan.Sprint(commit.Hash) + "\n" + "Author: " + commit.Author + "\n" + commit.Time + "\n" + "\n" + "\t\t" + commit.Message + "\n" fmt.Fprintln(v, commitDetail) diff, err := entity.Diff(entity.Commit.Hash) if err != nil { |
