summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2018-12-30 14:51:25 +0300
committerIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2018-12-30 14:51:25 +0300
commitf7dae084cbe5c1c0c763bc2e6b4c5814c5dff0b6 (patch)
treec830da1154525d87cd009c32797ca40bdb15153a
parentMerge remote-tracking branch 'origin/develop' into develop (diff)
parentfixes a semantic error while loading repositories (diff)
downloadgitbatch-f7dae084cbe5c1c0c763bc2e6b4c5814c5dff0b6.tar.gz
Merge branch 'develop' of https://github.com/isacikgoz/gitbatch into develop
-rw-r--r--.gitignore1
-rw-r--r--main.go2
-rw-r--r--pkg/git/authentication.go4
-rw-r--r--pkg/git/branch.go24
-rw-r--r--pkg/git/cmd-commit.go8
-rw-r--r--pkg/git/cmd-config.go16
-rw-r--r--pkg/git/cmd-fetch.go5
-rw-r--r--pkg/git/cmd-pull.go6
-rw-r--r--pkg/git/cmd-reset.go5
-rw-r--r--pkg/git/cmd-stash.go15
-rw-r--r--pkg/git/commit.go5
-rw-r--r--pkg/git/job.go10
-rw-r--r--pkg/git/remotebranch.go2
-rw-r--r--pkg/git/repository.go4
-rw-r--r--pkg/gui/gui.go20
-rw-r--r--pkg/gui/mainview.go3
-rw-r--r--pkg/gui/sideviews.go3
17 files changed, 83 insertions, 50 deletions
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..7ef48b8 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.1")
// parse the command line flag and options
kingpin.Parse()
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..e5facf8 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
@@ -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-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 <commit> 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 <commit> 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 <commit>
ResetSoft ResetType = "soft"
+
// ResetKeep Resets index entries and updates files in the working tree
// that are different between <commit> and HEAD
ResetKeep ResetType = "keep"
diff --git a/pkg/git/cmd-stash.go b/pkg/git/cmd-stash.go
index a786833..463bd35 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,12 +57,22 @@ 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)
+ var desc string
+ if stashHashRegex.MatchString(hash) && len(stashHashRegex.Split(trimmed, 2)) >= 2 {
+ 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,
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()
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
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