diff options
| -rw-r--r-- | main.go | 3 | ||||
| -rw-r--r-- | pkg/app/app.go | 12 | ||||
| -rw-r--r-- | pkg/app/files.go | 10 | ||||
| -rw-r--r-- | pkg/git/branch.go | 24 | ||||
| -rw-r--r-- | pkg/git/commit.go | 30 | ||||
| -rw-r--r-- | pkg/git/git-commands.go | 2 | ||||
| -rw-r--r-- | pkg/git/remote.go | 2 | ||||
| -rw-r--r-- | pkg/git/remotebranch.go | 2 | ||||
| -rw-r--r-- | pkg/git/repository.go | 12 | ||||
| -rw-r--r-- | pkg/gui/branchview.go | 2 | ||||
| -rw-r--r-- | pkg/gui/commitsview.go | 10 | ||||
| -rw-r--r-- | pkg/gui/diffview.go | 2 | ||||
| -rw-r--r-- | pkg/gui/errorview.go | 2 | ||||
| -rw-r--r-- | pkg/gui/gui-util.go | 2 | ||||
| -rw-r--r-- | pkg/gui/gui.go | 13 | ||||
| -rw-r--r-- | pkg/gui/keybindings.go | 4 | ||||
| -rw-r--r-- | pkg/gui/mainview.go | 6 | ||||
| -rw-r--r-- | pkg/gui/textstyle.go | 36 | ||||
| -rw-r--r-- | pkg/helpers/utils.go | 2 | ||||
| -rw-r--r-- | pkg/queue/queue.go | 2 |
20 files changed, 93 insertions, 85 deletions
@@ -3,12 +3,11 @@ package main import ( "os" - log "github.com/sirupsen/logrus" "github.com/isacikgoz/gitbatch/pkg/app" + log "github.com/sirupsen/logrus" "gopkg.in/alecthomas/kingpin.v2" ) - var ( // take this as default directory if user does not start app with -d flag currentDir, err = os.Getwd() diff --git a/pkg/app/app.go b/pkg/app/app.go index 27dd58c..53bb34b 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -1,22 +1,21 @@ package app import ( - log "github.com/sirupsen/logrus" "github.com/isacikgoz/gitbatch/pkg/gui" + log "github.com/sirupsen/logrus" ) // The App struct is responsible to hold app-wide related entities. Currently // it has only the gui.Gui pointer for interface entity. type App struct { - Gui *gui.Gui + Gui *gui.Gui } // If any pre-required operation is needed, setup will handle that task. It is // designed to be a wrapper for main method right now. func Setup(directory, repoPattern, logLevel string) (*App, error) { // initiate the app and give it initial values - app := &App{ - } + app := &App{} setLogLevel(logLevel) var err error directories := generateDirectories(directory, repoPattern) @@ -29,6 +28,7 @@ func Setup(directory, repoPattern, logLevel string) (*App, error) { return app, err } // hopefull everything went smooth as butter + log.Trace("App configuration completed") return app, nil } @@ -55,6 +55,6 @@ func setLogLevel(logLevel string) { log.SetLevel(log.FatalLevel) } log.WithFields(log.Fields{ - "level": logLevel, - }).Trace("logging set to level") + "level": logLevel, + }).Trace("logging level has been set") } diff --git a/pkg/app/files.go b/pkg/app/files.go index c99ea5b..f6ae947 100644 --- a/pkg/app/files.go +++ b/pkg/app/files.go @@ -9,7 +9,7 @@ import ( log "github.com/sirupsen/logrus" ) -// generateDirectories is to find all the files in given path. This method +// generateDirectories is to find all the files in given path. This method // does not check if the given file is a valid git repositories func generateDirectories(directory string, repoPattern string) (directories []string) { files, err := ioutil.ReadDir(directory) @@ -30,9 +30,9 @@ func generateDirectories(directory string, repoPattern string) (directories []st // if we cannot open it, simply continue to iteration and don't consider if err != nil { log.WithFields(log.Fields{ - "file": file, - "directory": directory, - }).Trace("Failed to open file in the directory") + "file": file, + "directory": directory, + }).Trace("Failed to open file in the directory") continue } dir, err := filepath.Abs(file.Name()) @@ -46,7 +46,7 @@ func generateDirectories(directory string, repoPattern string) (directories []st return directories } -// takes a fileInfo slice and returns it with the ones matches with the +// takes a fileInfo slice and returns it with the ones matches with the // repoPattern string func filterDirectories(files []os.FileInfo, repoPattern string) []os.FileInfo { var filteredRepos []os.FileInfo diff --git a/pkg/git/branch.go b/pkg/git/branch.go index 8943b21..cd3e3f6 100644 --- a/pkg/git/branch.go +++ b/pkg/git/branch.go @@ -4,8 +4,8 @@ import ( "github.com/isacikgoz/gitbatch/pkg/helpers" "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/plumbing" - "strings" "regexp" + "strings" ) // Branch is the wrapper of go-git's Reference struct. In addition to that, it @@ -20,7 +20,7 @@ type Branch struct { Clean bool } -// returns the active branch of the repository entity by simply getting the +// returns the active branch of the repository entity by simply getting the // head reference and searching it from the entities branch slice func (entity *RepoEntity) getActiveBranch() (branch *Branch) { headRef, _ := entity.Repository.Head() @@ -32,7 +32,7 @@ func (entity *RepoEntity) getActiveBranch() (branch *Branch) { return nil } -// search for branches in go-git way. It is useful to do so that checkout and +// search for branches in go-git way. It is useful to do so that checkout and // checkout error handling can be handled by code rather than struggling with // git cammand and its output func (entity *RepoEntity) loadLocalBranches() error { @@ -93,14 +93,14 @@ func (entity *RepoEntity) Checkout(branch *Branch) error { entity.Branch.Pushables, entity.Branch.Pullables = UpstreamDifferenceCount(entity.AbsPath) // TODO: same code on 3 different occasion, maybe something wrong? // make this conditional on global scale - if err = entity.Remote.switchRemoteBranch(entity.Remote.Name + "/" + entity.Branch.Name); err !=nil { + if err = entity.Remote.switchRemoteBranch(entity.Remote.Name + "/" + entity.Branch.Name); err != nil { // probably couldn't find, but its ok. return nil } return nil } -// checking the branch if it has any changes from its head revision. Initially +// checking the branch if it has any changes from its head revision. Initially // I implemented this with go-git but it was incredibly slow and there is also // an issue about it: https://github.com/src-d/go-git/issues/844 func (entity *RepoEntity) isClean() bool { @@ -132,13 +132,13 @@ func (entity *RepoEntity) pullDiffsToUpstream() ([]*Commit, error) { for _, s := range sliced { 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) + 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) } } } diff --git a/pkg/git/commit.go b/pkg/git/commit.go index 9045555..974d1b3 100644 --- a/pkg/git/commit.go +++ b/pkg/git/commit.go @@ -8,22 +8,22 @@ import ( "gopkg.in/src-d/go-git.v4/plumbing/object" ) -// Commit is the lightweight version of go-git's Reference struct. it holds -// hash of the commit, author's e-mail address, Message (subject and body +// Commit is the lightweight version of go-git's Reference struct. it holds +// hash of the commit, author's e-mail address, Message (subject and body // combined) commit date and commit type wheter it is local commit or a remote type Commit struct { - Hash string - Author string - Message string - Time string - CommitType CommitType + Hash string + Author string + Message string + Time string + CommitType CommitType } // type of the commit; it can be local or remote (upstream diff) type CommitType string const ( - LocalCommit CommitType = "local" + LocalCommit CommitType = "local" RemoteCommit CommitType = "remote" ) @@ -63,6 +63,9 @@ func (entity *RepoEntity) loadCommits() error { } defer cIter.Close() rmcs, err := entity.pullDiffsToUpstream() + if err != nil { + return err + } for _, rmc := range rmcs { entity.Commits = append(entity.Commits, rmc) } @@ -70,10 +73,10 @@ func (entity *RepoEntity) loadCommits() error { err = cIter.ForEach(func(c *object.Commit) error { re := regexp.MustCompile(`\r?\n`) commit := &Commit{ - Hash: re.ReplaceAllString(c.Hash.String(), " "), - Author: c.Author.Email, - Message: re.ReplaceAllString(c.Message, " "), - Time: c.Author.When.String(), + 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) @@ -87,9 +90,8 @@ func (entity *RepoEntity) loadCommits() error { return nil } - // returns the diff to previous commit detail of the given hash of a specific -// commit +// commit func (entity *RepoEntity) Diff(hash string) (diff string, err error) { currentCommitIndex := 0 diff --git a/pkg/git/git-commands.go b/pkg/git/git-commands.go index fd56e1e..37aca64 100644 --- a/pkg/git/git-commands.go +++ b/pkg/git/git-commands.go @@ -131,4 +131,4 @@ func (entity *RepoEntity) StatusWithGit() string { return "?" } return status -}
\ No newline at end of file +} diff --git a/pkg/git/remote.go b/pkg/git/remote.go index b7bd907..035c68d 100644 --- a/pkg/git/remote.go +++ b/pkg/git/remote.go @@ -25,7 +25,7 @@ func (entity *RepoEntity) NextRemote() error { entity.Remote = entity.Remotes[currentRemoteIndex+1] } // TODO: same code on 3 different occasion, maybe something wrong? - if err := entity.Remote.switchRemoteBranch(entity.Remote.Name + "/" + entity.Branch.Name); err !=nil { + if err := entity.Remote.switchRemoteBranch(entity.Remote.Name + "/" + entity.Branch.Name); err != nil { // probably couldn't find, but its ok. } return nil diff --git a/pkg/git/remotebranch.go b/pkg/git/remotebranch.go index b37d3b7..1f46b3d 100644 --- a/pkg/git/remotebranch.go +++ b/pkg/git/remotebranch.go @@ -9,7 +9,7 @@ import ( "gopkg.in/src-d/go-git.v4/plumbing/storer" ) -// RemoteBranch is the wrapper of go-git's Reference struct. In addition to +// RemoteBranch is the wrapper of go-git's Reference struct. In addition to // that, it also holds name of the remote branch type RemoteBranch struct { Name string diff --git a/pkg/git/repository.go b/pkg/git/repository.go index 75495d0..f3c76bf 100644 --- a/pkg/git/repository.go +++ b/pkg/git/repository.go @@ -29,14 +29,14 @@ type RepoEntity struct { type RepoState uint8 const ( - Available RepoState = 0 + Available RepoState = 0 Queued RepoState = 1 Working RepoState = 2 Success RepoState = 3 Fail RepoState = 4 ) -// initializee a RepoEntity struct with its belongings. +// initializee a RepoEntity struct with its belongings. func InitializeRepository(directory string) (entity *RepoEntity, err error) { file, err := os.Open(directory) if err != nil { @@ -54,7 +54,7 @@ func InitializeRepository(directory string) (entity *RepoEntity, err error) { Name: fileInfo.Name(), AbsPath: directory, Repository: *r, - State: Available, + State: Available, } // after we intiate the struct we can fill its values entity.loadLocalBranches() @@ -74,8 +74,8 @@ func InitializeRepository(directory string) (entity *RepoEntity, err error) { // TODO: tend to take origin/master as default entity.Remote = entity.Remotes[0] // TODO: same code on 3 different occasion, maybe something wrong? - if err = entity.Remote.switchRemoteBranch(entity.Remote.Name + "/" + entity.Branch.Name); err !=nil { - // probably couldn't find, but its ok. + if err = entity.Remote.switchRemoteBranch(entity.Remote.Name + "/" + entity.Branch.Name); err != nil { + // probably couldn't find, but its ok. } } else { // if there is no remote, this project is totally useless actually @@ -116,7 +116,7 @@ func (entity *RepoEntity) Fetch() error { return nil } -// Incorporates changes from the named commits or branches into the current +// Incorporates changes from the named commits or branches into the current // branch func (entity *RepoEntity) Merge() error { entity.Checkout(entity.Branch) diff --git a/pkg/gui/branchview.go b/pkg/gui/branchview.go index cb6e32f..08a717f 100644 --- a/pkg/gui/branchview.go +++ b/pkg/gui/branchview.go @@ -41,7 +41,7 @@ func (gui *Gui) nextBranch(g *gocui.Gui, v *gocui.View) error { } if err = entity.Checkout(entity.NextBranch()); err != nil { if err = gui.openErrorView(g, err.Error(), - "You should manually resolve this issue"); err != nil { + "You should manually resolve this issue"); err != nil { return err } return nil diff --git a/pkg/gui/commitsview.go b/pkg/gui/commitsview.go index 8d162f6..748126e 100644 --- a/pkg/gui/commitsview.go +++ b/pkg/gui/commitsview.go @@ -19,12 +19,12 @@ 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 = "" + var body string if c.CommitType == git.LocalCommit { - body = cyan.Sprint(c.Hash[:hashLength])+" "+c.Message - } else { - body = yellow.Sprint(c.Hash[:hashLength])+" "+c.Message - } + body = cyan.Sprint(c.Hash[:hashLength]) + " " + c.Message + } else { + body = yellow.Sprint(c.Hash[:hashLength]) + " " + c.Message + } if c.Hash == entity.Commit.Hash { currentindex = i fmt.Fprintln(out, selectionIndicator+body) diff --git a/pkg/gui/diffview.go b/pkg/gui/diffview.go index 8011de6..4ebf82e 100644 --- a/pkg/gui/diffview.go +++ b/pkg/gui/diffview.go @@ -28,7 +28,7 @@ func (gui *Gui) openCommitDiffView(g *gocui.Gui, v *gocui.View) error { } commit := entity.Commit commitDetail := "Hash: " + cyan.Sprint(commit.Hash) + "\n" + "Author: " + commit.Author + - "\n" + commit.Time + "\n" + "\n" + "\t\t" + commit.Message + "\n" + "\n" + commit.Time + "\n" + "\n" + "\t\t" + commit.Message + "\n" fmt.Fprintln(v, commitDetail) diff, err := entity.Diff(entity.Commit.Hash) if err != nil { diff --git a/pkg/gui/errorview.go b/pkg/gui/errorview.go index cca3853..362a656 100644 --- a/pkg/gui/errorview.go +++ b/pkg/gui/errorview.go @@ -6,7 +6,7 @@ import ( "github.com/jroimartin/gocui" ) -// open an error view to inform user with a message and a useful note +// open an error view to inform user with a message and a useful note func (gui *Gui) openErrorView(g *gocui.Gui, message string, note string) error { maxX, maxY := g.Size() diff --git a/pkg/gui/gui-util.go b/pkg/gui/gui-util.go index e3a7f42..c734387 100644 --- a/pkg/gui/gui-util.go +++ b/pkg/gui/gui-util.go @@ -24,7 +24,7 @@ func (gui *Gui) refreshViews(g *gocui.Gui, entity *git.RepoEntity) error { return nil } -// siwtch the app mode +// siwtch the app mode // TODO: switching can be made with conventional iteration func (gui *Gui) switchMode(g *gocui.Gui, v *gocui.View) error { switch mode := gui.State.Mode.ModeID; mode { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index ef3df9c..d420594 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -6,6 +6,7 @@ import ( "github.com/isacikgoz/gitbatch/pkg/git" "github.com/isacikgoz/gitbatch/pkg/queue" "github.com/jroimartin/gocui" + log "github.com/sirupsen/logrus" ) // Gui struct hold the gocui struct along with the gui's state, also keybindings @@ -16,7 +17,7 @@ type Gui struct { State guiState } -// guiState struct holds the repositories, directiories, mode and queue of the +// guiState struct holds the repositories, directiories, mode and queue of the // gui object. These values are not static type guiState struct { Repositories []*git.RepoEntity @@ -62,7 +63,7 @@ var ( fetchMode = mode{ModeID: FetchMode, DisplayString: "Fetch", CommandString: "fetch"} pullMode = mode{ModeID: PullMode, DisplayString: "Pull", CommandString: "pull"} - mergeMode = mode{ModeID: MergeMode, DisplayString: "Merge", CommandString: "merge"} + mergeMode = mode{ModeID: MergeMode, DisplayString: "Merge", CommandString: "merge"} ) // create a Gui opject and fill it's state related entites @@ -78,7 +79,7 @@ func NewGui(directoies []string) (*Gui, error) { return gui, nil } -// run the main loop with intial values +// run the main loop with initial values func (gui *Gui) Run() error { g, err := gocui.NewGui(gocui.OutputNormal) if err != nil { @@ -92,15 +93,18 @@ func (gui *Gui) Run() error { v, err := g.SetView(loadingViewFeature.Name, maxX/2-10, maxY/2-1, maxX/2+10, maxY/2+1) if err != nil { if err != gocui.ErrUnknownView { + log.Warn("Loading view cannot be created.") return } fmt.Fprintln(v, "Loading...") } if _, err := g.SetCurrentView(loadingViewFeature.Name); err != nil { + log.Warn("Loading view cannot be focused.") return } rs, err := git.LoadRepositoryEntities(g_ui.State.Directories) if err != nil { + log.Error("Error while loading repositories.") return } g_ui.State.Repositories = rs @@ -112,12 +116,15 @@ func (gui *Gui) Run() error { g.SetManagerFunc(gui.layout) if err := gui.generateKeybindings(); err != nil { + log.Error("Keybindings could not be created.") return err } if err := gui.keybindings(g); err != nil { + log.Error("Keybindings could not be set.") return err } if err := g.MainLoop(); err != nil && err != gocui.ErrQuit { + log.Error("Error in the main loop. " + err.Error()) return err } return nil diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index bc9d9fd..43916ed 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -213,7 +213,7 @@ func (gui *Gui) keybindings(g *gocui.Gui) error { } // the bottom line of the gui is mode indicator and keybindings view. Only the -// important controls (marked as vital) are shown +// important controls (marked as vital) are shown func (gui *Gui) updateKeyBindingsView(g *gocui.Gui, viewName string) error { v, err := g.View(keybindingsViewFeature.Name) if err != nil { @@ -242,7 +242,7 @@ func (gui *Gui) updateKeyBindingsView(g *gocui.Gui, viewName string) error { modeLabel = "No mode selected" } - fmt.Fprint(v, ws + modeLabel + ws + modeSeperator) + fmt.Fprint(v, ws+modeLabel+ws+modeSeperator) for _, k := range gui.KeyBindings { if k.View == viewName && k.Vital { diff --git a/pkg/gui/mainview.go b/pkg/gui/mainview.go index eb57526..942b74d 100644 --- a/pkg/gui/mainview.go +++ b/pkg/gui/mainview.go @@ -8,8 +8,8 @@ import ( "github.com/jroimartin/gocui" ) -// this is the inital function for filling the values for the main view. the -// function waits a seperate routine to fill the gui's repositiory slice +// this is the initial function for filling the values for the main view. the +// function waits a separate routine to fill the gui's repository slice func (gui *Gui) fillMain(g *gocui.Gui) error { g.Update(func(g *gocui.Gui) error { v, err := g.View(mainViewFeature.Name) @@ -36,7 +36,7 @@ func (gui *Gui) fillMain(g *gocui.Gui) error { return nil } -// moves the cursor downwards for the main view and if it goes to bottom it +// moves the cursor downwards for the main view and if it goes to bottom it // prevents from going further func (gui *Gui) cursorDown(g *gocui.Gui, v *gocui.View) error { if v != nil { diff --git a/pkg/gui/textstyle.go b/pkg/gui/textstyle.go index 07b71ea..ef2a184 100644 --- a/pkg/gui/textstyle.go +++ b/pkg/gui/textstyle.go @@ -20,35 +20,35 @@ var ( bold = color.New(color.Bold) - maxBranchLength = 15 + maxBranchLength = 15 maxRepositoryLength = 20 - hashLength = 7 + hashLength = 7 - ws = " " - pushable = string(blue.Sprint("↖")) - pullable = string(blue.Sprint("↘")) - confidentArrow = string(magenta.Sprint("→")) + ws = " " + pushable = string(blue.Sprint("↖")) + pullable = string(blue.Sprint("↘")) + confidentArrow = string(magenta.Sprint("→")) unconfidentArrow = string(yellow.Sprint("→")) - dirty = string(yellow.Sprint("✗")) - unkown = magenta.Sprint("?") + dirty = string(yellow.Sprint("✗")) + unknown = magenta.Sprint("?") - queuedSymbol = "•" + queuedSymbol = "•" workingSymbol = "•" successSymbol = "✔" - failSymbol = "✗" + failSymbol = "✗" fetchSymbol = "↓" - pullSymbol = "↓↳" + pullSymbol = "↓↳" mergeSymbol = "↳" - modeSeperator = "" + modeSeperator = "" keyBindingSeperator = "░" selectionIndicator = string(green.Sprint("→")) + ws - tab = ws + ws + tab = ws + ws ) -// this fucntion handles the render and representation of the repository +// this function handles the render and representation of the repository // TODO: cleanup is required, right now it looks too complicated func (gui *Gui) displayString(entity *git.RepoEntity) string { suffix := "" @@ -68,15 +68,15 @@ func (gui *Gui) displayString(entity *git.RepoEntity) string { prefix = prefix + string(cyan.Sprint(branch)) if !entity.Branch.Clean { - prefix = prefix + ws + dirty + ws + prefix = prefix + ws + dirty + ws } else { - prefix = prefix + ws + prefix = prefix + ws } // rendering the satus according to repository's state if entity.State == git.Queued { if inQueue, ty := gui.State.Queue.IsInTheQueue(entity); inQueue { - switch mode := ty; mode { + switch mode := ty; mode { case queue.Fetch: suffix = blue.Sprint(queuedSymbol) case queue.Pull: @@ -123,7 +123,7 @@ func trimRemoteURL(url string) (urltype string, shorturl string) { rehttp := regexp.MustCompile(`http://`) rehttps := regexp.MustCompile(`https://`) - // seperate the protocol and remote link + // separate the protocol and remote link if ressh.MatchString(url) { shorturl = ressh.Split(url, 5)[1] urltype = "ssh" diff --git a/pkg/helpers/utils.go b/pkg/helpers/utils.go index 667597d..5dfe605 100644 --- a/pkg/helpers/utils.go +++ b/pkg/helpers/utils.go @@ -18,7 +18,7 @@ func TrimTrailingNewline(str string) string { return str } -// find the minumum value of two int +// find the minimum value of two int func Min(x, y int) int { if x < y { return x diff --git a/pkg/queue/queue.go b/pkg/queue/queue.go index 091fa84..511b6ba 100644 --- a/pkg/queue/queue.go +++ b/pkg/queue/queue.go @@ -94,7 +94,7 @@ func (jobQueue *JobQueue) StartNext() (j *Job, finished bool, err error) { finished = true return nil, finished, nil } - i := len(jobQueue.series)-1 + i := len(jobQueue.series) - 1 lastJob := jobQueue.series[i] jobQueue.series = jobQueue.series[:i] if err = lastJob.start(); err != nil { |
