diff options
| author | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2018-12-16 22:12:18 +0300 |
|---|---|---|
| committer | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2018-12-16 22:12:18 +0300 |
| commit | da887d1c197b16bbf9e4c9457641b8acf22ce3aa (patch) | |
| tree | d1614dce8bd5ef92614932a0a91046e1124d0422 | |
| parent | app args and configuration handle revised (diff) | |
| download | gitbatch-da887d1c197b16bbf9e4c9457641b8acf22ce3aa.tar.gz | |
add option to set upstream to branch and minor improvements
| -rw-r--r-- | pkg/app/quick.go | 8 | ||||
| -rw-r--r-- | pkg/git/cmd-config.go | 8 | ||||
| -rw-r--r-- | pkg/git/cmd-fetch.go | 8 | ||||
| -rw-r--r-- | pkg/gui/keybindings.go | 26 | ||||
| -rw-r--r-- | pkg/gui/sideviews.go | 49 |
5 files changed, 90 insertions, 9 deletions
diff --git a/pkg/app/quick.go b/pkg/app/quick.go index 0a845c4..fba5d8f 100644 --- a/pkg/app/quick.go +++ b/pkg/app/quick.go @@ -1,11 +1,11 @@ package app import ( + "fmt" "sync" "time" "github.com/isacikgoz/gitbatch/pkg/git" - log "github.com/sirupsen/logrus" ) func quick(directories []string, depth int, mode string) { @@ -18,13 +18,15 @@ func quick(directories []string, depth int, mode string) { defer wg.Done() err := operate(d, mode) if err != nil { - log.Errorf("%s: %s", d, err.Error()) + fmt.Printf("%s: %s\n", d, err.Error()) + } else { + fmt.Printf("%s: successful\n", d) } }(dir, mode) } wg.Wait() elapsed := time.Since(start) - log.Infof("%d repositories finished in: %s\n", len(directories), elapsed) + fmt.Printf("%d repositories finished in: %s\n", len(directories), elapsed) } func operate(directory, mode string) error { diff --git a/pkg/git/cmd-config.go b/pkg/git/cmd-config.go index 541b0be..dfbf661 100644 --- a/pkg/git/cmd-config.go +++ b/pkg/git/cmd-config.go @@ -28,7 +28,7 @@ type ConfigSite string const ( // ConfigStieLocal - ConfigStieLocal ConfigSite = "local" + ConfigSiteLocal ConfigSite = "local" // ConfgiSiteGlobal ConfgiSiteGlobal ConfigSite = "global" ) @@ -86,10 +86,10 @@ func AddConfig(entity *RepoEntity, options ConfigOptions, value string) (err err } -// addConfigWithGit is simply a bare git commit -m <msg> command which is flexible +// addConfigWithGit is simply a bare git config --add <option> command which is flexible func addConfigWithGit(entity *RepoEntity, options ConfigOptions, value string) (err error) { args := make([]string, 0) - args = append(args, commitCommand) + args = append(args, configCommand) if len(string(options.Site)) > 0 { args = append(args, "--"+string(options.Site)) } @@ -99,7 +99,7 @@ func addConfigWithGit(entity *RepoEntity, options ConfigOptions, value string) ( args = append(args, value) } if err := GenericGitCommand(entity.AbsPath, args); err != nil { - log.Warn("Error at git command (commit)") + log.Warn("Error at git command (config)") return err } // till this step everything should be ok diff --git a/pkg/git/cmd-fetch.go b/pkg/git/cmd-fetch.go index df600b3..d1d6abb 100644 --- a/pkg/git/cmd-fetch.go +++ b/pkg/git/cmd-fetch.go @@ -54,7 +54,13 @@ func Fetch(entity *RepoEntity, options FetchOptions) (err error) { return err case fetchCmdModeNative: // this should be the refspec as default, let's give it a try - refspec := "+" + "refs/heads/" + entity.Branch.Name + ":" + "/refs/remotes/" + entity.Remote.Branch.Name + // TODO: Fix for quick mode, maybe better read config file + var refspec string + if entity.Branch == nil { + refspec = "+refs/heads/*:refs/remotes/origin/*" + } else { + refspec = "+" + "refs/heads/" + entity.Branch.Name + ":" + "/refs/remotes/" + entity.Remote.Branch.Name + } err = fetchWithGoGit(entity, options, refspec) return err } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 6f21fab..eff7952 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -421,6 +421,14 @@ func (gui *Gui) generateKeybindings() error { Description: "Synch with Remote", Vital: true, }, { + View: branchViewFeature.Name, + Key: 'u', + Modifier: gocui.ModNone, + Handler: gui.setUpstreamToBranch, + Display: "u", + Description: "Set Upstream", + Vital: true, + }, { View: commitViewFeature.Name, Key: 'd', Modifier: gocui.ModNone, @@ -429,6 +437,24 @@ func (gui *Gui) generateKeybindings() error { Description: "Show commit diff", Vital: true, }, + // upstream confirmation + { + View: confirmationViewFeature.Name, + Key: gocui.KeyEsc, + Modifier: gocui.ModNone, + Handler: gui.closeConfirmationView, + Display: "esc", + Description: "close/cancel", + Vital: true, + }, { + View: confirmationViewFeature.Name, + Key: gocui.KeyEnter, + Modifier: gocui.ModNone, + Handler: gui.confirmSetUpstreamToBranch, + Display: "enter", + Description: "Set Upstream", + Vital: true, + }, // Diff View Controls { View: diffViewFeature.Name, diff --git a/pkg/gui/sideviews.go b/pkg/gui/sideviews.go index 57518f3..86aa3cb 100644 --- a/pkg/gui/sideviews.go +++ b/pkg/gui/sideviews.go @@ -8,7 +8,8 @@ import ( ) var ( - sideViews = []viewFeature{remoteViewFeature, remoteBranchViewFeature, branchViewFeature, commitViewFeature} + confirmationViewFeature = viewFeature{Name: "confirmation", Title: " Confirmation "} + sideViews = []viewFeature{remoteViewFeature, remoteBranchViewFeature, branchViewFeature, commitViewFeature} ) // updates the remotesview for given entity @@ -211,6 +212,52 @@ func (gui *Gui) syncRemoteBranch(g *gocui.Gui, v *gocui.View) error { return err } +// basically does fetch --prune +func (gui *Gui) setUpstreamToBranch(g *gocui.Gui, v *gocui.View) error { + maxX, maxY := g.Size() + + entity := gui.getSelectedRepository() + v, err := g.SetView(confirmationViewFeature.Name, maxX/2-30, maxY/2-2, maxX/2+30, maxY/2+2) + if err != nil { + if err != gocui.ErrUnknownView { + return err + } + fmt.Fprintln(v, "branch."+entity.Branch.Name+"."+"remote"+"="+entity.Remote.Name) + fmt.Fprintln(v, "branch."+entity.Branch.Name+"."+"merge"+"="+entity.Branch.Reference.Name().String()) + } + return gui.focusToView(confirmationViewFeature.Name) +} + +// basically does fetch --prune +func (gui *Gui) confirmSetUpstreamToBranch(g *gocui.Gui, v *gocui.View) error { + var err error + entity := gui.getSelectedRepository() + if err = git.AddConfig(entity, git.ConfigOptions{ + Section: "branch." + entity.Branch.Name, + Option: "remote", + Site: git.ConfigSiteLocal, + }, entity.Remote.Name); err != nil { + return err + } + if err = git.AddConfig(entity, git.ConfigOptions{ + Section: "branch." + entity.Branch.Name, + Option: "merge", + Site: git.ConfigSiteLocal, + }, entity.Branch.Reference.Name().String()); err != nil { + return err + } + entity.Refresh() + gui.refreshMain(g) + return gui.closeConfirmationView(g, v) +} + +func (gui *Gui) closeConfirmationView(g *gocui.Gui, v *gocui.View) error { + if err := g.DeleteView(v.Name()); err != nil { + return err + } + return gui.closeViewCleanup(branchViewFeature.Name) +} + // after checkout a remote some refreshments needed func (gui *Gui) remoteChangeFollowUp(g *gocui.Gui, entity *git.RepoEntity) (err error) { if err = gui.updateRemotes(g, entity); err != nil { |
