summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--pkg/app/config.go6
-rw-r--r--pkg/app/files.go5
-rw-r--r--pkg/git/add.go3
-rw-r--r--pkg/git/remote.go13
-rw-r--r--pkg/git/repository.go12
-rw-r--r--pkg/git/rev-list.go3
-rw-r--r--pkg/gui/branchview.go36
-rw-r--r--pkg/gui/gui-util.go6
-rw-r--r--pkg/gui/gui.go13
-rw-r--r--pkg/gui/remotebranchview.go18
-rw-r--r--pkg/gui/remotesview.go6
-rw-r--r--pkg/gui/stagedview.go12
-rw-r--r--pkg/gui/stashview.go18
-rw-r--r--pkg/gui/statusview.go12
-rw-r--r--pkg/gui/unstagedview.go18
16 files changed, 67 insertions, 115 deletions
diff --git a/README.md b/README.md
index e3bfdd7..ee27f58 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,7 @@ run the `gitbatch` command from the parent of your git repositories. For start-u
For more information;
- [Controls page](https://github.com/isacikgoz/gitbatch/wiki/Controls)
+- [Configuration page](https://github.com/isacikgoz/gitbatch/wiki/Configuration)
- [Modes page](https://github.com/isacikgoz/gitbatch/wiki/Modes)
- [Display page](https://github.com/isacikgoz/gitbatch/wiki/Display)
diff --git a/pkg/app/config.go b/pkg/app/config.go
index 94052e6..b613532 100644
--- a/pkg/app/config.go
+++ b/pkg/app/config.go
@@ -80,10 +80,8 @@ func readConfiguration() error {
// write configuration to a file
func writeConfiguration() error {
- if err := viper.WriteConfig(); err != nil {
- return err
- }
- return nil
+ err := viper.WriteConfig()
+ return err
}
// initialize the configuration manager
diff --git a/pkg/app/files.go b/pkg/app/files.go
index b6ec662..25e5074 100644
--- a/pkg/app/files.go
+++ b/pkg/app/files.go
@@ -74,12 +74,15 @@ func seperateDirectories(directory string) (directories, gitDirectories []string
return nil, nil, err
}
// with this approach, we ignore submodule or sub repositoreis in a git repository
- _, err = os.Open(dir + string(os.PathSeparator) + ".git")
+ ff, err := os.Open(dir + string(os.PathSeparator) + ".git")
if err != nil {
directories = append(directories, dir)
} else {
gitDirectories = append(gitDirectories, dir)
}
+ ff.Close()
+ file.Close()
+
}
return directories, gitDirectories, nil
}
diff --git a/pkg/git/add.go b/pkg/git/add.go
index 6abb868..61fd587 100644
--- a/pkg/git/add.go
+++ b/pkg/git/add.go
@@ -9,12 +9,14 @@ import (
var addCommand = "add"
+// AddOptions defines the rules for "git add" command
type AddOptions struct {
Update bool
Force bool
DryRun bool
}
+// Add is a wrapper function for "git add" command
func (file *File) Add(option AddOptions) error {
args := make([]string, 0)
args = append(args, addCommand)
@@ -36,6 +38,7 @@ func (file *File) Add(option AddOptions) error {
return nil
}
+// AddAll function is the wrapper of "git add ." command
func (entity *RepoEntity) AddAll(option AddOptions) error {
args := make([]string, 0)
args = append(args, addCommand)
diff --git a/pkg/git/remote.go b/pkg/git/remote.go
index 62eb0db..96b8aa7 100644
--- a/pkg/git/remote.go
+++ b/pkg/git/remote.go
@@ -22,10 +22,8 @@ func (entity *RepoEntity) NextRemote() error {
} else {
entity.Remote = entity.Remotes[currentRemoteIndex+1]
}
- if err := entity.Remote.SyncBranches(entity.Branch.Name); err != nil {
- return err
- }
- return nil
+ err := entity.Remote.SyncBranches(entity.Branch.Name)
+ return err
}
// PreviousRemote iterates over previous branch of a remote
@@ -36,10 +34,8 @@ func (entity *RepoEntity) PreviousRemote() error {
} else {
entity.Remote = entity.Remotes[currentRemoteIndex-1]
}
- if err := entity.Remote.SyncBranches(entity.Branch.Name); err != nil {
- return err
- }
- return nil
+ err := entity.Remote.SyncBranches(entity.Branch.Name)
+ return err
}
// returns the active remote index
@@ -80,6 +76,7 @@ func (entity *RepoEntity) loadRemotes() error {
return err
}
+// SyncBranches sets the remote branch according to repository's active branch
func (remote *Remote) SyncBranches(branchName string) error {
if err := remote.switchRemoteBranch(remote.Name + "/" + branchName); err != nil {
// probably couldn't find, but its ok.
diff --git a/pkg/git/repository.go b/pkg/git/repository.go
index b127305..8d0160b 100644
--- a/pkg/git/repository.go
+++ b/pkg/git/repository.go
@@ -37,7 +37,7 @@ const (
Available RepoState = 0
// Queued means repo is queued for a operation
Queued RepoState = 1
- // Working means an operation is jsut started for this repository
+ // Working means an operation is just started for this repository
Working RepoState = 2
// Success is the expected outcome of the operation
Success RepoState = 3
@@ -51,7 +51,7 @@ func InitializeRepository(directory string) (entity *RepoEntity, err error) {
if err != nil {
log.WithFields(log.Fields{
"directory": directory,
- }).Trace("Cannot open as direcotry")
+ }).Trace("Cannot open as directory")
return nil, err
}
fileInfo, err := file.Stat()
@@ -62,7 +62,7 @@ func InitializeRepository(directory string) (entity *RepoEntity, err error) {
if err != nil {
log.WithFields(log.Fields{
"directory": directory,
- }).Trace("Cannot open direcotry as a git repository")
+ }).Trace("Cannot open directory as a git repository")
return nil, err
}
entity = &RepoEntity{RepoID: helpers.RandomString(8),
@@ -132,8 +132,6 @@ func (entity *RepoEntity) Refresh() error {
if err := entity.loadRemotes(); err != nil {
return err
}
- if err := entity.loadStashedItems(); err != nil {
- return err
- }
- return nil
+ err = entity.loadStashedItems()
+ return err
}
diff --git a/pkg/git/rev-list.go b/pkg/git/rev-list.go
index 5debe47..664d69f 100644
--- a/pkg/git/rev-list.go
+++ b/pkg/git/rev-list.go
@@ -35,9 +35,8 @@ func RevList(entity *RepoEntity, options RevListOptions) ([]string, error) {
for _, hash := range hashes {
if len(hash) != hashLength {
return make([]string, 0), nil
- } else {
- break
}
+ break
}
return hashes, nil
}
diff --git a/pkg/gui/branchview.go b/pkg/gui/branchview.go
index c955cf0..f69a212 100644
--- a/pkg/gui/branchview.go
+++ b/pkg/gui/branchview.go
@@ -26,10 +26,8 @@ func (gui *Gui) updateBranch(g *gocui.Gui, entity *git.RepoEntity) error {
}
fmt.Fprintln(out, tab+b.Name)
}
- if err = gui.smartAnchorRelativeToLine(out, currentindex, totalbranches); err != nil {
- return err
- }
- return nil
+ err = gui.smartAnchorRelativeToLine(out, currentindex, totalbranches)
+ return err
}
// iteration handler for the branchview
@@ -37,17 +35,13 @@ func (gui *Gui) nextBranch(g *gocui.Gui, v *gocui.View) error {
var err error
entity := gui.getSelectedRepository()
if err = entity.Checkout(entity.NextBranch()); err != nil {
- if err = gui.openErrorView(g, err.Error(),
+ err = gui.openErrorView(g, err.Error(),
"You should manually resolve this issue",
- branchViewFeature.Name); err != nil {
- return err
- }
- return nil
- }
- if err = gui.checkoutFollowUp(g, entity); err != nil {
+ branchViewFeature.Name)
return err
}
- return nil
+ err = gui.checkoutFollowUp(g, entity)
+ return err
}
// iteration handler for the branchview
@@ -55,17 +49,13 @@ func (gui *Gui) previousBranch(g *gocui.Gui, v *gocui.View) error {
var err error
entity := gui.getSelectedRepository()
if err = entity.Checkout(entity.PreviousBranch()); err != nil {
- if err = gui.openErrorView(g, err.Error(),
+ err = gui.openErrorView(g, err.Error(),
"You should manually resolve this issue",
- branchViewFeature.Name); err != nil {
- return err
- }
- return nil
- }
- if err = gui.checkoutFollowUp(g, entity); err != nil {
+ branchViewFeature.Name)
return err
}
- return nil
+ err = gui.checkoutFollowUp(g, entity)
+ return err
}
// after checkout a branch some refreshments needed
@@ -79,8 +69,6 @@ func (gui *Gui) checkoutFollowUp(g *gocui.Gui, entity *git.RepoEntity) (err erro
if err = gui.updateRemoteBranches(g, entity); err != nil {
return err
}
- if err = gui.refreshMain(g); err != nil {
- return err
- }
- return nil
+ err = gui.refreshMain(g)
+ return err
}
diff --git a/pkg/gui/gui-util.go b/pkg/gui/gui-util.go
index 2462723..bd02f7c 100644
--- a/pkg/gui/gui-util.go
+++ b/pkg/gui/gui-util.go
@@ -116,10 +116,8 @@ func (gui *Gui) correctCursor(v *gocui.View) error {
if err := v.SetCursor(cx, newCy); err != nil {
return err
}
- if err := v.SetOrigin(ox, ly-newCy); err != nil {
- return err
- }
- return nil
+ err := v.SetOrigin(ox, ly-newCy)
+ return err
}
// this function handles the iteration of a side view and set its origin point
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 0cf9458..2e75b4a 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -203,20 +203,15 @@ func (gui *Gui) layout(g *gocui.Gui) error {
// focus to next view
func (gui *Gui) nextMainView(g *gocui.Gui, v *gocui.View) error {
- if err := gui.nextViewOfGroup(g, v, mainViews); err != nil {
- return err
- }
- return nil
+ err := gui.nextViewOfGroup(g, v, mainViews)
+ return err
}
// focus to previous view
func (gui *Gui) previousMainView(g *gocui.Gui, v *gocui.View) error {
- if err := gui.previousViewOfGroup(g, v, mainViews); err != nil {
- return err
- }
- return nil
+ err := gui.previousViewOfGroup(g, v, mainViews)
+ return err
}
-
// quit from the gui and end its loop
func (gui *Gui) quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
diff --git a/pkg/gui/remotebranchview.go b/pkg/gui/remotebranchview.go
index 6c58565..4974808 100644
--- a/pkg/gui/remotebranchview.go
+++ b/pkg/gui/remotebranchview.go
@@ -51,10 +51,8 @@ func (gui *Gui) syncRemoteBranch(g *gocui.Gui, v *gocui.View) error {
// some time need to fix, movement aint bad huh?
gui.nextRemote(g, v)
gui.previousRemote(g, v)
- if err = gui.updateRemoteBranches(g, entity); err != nil {
- return err
- }
- return nil
+ err = gui.updateRemoteBranches(g, entity)
+ return err
}
// iteration handler for the remotebranchview
@@ -64,10 +62,8 @@ func (gui *Gui) nextRemoteBranch(g *gocui.Gui, v *gocui.View) error {
if err = entity.Remote.NextRemoteBranch(); err != nil {
return err
}
- if err = gui.updateRemoteBranches(g, entity); err != nil {
- return err
- }
- return nil
+ err = gui.updateRemoteBranches(g, entity)
+ return err
}
// iteration handler for the remotebranchview
@@ -77,8 +73,6 @@ func (gui *Gui) previousRemoteBranch(g *gocui.Gui, v *gocui.View) error {
if err = entity.Remote.PreviousRemoteBranch(); err != nil {
return err
}
- if err = gui.updateRemoteBranches(g, entity); err != nil {
- return err
- }
- return nil
+ err = gui.updateRemoteBranches(g, entity)
+ return err
}
diff --git a/pkg/gui/remotesview.go b/pkg/gui/remotesview.go
index 55366b2..51323dc 100644
--- a/pkg/gui/remotesview.go
+++ b/pkg/gui/remotesview.go
@@ -68,8 +68,6 @@ func (gui *Gui) remoteChangeFollowUp(g *gocui.Gui, entity *git.RepoEntity) (err
if err = gui.updateRemotes(g, entity); err != nil {
return err
}
- if err = gui.updateRemoteBranches(g, entity); err != nil {
- return err
- }
- return nil
+ err = gui.updateRemoteBranches(g, entity)
+ return err
}
diff --git a/pkg/gui/stagedview.go b/pkg/gui/stagedview.go
index 3e83a96..e27d35d 100644
--- a/pkg/gui/stagedview.go
+++ b/pkg/gui/stagedview.go
@@ -43,10 +43,8 @@ func (gui *Gui) resetChanges(g *gocui.Gui, v *gocui.View) error {
if err := files[cy+oy].Reset(git.ResetOptions{}); err != nil {
return err
}
- if err := refreshAllStatusView(g, entity); err != nil {
- return err
- }
- return nil
+ err = refreshAllStatusView(g, entity)
+ return err
}
func (gui *Gui) resetAllChanges(g *gocui.Gui, v *gocui.View) error {
@@ -54,10 +52,8 @@ func (gui *Gui) resetAllChanges(g *gocui.Gui, v *gocui.View) error {
if err := entity.ResetAll(git.ResetOptions{}); err != nil {
return err
}
- if err := refreshAllStatusView(g, entity); err != nil {
- return err
- }
- return nil
+ err := refreshAllStatusView(g, entity)
+ return err
}
// refresh the main view and re-render the repository representations
diff --git a/pkg/gui/stashview.go b/pkg/gui/stashview.go
index cfdc104..54a05db 100644
--- a/pkg/gui/stashview.go
+++ b/pkg/gui/stashview.go
@@ -19,10 +19,8 @@ func (gui *Gui) openStashView(g *gocui.Gui) error {
v.Title = stashViewFeature.Title
}
entity := gui.getSelectedRepository()
- if err := refreshStashView(g, entity); err != nil {
- return err
- }
- return nil
+ err = refreshStashView(g, entity)
+ return err
}
//
@@ -36,10 +34,8 @@ func (gui *Gui) stashChanges(g *gocui.Gui, v *gocui.View) error {
return err
}
}
- if err := refreshAllStatusView(g, entity); err != nil {
- return err
- }
- return nil
+ err = refreshAllStatusView(g, entity)
+ return err
}
//
@@ -62,10 +58,8 @@ func (gui *Gui) popStash(g *gocui.Gui, v *gocui.View) error {
if err := entity.Refresh(); err != nil {
return err
}
- if err := refreshAllStatusView(g, entity); err != nil {
- return err
- }
- return nil
+ err = refreshAllStatusView(g, entity)
+ return err
}
// refresh the main view and re-render the repository representations
diff --git a/pkg/gui/statusview.go b/pkg/gui/statusview.go
index d95a56f..282d643 100644
--- a/pkg/gui/statusview.go
+++ b/pkg/gui/statusview.go
@@ -28,18 +28,14 @@ func (gui *Gui) openStatusView(g *gocui.Gui, v *gocui.View) error {
// focus to next view
func (gui *Gui) nextStatusView(g *gocui.Gui, v *gocui.View) error {
- if err := gui.nextViewOfGroup(g, v, statusViews); err != nil {
- return err
- }
- return nil
+ err := gui.nextViewOfGroup(g, v, statusViews)
+ return err
}
// focus to previous view
func (gui *Gui) previousStatusView(g *gocui.Gui, v *gocui.View) error {
- if err := gui.previousViewOfGroup(g, v, statusViews); err != nil {
- return err
- }
- return nil
+ err := gui.previousViewOfGroup(g, v, statusViews)
+ return err
}
// moves the cursor downwards for the main view and if it goes to bottom it
diff --git a/pkg/gui/unstagedview.go b/pkg/gui/unstagedview.go
index 93082cc..ef4866f 100644
--- a/pkg/gui/unstagedview.go
+++ b/pkg/gui/unstagedview.go
@@ -19,10 +19,8 @@ func (gui *Gui) openUnStagedView(g *gocui.Gui) error {
v.Title = unstageViewFeature.Title
}
entity := gui.getSelectedRepository()
- if err := refreshUnstagedView(g, entity); err != nil {
- return err
- }
- return nil
+ err = refreshUnstagedView(g, entity)
+ return err
}
func (gui *Gui) addChanges(g *gocui.Gui, v *gocui.View) error {
@@ -39,10 +37,8 @@ func (gui *Gui) addChanges(g *gocui.Gui, v *gocui.View) error {
if err := files[cy+oy].Add(git.AddOptions{}); err != nil {
return err
}
- if err := refreshAllStatusView(g, entity); err != nil {
- return err
- }
- return nil
+ err = refreshAllStatusView(g, entity)
+ return err
}
func (gui *Gui) addAllChanges(g *gocui.Gui, v *gocui.View) error {
@@ -50,10 +46,8 @@ func (gui *Gui) addAllChanges(g *gocui.Gui, v *gocui.View) error {
if err := entity.AddAll(git.AddOptions{}); err != nil {
return err
}
- if err := refreshAllStatusView(g, entity); err != nil {
- return err
- }
- return nil
+ err := refreshAllStatusView(g, entity)
+ return err
}
// refresh the main view and re-render the repository representations