diff options
| author | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2018-12-04 00:47:30 +0300 |
|---|---|---|
| committer | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2018-12-04 00:47:30 +0300 |
| commit | 9e5b1546305a8ac245a1b2cfe14446c0797308ac (patch) | |
| tree | c787a7c8dd4514f8f1da9564e15f7df90b396616 | |
| parent | added initial logging to git package (diff) | |
| download | gitbatch-9e5b1546305a8ac245a1b2cfe14446c0797308ac.tar.gz | |
reverse scrolling on commits implemented
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | pkg/git/commit.go | 16 | ||||
| -rw-r--r-- | pkg/gui/commitsview.go | 13 | ||||
| -rw-r--r-- | pkg/gui/keybindings.go | 8 |
4 files changed, 38 insertions, 1 deletions
@@ -78,7 +78,7 @@ run the `gitbatch` command from the parent of your git repositories. For start-u - add testing - select all feature - arrange repositories to an order e.g. alphabetic, last modified, etc. -- shift keys, i.e. **s** for iterate **shift + s** for reverse iteration +- shift keys, i.e. **s** for iterate **alt + s** for reverse iteration (partially implemented) - recursive repository search from the filesystem - full src-d/go-git integration (*having some performance issues*) - implement config file to pre-define repo locations or some settings diff --git a/pkg/git/commit.go b/pkg/git/commit.go index f51801d..a15b3a4 100644 --- a/pkg/git/commit.go +++ b/pkg/git/commit.go @@ -47,6 +47,22 @@ func (entity *RepoEntity) NextCommit() error { return nil } +// PreviousCommit iterates to opposite direction +func (entity *RepoEntity) PreviousCommit() error { + currentCommitIndex := 0 + for i, cs := range entity.Commits { + if cs.Hash == entity.Commit.Hash { + currentCommitIndex = i + } + } + if currentCommitIndex == 0 { + entity.Commit = entity.Commits[len(entity.Commits)-1] + return nil + } + entity.Commit = entity.Commits[currentCommitIndex-1] + return nil +} + // loads the local commits by simply using git log way. ALso, gets the upstream // diff commits func (entity *RepoEntity) loadCommits() error { diff --git a/pkg/gui/commitsview.go b/pkg/gui/commitsview.go index 27abc69..91cb795 100644 --- a/pkg/gui/commitsview.go +++ b/pkg/gui/commitsview.go @@ -50,3 +50,16 @@ func (gui *Gui) nextCommit(g *gocui.Gui, v *gocui.View) error { } return err } + +// reverse iteration handler for the commitsview +func (gui *Gui) prevCommit(g *gocui.Gui, v *gocui.View) error { + var err error + entity := gui.getSelectedRepository() + if err = entity.PreviousCommit(); err != nil { + return err + } + if err = gui.updateCommits(g, entity); err != nil { + return err + } + return err +} diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index df3e4d8..f224bc3 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -109,6 +109,14 @@ func (gui *Gui) generateKeybindings() error { Display: "s", Description: "Iterate over commits", Vital: false, + },{ + View: mainViewFeature.Name, + Key: 's', + Modifier: gocui.ModAlt, + Handler: gui.prevCommit, + Display: "alt + s", + Description: "Iterate over commits", + Vital: false, }, { View: mainViewFeature.Name, Key: 'd', |
