From 7e0d80e24c3dc4e3ab39eb9d0e3c8978ad7b1b72 Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Sat, 22 Dec 2018 00:46:34 +0300 Subject: suppress an ambigous bug --- pkg/gui/mainview.go | 3 +++ pkg/gui/sideviews.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pkg/gui/mainview.go b/pkg/gui/mainview.go index e4c0159..4661f43 100644 --- a/pkg/gui/mainview.go +++ b/pkg/gui/mainview.go @@ -101,6 +101,9 @@ func (gui *Gui) cursorUp(g *gocui.Gui, v *gocui.View) error { // rrequire a better implementation or the slice's order must be synchronized // with the views lines func (gui *Gui) getSelectedRepository() *git.RepoEntity { + if len(gui.State.Repositories) == 0 { + return nil + } v, _ := gui.g.View(mainViewFeature.Name) _, oy := v.Origin() _, cy := v.Cursor() diff --git a/pkg/gui/sideviews.go b/pkg/gui/sideviews.go index 6316255..a602b2e 100644 --- a/pkg/gui/sideviews.go +++ b/pkg/gui/sideviews.go @@ -14,6 +14,9 @@ var ( // refreshes the side views of the application for given git.RepoEntity struct func (gui *Gui) renderSideViews(e *git.RepoEntity) error { + if e == nil { + return nil + } var err error if err = gui.renderRemotes(e); err != nil { return err -- cgit v1.2.3 From 56f7a998b45f985865997b540e15e1046f74e5a0 Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Thu, 27 Dec 2018 22:35:18 +0300 Subject: fix #38 for unhashed stashed items. --- pkg/git/cmd-stash.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/git/cmd-stash.go b/pkg/git/cmd-stash.go index a786833..85e25e3 100644 --- a/pkg/git/cmd-stash.go +++ b/pkg/git/cmd-stash.go @@ -60,8 +60,13 @@ func (e *RepoEntity) loadStashedItems() error { trimmed = stashBranchRegex.Split(trimmed, 2)[1] hash := stashHashRegex.FindString(trimmed) + var desc string + if stashHashRegex.MatchString(hash) { + desc = stashHashRegex.Split(trimmed, 2)[1][1:] + } else { + desc = trimmed + } // trim hash - desc := stashHashRegex.Split(trimmed, 2)[1][1:] e.Stasheds = append(e.Stasheds, &StashedItem{ StashID: i, -- cgit v1.2.3 From 7301223c81584a8eaeb02b61cb29c6c2cf83b818 Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Thu, 27 Dec 2018 23:11:09 +0300 Subject: bump version --- .gitignore | 1 + main.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9b75aa8..d1f8e82 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ exec.go.test build.sh test.go .vscode +build/ diff --git a/main.go b/main.go index 02a6b20..8edebeb 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ var ( ) func main() { - kingpin.Version("gitbatch version 0.1.2 (pre-release)") + kingpin.Version("gitbatch version 0.2.0") // parse the command line flag and options kingpin.Parse() -- cgit v1.2.3 From dd5d87b9194954f45135edfc15d6b22bf135cddf Mon Sep 17 00:00:00 2001 From: Hugo Soto Date: Thu, 27 Dec 2018 17:51:06 -0300 Subject: Fix/linting (#41) * Clean err returning * Fix var naming convention * Inline error return values and reorder imports * Add and improve func and const descriptions * Inline returning values --- pkg/git/authentication.go | 4 ++-- pkg/git/branch.go | 6 +++--- pkg/git/cmd-commit.go | 8 +++----- pkg/git/cmd-config.go | 16 ++++++++-------- pkg/git/cmd-fetch.go | 5 ++--- pkg/git/cmd-pull.go | 6 +++--- pkg/git/cmd-reset.go | 5 +++++ pkg/git/commit.go | 5 +---- pkg/git/job.go | 10 +++++----- pkg/git/remotebranch.go | 2 +- pkg/git/repository.go | 4 ++-- 11 files changed, 35 insertions(+), 36 deletions(-) diff --git a/pkg/git/authentication.go b/pkg/git/authentication.go index 3e834ec..a33816b 100644 --- a/pkg/git/authentication.go +++ b/pkg/git/authentication.go @@ -14,8 +14,8 @@ type Credentials struct { } var ( - authProtocolHttp = "http" - authProtocolHttps = "https" + authProtocolHTTP = "http" + authProtocolHTTPS = "https" authProtocolSSH = "ssh" ) diff --git a/pkg/git/branch.go b/pkg/git/branch.go index 5be8e16..5277e20 100644 --- a/pkg/git/branch.go +++ b/pkg/git/branch.go @@ -1,13 +1,13 @@ package git import ( + "strconv" + "strings" + "github.com/isacikgoz/gitbatch/pkg/helpers" log "github.com/sirupsen/logrus" "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/plumbing" - - "strconv" - "strings" ) // Branch is the wrapper of go-git's Reference struct. In addition to that, it diff --git a/pkg/git/cmd-commit.go b/pkg/git/cmd-commit.go index 6e836ab..23c1de1 100644 --- a/pkg/git/cmd-commit.go +++ b/pkg/git/cmd-commit.go @@ -27,7 +27,7 @@ type CommitOptions struct { Email string } -// CommitCommand +// CommitCommand defines which commit command to use. func CommitCommand(e *RepoEntity, options CommitOptions) (err error) { // here we configure commit operation // default mode is go-git (this may be configured) @@ -35,11 +35,9 @@ func CommitCommand(e *RepoEntity, options CommitOptions) (err error) { switch commitCmdMode { case commitCmdModeLegacy: - err = commitWithGit(e, options) - return err + return commitWithGit(e, options) case commitCmdModeNative: - err = commitWithGoGit(e, options) - return err + return commitWithGoGit(e, options) } return errors.New("Unhandled commit operation") } diff --git a/pkg/git/cmd-config.go b/pkg/git/cmd-config.go index 06ba74b..e4bacf0 100644 --- a/pkg/git/cmd-config.go +++ b/pkg/git/cmd-config.go @@ -14,7 +14,7 @@ var ( configCmdModeNative = "go-git" ) -// CommitOptions defines the rules for commit operation +// ConfigOptions defines the rules for commit operation type ConfigOptions struct { // Section Section string @@ -24,12 +24,14 @@ type ConfigOptions struct { Site ConfigSite } +// ConfigSite defines a string type for the site. type ConfigSite string const ( - // ConfigStieLocal + // ConfigSiteLocal defines a local config. ConfigSiteLocal ConfigSite = "local" - // ConfgiSiteGlobal + + // ConfgiSiteGlobal defines a global config. ConfgiSiteGlobal ConfigSite = "global" ) @@ -41,11 +43,9 @@ func Config(e *RepoEntity, options ConfigOptions) (value string, err error) { switch configCmdMode { case configCmdModeLegacy: - value, err = configWithGit(e, options) - return value, err + return configWithGit(e, options) case configCmdModeNative: - value, err = configWithGoGit(e, options) - return value, err + return configWithGoGit(e, options) } return value, errors.New("Unhandled config operation") } @@ -78,7 +78,7 @@ func configWithGoGit(e *RepoEntity, options ConfigOptions) (value string, err er return config.Raw.Section(options.Section).Option(options.Option), nil } -// AddConfig +// AddConfig adds an entry on the ConfigOptions field. func AddConfig(e *RepoEntity, options ConfigOptions, value string) (err error) { return addConfigWithGit(e, options, value) diff --git a/pkg/git/cmd-fetch.go b/pkg/git/cmd-fetch.go index e7a60f7..0830105 100644 --- a/pkg/git/cmd-fetch.go +++ b/pkg/git/cmd-fetch.go @@ -113,7 +113,7 @@ func fetchWithGoGit(e *RepoEntity, options FetchOptions, refspec string) (err er if err != nil { return err } - if protocol == authProtocolHttp || protocol == authProtocolHttps { + if protocol == authProtocolHTTP || protocol == authProtocolHTTPS { opt.Auth = &http.BasicAuth{ Username: options.Credentials.User, Password: options.Credentials.Password, @@ -123,8 +123,7 @@ func fetchWithGoGit(e *RepoEntity, options FetchOptions, refspec string) (err er } } - err = e.Repository.Fetch(opt) - if err != nil { + if err := e.Repository.Fetch(opt); err != nil { if err == git.NoErrAlreadyUpToDate { // Already up-to-date log.Warn(err.Error()) diff --git a/pkg/git/cmd-pull.go b/pkg/git/cmd-pull.go index 2c28d3a..f620925 100644 --- a/pkg/git/cmd-pull.go +++ b/pkg/git/cmd-pull.go @@ -85,7 +85,7 @@ func pullWithGoGit(e *RepoEntity, options PullOptions) (err error) { if err != nil { return err } - if protocol == authProtocolHttp || protocol == authProtocolHttps { + if protocol == authProtocolHTTP || protocol == authProtocolHTTPS { opt.Auth = &http.BasicAuth{ Username: options.Credentials.User, Password: options.Credentials.Password, @@ -98,8 +98,8 @@ func pullWithGoGit(e *RepoEntity, options PullOptions) (err error) { if err != nil { return err } - err = w.Pull(opt) - if err != nil { + + if err = w.Pull(opt); err != nil { if err == git.NoErrAlreadyUpToDate { // Already up-to-date log.Warn(err.Error()) diff --git a/pkg/git/cmd-reset.go b/pkg/git/cmd-reset.go index cc5f0f9..bea436c 100644 --- a/pkg/git/cmd-reset.go +++ b/pkg/git/cmd-reset.go @@ -24,23 +24,28 @@ type ResetOptions struct { Rtype ResetType } +// ResetType defines a string type for reset git command. type ResetType string const ( // ResetHard Resets the index and working tree. Any changes to tracked // files in the working tree since are discarded. ResetHard ResetType = "hard" + // ResetMixed Resets the index but not the working tree (i.e., the changed // files are preserved but not marked for commit) and reports what has not // been updated. This is the default action. ResetMixed ResetType = "mixed" + // ResetMerge Resets the index and updates the files in the working tree // that are different between and HEAD, but keeps those which are // different between the index and working tree ResetMerge ResetType = "merge" + // ResetSoft Does not touch the index file or the working tree at all // (but resets the head to ResetSoft ResetType = "soft" + // ResetKeep Resets index entries and updates files in the working tree // that are different between and HEAD ResetKeep ResetType = "keep" diff --git a/pkg/git/commit.go b/pkg/git/commit.go index 716ccba..f78bb64 100644 --- a/pkg/git/commit.go +++ b/pkg/git/commit.go @@ -99,10 +99,7 @@ func (e *RepoEntity) loadCommits() error { e.Commits = append(e.Commits, commit) return nil }) - if err != nil { - return err - } - return nil + return err } // this function creates the commit entities according to active branchs diffs diff --git a/pkg/git/job.go b/pkg/git/job.go index c64086e..85c28f3 100644 --- a/pkg/git/job.go +++ b/pkg/git/job.go @@ -1,7 +1,5 @@ package git -import () - // Job relates the type of the operation and the entity type Job struct { // JobType is to select operation type that will be applied to repository @@ -16,11 +14,13 @@ type Job struct { type JobType string const ( - // Fetch is wrapper of git fetch command + // FetchJob is wrapper of git fetch command FetchJob JobType = "fetch" - // Pull is wrapper of git pull command + + // PullJob is wrapper of git pull command PullJob JobType = "pull" - // Merge is wrapper of git merge command + + // MergeJob is wrapper of git merge command MergeJob JobType = "merge" ) diff --git a/pkg/git/remotebranch.go b/pkg/git/remotebranch.go index 207f5a9..337b28b 100644 --- a/pkg/git/remotebranch.go +++ b/pkg/git/remotebranch.go @@ -86,5 +86,5 @@ func (r *Remote) switchRemoteBranch(remoteBranchName string) error { return nil } } - return errors.New("Remote branch not found.") + return errors.New("Remote branch not found") } diff --git a/pkg/git/repository.go b/pkg/git/repository.go index 28c95cd..0e57482 100644 --- a/pkg/git/repository.go +++ b/pkg/git/repository.go @@ -65,7 +65,7 @@ var ( ) const ( - // This is the repository updated topic + // RepositoryUpdated defines the topic for an updated repository. RepositoryUpdated = "repository.updated" ) @@ -176,7 +176,7 @@ func (e *RepoEntity) On(event string, listener RepositoryListener) { e.listeners[event] = append(e.listeners[event], listener) } -// Emit notifies listeners about the event +// Publish publishes the data to a certain event by its name. func (e *RepoEntity) Publish(eventName string, data interface{}) error { e.mutex.RLock() defer e.mutex.RUnlock() -- cgit v1.2.3 From 0c430a1e638be37e0afb9ef3759971a0ab0cd132 Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Fri, 28 Dec 2018 01:21:11 +0300 Subject: fixes a bug on branch and stash without HEAD (#44) --- pkg/git/branch.go | 18 +++++++++++++++++- pkg/git/cmd-stash.go | 8 +++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pkg/git/branch.go b/pkg/git/branch.go index 5277e20..e5facf8 100644 --- a/pkg/git/branch.go +++ b/pkg/git/branch.go @@ -33,7 +33,11 @@ func (e *RepoEntity) loadLocalBranches() error { return err } defer bs.Close() - headRef, _ := e.Repository.Head() + headRef, err := e.Repository.Head() + if err != nil { + return err + } + var branchFound bool bs.ForEach(func(b *plumbing.Reference) error { if b.Type() == plumbing.HashReference { var push, pull string @@ -65,11 +69,23 @@ func (e *RepoEntity) loadLocalBranches() error { } if b.Name() == headRef.Name() { e.Branch = branch + branchFound = true } lbs = append(lbs, branch) } return nil }) + if !branchFound { + branch := &Branch{ + Name: headRef.Hash().String(), + Reference: headRef, + Pushables: "?", + Pullables: "?", + Clean: e.isClean(), + } + lbs = append(lbs, branch) + e.Branch = branch + } e.Branches = lbs return err } diff --git a/pkg/git/cmd-stash.go b/pkg/git/cmd-stash.go index 85e25e3..934628e 100644 --- a/pkg/git/cmd-stash.go +++ b/pkg/git/cmd-stash.go @@ -36,7 +36,8 @@ func (e *RepoEntity) loadStashedItems() error { output := stashGet(e, "list") stashIDRegex := regexp.MustCompile(`stash@{[\d]+}:`) stashIDRegexInt := regexp.MustCompile(`[\d]+`) - stashBranchRegex := regexp.MustCompile(`[\w]+: `) + stashBranchRegex := regexp.MustCompile(`^(.*?): `) + stashMsgRegex := regexp.MustCompile(`WIP on \(?([^)]*)\)?`) stashHashRegex := regexp.MustCompile(`[\w]{7}`) stashlist := strings.Split(output, "\n") @@ -56,6 +57,11 @@ func (e *RepoEntity) loadStashedItems() error { stashBranchRegexMatch := stashBranchRegex.FindString(trimmed) branchName := stashBranchRegexMatch[:len(stashBranchRegexMatch)-2] + branchMatches := stashMsgRegex.FindStringSubmatch(branchName) + if len(branchMatches) >= 2 { + branchName = stashBranchRegexMatch[:len(stashBranchRegexMatch)-2] + } + // trim branch section trimmed = stashBranchRegex.Split(trimmed, 2)[1] hash := stashHashRegex.FindString(trimmed) -- cgit v1.2.3 From 51ee48c28778c022e0b17e6102495caa571e12b1 Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Fri, 28 Dec 2018 01:58:30 +0300 Subject: Hotfix 40 (#45) * fixes a bug on branch and stash without HEAD * fix on 40 issue, again. --- pkg/git/cmd-stash.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/git/cmd-stash.go b/pkg/git/cmd-stash.go index 934628e..463bd35 100644 --- a/pkg/git/cmd-stash.go +++ b/pkg/git/cmd-stash.go @@ -67,7 +67,7 @@ func (e *RepoEntity) loadStashedItems() error { hash := stashHashRegex.FindString(trimmed) var desc string - if stashHashRegex.MatchString(hash) { + if stashHashRegex.MatchString(hash) && len(stashHashRegex.Split(trimmed, 2)) >= 2 { desc = stashHashRegex.Split(trimmed, 2)[1][1:] } else { desc = trimmed -- cgit v1.2.3 From 44ddb04e0bfe395565ace08e34d1d84332c48bc1 Mon Sep 17 00:00:00 2001 From: İbrahim Serdar Açıkgöz Date: Fri, 28 Dec 2018 10:59:28 +0300 Subject: fixes a semantic error while loading repositories --- main.go | 2 +- pkg/gui/gui.go | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 8edebeb..7ef48b8 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ var ( ) func main() { - kingpin.Version("gitbatch version 0.2.0") + kingpin.Version("gitbatch version 0.2.1") // parse the command line flag and options kingpin.Parse() diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 2e1f2b2..c839860 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -101,6 +101,16 @@ func (gui *Gui) Run() error { return err } + defer g.Close() + gui.g = g + g.Highlight = true + g.SelFgColor = gocui.ColorGreen + + // If InputEsc is true, when ESC sequence is in the buffer and it doesn't + // match any known sequence, ESC means KeyEsc. + g.InputEsc = true + g.SetManagerFunc(gui.layout) + // start an async view apart from this loop to show loading screen go func(g_ui *Gui) { maxX, maxY := g.Size() @@ -131,16 +141,6 @@ func (gui *Gui) Run() error { gui.fillMain(g) }(gui) - defer g.Close() - gui.g = g - g.Highlight = true - g.SelFgColor = gocui.ColorGreen - - // If InputEsc is true, when ESC sequence is in the buffer and it doesn't - // match any known sequence, ESC means KeyEsc. - g.InputEsc = true - g.SetManagerFunc(gui.layout) - if err := gui.generateKeybindings(); err != nil { log.Error("Keybindings could not be created.") return err -- cgit v1.2.3