diff options
| -rw-r--r-- | core/command/add.go (renamed from core/command/cmd-add.go) | 0 | ||||
| -rw-r--r-- | core/command/commit.go (renamed from core/command/cmd-commit.go) | 0 | ||||
| -rw-r--r-- | core/command/config.go (renamed from core/command/cmd-config.go) | 0 | ||||
| -rw-r--r-- | core/command/diff.go (renamed from core/command/cmd-diff.go) | 2 | ||||
| -rw-r--r-- | core/command/fetch.go (renamed from core/command/cmd-fetch.go) | 12 | ||||
| -rw-r--r-- | core/command/merge.go (renamed from core/command/cmd-merge.go) | 2 | ||||
| -rw-r--r-- | core/command/pull.go (renamed from core/command/cmd-pull.go) | 6 | ||||
| -rw-r--r-- | core/command/reset.go (renamed from core/command/cmd-reset.go) | 0 | ||||
| -rw-r--r-- | core/command/status.go (renamed from core/command/cmd-status.go) | 0 | ||||
| -rw-r--r-- | core/git/branch.go | 16 | ||||
| -rw-r--r-- | core/git/commit.go | 15 | ||||
| -rw-r--r-- | core/git/remote.go | 10 | ||||
| -rw-r--r-- | core/git/repository.go | 75 | ||||
| -rw-r--r-- | core/job/job.go | 22 | ||||
| -rw-r--r-- | gui/authenticationview.go | 10 | ||||
| -rw-r--r-- | gui/diffview.go | 4 | ||||
| -rw-r--r-- | gui/mainview.go | 16 | ||||
| -rw-r--r-- | gui/sideviews.go | 30 | ||||
| -rw-r--r-- | gui/util-textstyle.go | 33 |
19 files changed, 130 insertions, 123 deletions
diff --git a/core/command/cmd-add.go b/core/command/add.go index 5ad8774..5ad8774 100644 --- a/core/command/cmd-add.go +++ b/core/command/add.go diff --git a/core/command/cmd-commit.go b/core/command/commit.go index bf81a25..bf81a25 100644 --- a/core/command/cmd-commit.go +++ b/core/command/commit.go diff --git a/core/command/cmd-config.go b/core/command/config.go index 35eff23..35eff23 100644 --- a/core/command/cmd-config.go +++ b/core/command/config.go diff --git a/core/command/cmd-diff.go b/core/command/diff.go index 89d17be..ef48336 100644 --- a/core/command/cmd-diff.go +++ b/core/command/diff.go @@ -48,7 +48,7 @@ func diffWithGoGit(r *git.Repository, hash string) (diff string, err error) { // maybe we dont need to log the repo again? commits, err := r.Repo.Log(&gogit.LogOptions{ - From: plumbing.NewHash(r.Commit.Hash), + From: plumbing.NewHash(r.State.Commit.Hash), Order: gogit.LogOrderCommitterTime, }) if err != nil { diff --git a/core/command/cmd-fetch.go b/core/command/fetch.go index 6415651..cc827bf 100644 --- a/core/command/cmd-fetch.go +++ b/core/command/fetch.go @@ -61,10 +61,10 @@ func Fetch(r *git.Repository, options FetchOptions) (err error) { // this should be the refspec as default, let's give it a try // TODO: Fix for quick mode, maybe better read config file var refspec string - if r.Branch == nil { + if r.State.Branch == nil { refspec = "+refs/heads/*:refs/remotes/origin/*" } else { - refspec = "+" + "refs/heads/" + r.Branch.Name + ":" + "/refs/remotes/" + r.Remote.Branch.Name + refspec = "+" + "refs/heads/" + r.State.Branch.Name + ":" + "/refs/remotes/" + r.State.Remote.Branch.Name } err = fetchWithGoGit(r, options, refspec) return err @@ -94,7 +94,7 @@ func fetchWithGit(r *git.Repository, options FetchOptions) (err error) { if out, err := GenericGitCommandWithOutput(r.AbsPath, args); err != nil { return gerr.ParseGitError(out, err) } - r.SetState(git.Success) + r.SetWorkStatus(git.Success) // till this step everything should be ok return r.Refresh() } @@ -113,7 +113,7 @@ func fetchWithGoGit(r *git.Repository, options FetchOptions, refspec string) (er } // if any credential is given, let's add it to the git.FetchOptions if len(options.Credentials.User) > 0 { - protocol, err := git.AuthProtocol(r.Remote) + protocol, err := git.AuthProtocol(r.State.Remote) if err != nil { return err } @@ -137,7 +137,7 @@ func fetchWithGoGit(r *git.Repository, options FetchOptions, refspec string) (er // TODO: submit a PR for this kind of error, this type of catch is lame } else if strings.Contains(err.Error(), "couldn't find remote ref") { // we dont have remote ref, so lets pull other things.. maybe it'd be useful - rp := r.Remote.RefSpecs[0] + rp := r.State.Remote.RefSpecs[0] if fetchTryCount < fetchMaxTry { fetchTryCount++ fetchWithGoGit(r, options, rp) @@ -157,7 +157,7 @@ func fetchWithGoGit(r *git.Repository, options FetchOptions, refspec string) (er } } - r.SetState(git.Success) + r.SetWorkStatus(git.Success) // till this step everything should be ok return r.Refresh() } diff --git a/core/command/cmd-merge.go b/core/command/merge.go index 1bcc90f..0552403 100644 --- a/core/command/cmd-merge.go +++ b/core/command/merge.go @@ -34,6 +34,6 @@ func Merge(r *git.Repository, options MergeOptions) error { if out, err := GenericGitCommandWithOutput(r.AbsPath, args); err != nil { return gerr.ParseGitError(out, err) } - r.SetState(git.Success) + r.SetWorkStatus(git.Success) return r.Refresh() } diff --git a/core/command/cmd-pull.go b/core/command/pull.go index 7fbcecc..5644417 100644 --- a/core/command/cmd-pull.go +++ b/core/command/pull.go @@ -72,7 +72,7 @@ func pullWithGit(r *git.Repository, options PullOptions) (err error) { if out, err := GenericGitCommandWithOutput(r.AbsPath, args); err != nil { return gerr.ParseGitError(out, err) } - r.SetState(git.Success) + r.SetWorkStatus(git.Success) return r.Refresh() } @@ -88,7 +88,7 @@ func pullWithGoGit(r *git.Repository, options PullOptions) (err error) { } // if any credential is given, let's add it to the git.PullOptions if len(options.Credentials.User) > 0 { - protocol, err := git.AuthProtocol(r.Remote) + protocol, err := git.AuthProtocol(r.State.Remote) if err != nil { return err } @@ -136,6 +136,6 @@ func pullWithGoGit(r *git.Repository, options PullOptions) (err error) { } } - r.SetState(git.Success) + r.SetWorkStatus(git.Success) return r.Refresh() } diff --git a/core/command/cmd-reset.go b/core/command/reset.go index d97d82f..d97d82f 100644 --- a/core/command/cmd-reset.go +++ b/core/command/reset.go diff --git a/core/command/cmd-status.go b/core/command/status.go index f5947d6..f5947d6 100644 --- a/core/command/cmd-status.go +++ b/core/command/status.go diff --git a/core/git/branch.go b/core/git/branch.go index ead250a..e2ae793 100644 --- a/core/git/branch.go +++ b/core/git/branch.go @@ -54,7 +54,7 @@ func (r *Repository) loadLocalBranches() error { Ref2: "HEAD", }) if err != nil { - push = pushables[0] + push = "?" } else { push = strconv.Itoa(len(pushables)) } @@ -63,7 +63,7 @@ func (r *Repository) loadLocalBranches() error { Ref2: "@{u}", }) if err != nil { - pull = pullables[0] + pull = "?" } else { pull = strconv.Itoa(len(pullables)) } @@ -76,7 +76,7 @@ func (r *Repository) loadLocalBranches() error { Clean: clean, } if b.Name() == headRef.Name() { - r.Branch = branch + r.State.Branch = branch branchFound = true } lbs = append(lbs, branch) @@ -92,7 +92,7 @@ func (r *Repository) loadLocalBranches() error { Clean: r.isClean(), } lbs = append(lbs, branch) - r.Branch = branch + r.State.Branch = branch } r.Branches = lbs return err @@ -112,7 +112,7 @@ func (r *Repository) PreviousBranch() *Branch { func (r *Repository) currentBranchIndex() int { bix := 0 for i, lbs := range r.Branches { - if lbs.Name == r.Branch.Name { + if lbs.Name == r.State.Branch.Name { bix = i } } @@ -122,7 +122,7 @@ func (r *Repository) currentBranchIndex() int { // Checkout to given branch. If any errors occur, the method returns it instead // of returning nil func (r *Repository) Checkout(b *Branch) error { - if b.Name == r.Branch.Name { + if b.Name == r.State.Branch.Name { return nil } @@ -140,7 +140,7 @@ func (r *Repository) Checkout(b *Branch) error { // make this conditional on global scale // we don't care if this function returns an error - r.Remote.SyncBranches(b.Name) + r.State.Remote.SyncBranches(b.Name) return r.Refresh() } @@ -194,7 +194,7 @@ func RevList(r *Repository, options RevListOptions) ([]string, error) { cmd.Dir = r.AbsPath out, err := cmd.CombinedOutput() if err != nil { - return []string{"?"}, err + return nil, err } s := string(out) diff --git a/core/git/commit.go b/core/git/commit.go index 6c35778..71076b8 100644 --- a/core/git/commit.go +++ b/core/git/commit.go @@ -35,19 +35,19 @@ const ( // NextCommit iterates over next commit of a branch // TODO: the commits entites can tied to branch instead ot the repository func (r *Repository) NextCommit() { - r.Commit = r.Commits[(r.currentCommitIndex()+1)%len(r.Commits)] + r.State.Commit = r.Commits[(r.currentCommitIndex()+1)%len(r.Commits)] } // PreviousCommit iterates to opposite direction func (r *Repository) PreviousCommit() { - r.Commit = r.Commits[(len(r.Commits)+r.currentCommitIndex()-1)%len(r.Commits)] + r.State.Commit = r.Commits[(len(r.Commits)+r.currentCommitIndex()-1)%len(r.Commits)] } // returns the active commit index func (r *Repository) currentCommitIndex() int { cix := 0 for i, c := range r.Commits { - if c.Hash == r.Commit.Hash { + if c.Hash == r.State.Commit.Hash { cix = i } } @@ -116,6 +116,9 @@ func (r *Repository) pullDiffsToUpstream() ([]*Commit, error) { } else { re := regexp.MustCompile(`\r?\n`) for _, s := range pullables { + if len(s) < hashLength { + continue + } commit := &Commit{ Hash: s, Author: gitShowEmail(r.AbsPath, s), @@ -149,7 +152,7 @@ func gitShowEmail(repoPath, hash string) string { cmd.Dir = repoPath out, err := cmd.CombinedOutput() if err != nil { - return "?" + return "" } return string(out) } @@ -161,7 +164,7 @@ func gitShowBody(repoPath, hash string) string { cmd.Dir = repoPath out, err := cmd.CombinedOutput() if err != nil { - return "?" + return "" } return string(out) } @@ -173,7 +176,7 @@ func gitShowDate(repoPath, hash string) string { cmd.Dir = repoPath out, err := cmd.CombinedOutput() if err != nil { - return "?" + return "" } return string(out) } diff --git a/core/git/remote.go b/core/git/remote.go index a90bb85..4fb3070 100644 --- a/core/git/remote.go +++ b/core/git/remote.go @@ -17,15 +17,15 @@ type Remote struct { // NextRemote iterates over next branch of a remote func (r *Repository) NextRemote() error { - r.Remote = r.Remotes[(r.currentRemoteIndex()+1)%len(r.Remotes)] - r.Remote.SyncBranches(r.Branch.Name) + r.State.Remote = r.Remotes[(r.currentRemoteIndex()+1)%len(r.Remotes)] + r.State.Remote.SyncBranches(r.State.Branch.Name) return r.Publish(RepositoryUpdated, nil) } // PreviousRemote iterates over previous branch of a remote func (r *Repository) PreviousRemote() error { - r.Remote = r.Remotes[(len(r.Remotes)+r.currentRemoteIndex()-1)%len(r.Remotes)] - r.Remote.SyncBranches(r.Branch.Name) + r.State.Remote = r.Remotes[(len(r.Remotes)+r.currentRemoteIndex()-1)%len(r.Remotes)] + r.State.Remote.SyncBranches(r.State.Branch.Name) return r.Publish(RepositoryUpdated, nil) } @@ -33,7 +33,7 @@ func (r *Repository) PreviousRemote() error { func (r *Repository) currentRemoteIndex() int { cix := 0 for i, remote := range r.Remotes { - if remote.Name == r.Remote.Name { + if remote.Name == r.State.Remote.Name { cix = i } } diff --git a/core/git/repository.go b/core/git/repository.go index 8470f13..ba990fd 100644 --- a/core/git/repository.go +++ b/core/git/repository.go @@ -19,51 +19,54 @@ type Repository struct { AbsPath string ModTime time.Time Repo git.Repository - Branch *Branch Branches []*Branch - Remote *Remote Remotes []*Remote - Commit *Commit Commits []*Commit Stasheds []*StashedItem - state RepoState - - // TODO: move this into state - Message string + State *RepositoryState mutex *sync.RWMutex listeners map[string][]RepositoryListener } +// RepositoryState is the current pointers of a repository +type RepositoryState struct { + workStatus WorkStatus + Branch *Branch + Remote *Remote + Commit *Commit + Message string +} + // RepositoryListener is a type for listeners type RepositoryListener func(event *RepositoryEvent) error // RepositoryEvent is used to transfer event-related data. -// It is passed to listeners when Emit() is called +// It is passed to listeners when Publish() is called type RepositoryEvent struct { Name string Data interface{} } -// RepoState is the state of the repository for an operation -type RepoState struct { - State uint8 - Ready bool +// WorkStatus is the state of the repository for an operation +type WorkStatus struct { + Status uint8 + Ready bool } var ( // Available implies repo is ready for the operation - Available = RepoState{State: 0, Ready: true} + Available = WorkStatus{Status: 0, Ready: true} // Queued means repo is queued for a operation - Queued = RepoState{State: 1, Ready: false} + Queued = WorkStatus{Status: 1, Ready: false} // Working means an operation is just started for this repository - Working = RepoState{State: 2, Ready: false} + Working = WorkStatus{Status: 2, Ready: false} // Paused is expected when a user interaction is required - Paused = RepoState{State: 3, Ready: true} + Paused = WorkStatus{Status: 3, Ready: true} // Success is the expected outcome of the operation - Success = RepoState{State: 4, Ready: true} + Success = WorkStatus{Status: 4, Ready: true} // Fail is the unexpected outcome of the operation - Fail = RepoState{State: 5, Ready: false} + Fail = WorkStatus{Status: 5, Ready: false} ) const ( @@ -85,11 +88,14 @@ func FastInitializeRepo(dir string) (r *Repository, err error) { } // initialize Repository with minimum viable fields r = &Repository{RepoID: RandomString(8), - Name: fstat.Name(), - AbsPath: dir, - ModTime: fstat.ModTime(), - Repo: *rp, - state: Available, + Name: fstat.Name(), + AbsPath: dir, + ModTime: fstat.ModTime(), + Repo: *rp, + State: &RepositoryState{ + workStatus: Available, + Message: "", + }, mutex: &sync.RWMutex{}, listeners: make(map[string][]RepositoryListener), } @@ -126,14 +132,14 @@ func (r *Repository) loadComponents(reset bool) error { // set commit pointer for repository if len(r.Commits) > 0 { // select first commit - r.Commit = r.Commits[0] + r.State.Commit = r.Commits[0] } // set remote pointer for repository if len(r.Remotes) > 0 { // TODO: tend to take origin/master as default - r.Remote = r.Remotes[0] + r.State.Remote = r.Remotes[0] // if couldn't find, its ok. - r.Remote.SyncBranches(r.Branch.Name) + r.State.Remote.SyncBranches(r.State.Branch.Name) } else { // if there is no remote, this project is totally useless actually return errors.New("There is no remote for this repository") @@ -149,7 +155,7 @@ func (r *Repository) Refresh() error { // error can be ignored since the file already exists when app is loading // if the Repository is only fast initialized, no need to refresh because // it won't contain its belongings - if r.Branch == nil { + if r.State.Branch == nil { return nil } file, _ := os.Open(r.AbsPath) @@ -201,22 +207,15 @@ func (r *Repository) Publish(eventName string, data interface{}) error { } // State returns the state of the repository such as queued, failed etc. -func (r *Repository) State() RepoState { - return r.state +func (r *Repository) WorkStatus() WorkStatus { + return r.State.workStatus } // SetState sets the state of repository and sends repository updated event -func (r *Repository) SetState(state RepoState) { - r.state = state +func (r *Repository) SetWorkStatus(ws WorkStatus) { + r.State.workStatus = ws // we could send an event data but we don't need for this topic if err := r.Publish(RepositoryUpdated, nil); err != nil { log.Warnf("Cannot publish on %s topic.\n", RepositoryUpdated) } } - -// SetMessage sets the message of status, it is used if state is Fail -func (r *Repository) SetStateMessage(msg string) { - if r.State() == Fail { - r.Message = msg - } -} diff --git a/core/job/job.go b/core/job/job.go index 69953b7..9cfc0ed 100644 --- a/core/job/job.go +++ b/core/job/job.go @@ -31,7 +31,7 @@ const ( // starts the job func (j *Job) start() error { - j.Repository.SetState(git.Working) + j.Repository.SetWorkStatus(git.Working) // TODO: Handle errors? // TOOD: Better implementation required switch mode := j.JobType; mode { @@ -41,12 +41,12 @@ func (j *Job) start() error { opts = j.Options.(command.FetchOptions) } else { opts = command.FetchOptions{ - RemoteName: j.Repository.Remote.Name, + RemoteName: j.Repository.State.Remote.Name, } } if err := command.Fetch(j.Repository, opts); err != nil { - j.Repository.SetState(git.Fail) - j.Repository.SetStateMessage(err.Error()) + j.Repository.SetWorkStatus(git.Fail) + j.Repository.State.Message = err.Error() return err } case PullJob: @@ -55,24 +55,24 @@ func (j *Job) start() error { opts = j.Options.(command.PullOptions) } else { opts = command.PullOptions{ - RemoteName: j.Repository.Remote.Name, + RemoteName: j.Repository.State.Remote.Name, } } if err := command.Pull(j.Repository, opts); err != nil { - j.Repository.SetState(git.Fail) - j.Repository.SetStateMessage(err.Error()) + j.Repository.SetWorkStatus(git.Fail) + j.Repository.State.Message = err.Error() return err } case MergeJob: if err := command.Merge(j.Repository, command.MergeOptions{ - BranchName: j.Repository.Remote.Branch.Name, + BranchName: j.Repository.State.Remote.Branch.Name, }); err != nil { - j.Repository.SetState(git.Fail) - j.Repository.SetStateMessage(err.Error()) + j.Repository.SetWorkStatus(git.Fail) + j.Repository.State.Message = err.Error() return nil } default: - j.Repository.SetState(git.Available) + j.Repository.SetWorkStatus(git.Available) return nil } return nil diff --git a/gui/authenticationview.go b/gui/authenticationview.go index 97a214e..2faa3b7 100644 --- a/gui/authenticationview.go +++ b/gui/authenticationview.go @@ -41,7 +41,7 @@ func (gui *Gui) openAuthenticationView(g *gocui.Gui, jobQueue *job.JobQueue, job return err } jobRequiresAuth = job - if job.Repository.State() != git.Fail { + if job.Repository.WorkStatus() != git.Fail { if err := jobQueue.RemoveFromQueue(job.Repository); err != nil { log.Fatal(err.Error()) return err @@ -53,7 +53,7 @@ func (gui *Gui) openAuthenticationView(g *gocui.Gui, jobQueue *job.JobQueue, job if err != gocui.ErrUnknownView { return err } - fmt.Fprintln(v, keySymbol+selectionIndicator+red.Sprint(jobRequiresAuth.Repository.Remote.URL[0])) + fmt.Fprintln(v, keySymbol+selectionIndicator+red.Sprint(jobRequiresAuth.Repository.State.Remote.URL[0])) } g.Cursor = true if err := gui.openUserView(g); err != nil { @@ -104,7 +104,7 @@ func (gui *Gui) submitAuthenticationView(g *gocui.Gui, v *gocui.View) error { switch mode := jobRequiresAuth.JobType; mode { case job.FetchJob: jobRequiresAuth.Options = command.FetchOptions{ - RemoteName: jobRequiresAuth.Repository.Remote.Name, + RemoteName: jobRequiresAuth.Repository.State.Remote.Name, Credentials: git.Credentials{ User: creduser, Password: credpswd, @@ -113,14 +113,14 @@ func (gui *Gui) submitAuthenticationView(g *gocui.Gui, v *gocui.View) error { case job.PullJob: // we handle pull as fetch&merge so same rule applies jobRequiresAuth.Options = command.PullOptions{ - RemoteName: jobRequiresAuth.Repository.Remote.Name, + RemoteName: jobRequiresAuth.Repository.State.Remote.Name, Credentials: git.Credentials{ User: creduser, Password: credpswd, }, } } - jobRequiresAuth.Repository.SetState(git.Queued) + jobRequiresAuth.Repository.SetWorkStatus(git.Queued) // add this job to the last of the queue if err := gui.State.Queue.AddJob(jobRequiresAuth); err != nil { diff --git a/gui/diffview.go b/gui/diffview.go index 3bf9b05..9f49456 100644 --- a/gui/diffview.go +++ b/gui/diffview.go @@ -35,10 +35,10 @@ func (gui *Gui) prepareDiffView(g *gocui.Gui, v *gocui.View, display []string) ( // called from commitview, so initial view is commitview func (gui *Gui) openCommitDiffView(g *gocui.Gui, v *gocui.View) (err error) { r := gui.getSelectedRepository() - commit := r.Commit + commit := r.State.Commit commitDetail := []string{("Hash: " + cyan.Sprint(commit.Hash) + "\n" + "Author: " + commit.Author + "\n" + commit.Time + "\n" + "\n" + "\t\t" + commit.Message + "\n")} - diff, err := command.Diff(r, r.Commit.Hash) + diff, err := command.Diff(r, r.State.Commit.Hash) if err != nil { return err } diff --git a/gui/mainview.go b/gui/mainview.go index f12a26c..6cdaf61 100644 --- a/gui/mainview.go +++ b/gui/mainview.go @@ -192,7 +192,7 @@ func (gui *Gui) addToQueue(r *git.Repository) error { if err != nil { return err } - r.SetState(git.Queued) + r.SetWorkStatus(git.Queued) return nil } @@ -202,7 +202,7 @@ func (gui *Gui) removeFromQueue(r *git.Repository) error { if err != nil { return err } - r.SetState(git.Available) + r.SetWorkStatus(git.Available) return nil } @@ -214,7 +214,7 @@ func (gui *Gui) startQueue(g *gocui.Gui, v *gocui.View) error { gui_go.State.Queue = job.CreateJobQueue() for j, err := range fails { if err == gerr.ErrAuthenticationRequired { - j.Repository.SetState(git.Paused) + j.Repository.SetWorkStatus(git.Paused) gui_go.State.FailoverQueue.AddJob(j) } } @@ -224,7 +224,7 @@ func (gui *Gui) startQueue(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) submitCredentials(g *gocui.Gui, v *gocui.View) error { if is, j := gui.State.FailoverQueue.IsInTheQueue(gui.getSelectedRepository()); is { - if j.Repository.State() == git.Paused { + if j.Repository.WorkStatus() == git.Paused { gui.State.FailoverQueue.RemoveFromQueue(j.Repository) err := gui.openAuthenticationView(g, gui.State.Queue, j, v.Name()) if err != nil { @@ -244,11 +244,11 @@ func (gui *Gui) submitCredentials(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) markRepository(g *gocui.Gui, v *gocui.View) error { r := gui.getSelectedRepository() // maybe, failed entities may be added to queue again - if r.State().Ready { + if r.WorkStatus().Ready { if err := gui.addToQueue(r); err != nil { return err } - } else if r.State() == git.Queued { + } else if r.WorkStatus() == git.Queued { if err := gui.removeFromQueue(r); err != nil { return err } @@ -260,7 +260,7 @@ func (gui *Gui) markRepository(g *gocui.Gui, v *gocui.View) error { // current state into account before adding it func (gui *Gui) markAllRepositories(g *gocui.Gui, v *gocui.View) error { for _, r := range gui.State.Repositories { - if r.State().Ready { + if r.WorkStatus().Ready { if err := gui.addToQueue(r); err != nil { return err } @@ -275,7 +275,7 @@ func (gui *Gui) markAllRepositories(g *gocui.Gui, v *gocui.View) error { // current state into account before removing it func (gui *Gui) unmarkAllRepositories(g *gocui.Gui, v *gocui.View) error { for _, r := range gui.State.Repositories { - if r.State() == git.Queued { + if r.WorkStatus() == git.Queued { if err := gui.removeFromQueue(r); err != nil { return err } diff --git a/gui/sideviews.go b/gui/sideviews.go index 5a3adc7..1a910cf 100644 --- a/gui/sideviews.go +++ b/gui/sideviews.go @@ -47,7 +47,7 @@ func (gui *Gui) renderRemotes(r *git.Repository) error { if totalRemotes > 0 { for i, rm := range r.Remotes { _, shortURL := trimRemoteURL(rm.URL[0]) - if rm.Name == r.Remote.Name { + if rm.Name == r.State.Remote.Name { currentindex = i fmt.Fprintln(out, selectionIndicator+rm.Name+": "+shortURL) continue @@ -70,10 +70,10 @@ func (gui *Gui) renderRemoteBranches(r *git.Repository) error { } out.Clear() currentindex := 0 - trb := len(r.Remote.Branches) + trb := len(r.State.Remote.Branches) if trb > 0 { - for i, rm := range r.Remote.Branches { - if rm.Name == r.Remote.Branch.Name { + for i, rm := range r.State.Remote.Branches { + if rm.Name == r.State.Remote.Branch.Name { currentindex = i fmt.Fprintln(out, selectionIndicator+rm.Name) continue @@ -98,7 +98,7 @@ func (gui *Gui) renderBranch(r *git.Repository) error { currentindex := 0 totalbranches := len(r.Branches) for i, b := range r.Branches { - if b.Name == r.Branch.Name { + if b.Name == r.State.Branch.Name { currentindex = i fmt.Fprintln(out, selectionIndicator+b.Name) continue @@ -120,7 +120,7 @@ func (gui *Gui) renderCommits(r *git.Repository) error { currentindex := 0 totalcommits := len(r.Commits) for i, c := range r.Commits { - if c.Hash == r.Commit.Hash { + if c.Hash == r.State.Commit.Hash { currentindex = i fmt.Fprintln(out, selectionIndicator+commitLabel(c)) continue @@ -136,7 +136,7 @@ func (gui *Gui) sideViewsNextItem(g *gocui.Gui, v *gocui.View) error { r := gui.getSelectedRepository() switch viewName := v.Name(); viewName { case remoteBranchViewFeature.Name: - return r.Remote.NextRemoteBranch(r) + return r.State.Remote.NextRemoteBranch(r) case remoteViewFeature.Name: return r.NextRemote() case branchViewFeature.Name: @@ -159,7 +159,7 @@ func (gui *Gui) sideViewsPreviousItem(g *gocui.Gui, v *gocui.View) error { r := gui.getSelectedRepository() switch viewName := v.Name(); viewName { case remoteBranchViewFeature.Name: - return r.Remote.PreviousRemoteBranch(r) + return r.State.Remote.PreviousRemoteBranch(r) case remoteViewFeature.Name: return r.PreviousRemote() case branchViewFeature.Name: @@ -180,7 +180,7 @@ func (gui *Gui) sideViewsPreviousItem(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) syncRemoteBranch(g *gocui.Gui, v *gocui.View) error { r := gui.getSelectedRepository() return command.Fetch(r, command.FetchOptions{ - RemoteName: r.Remote.Name, + RemoteName: r.State.Remote.Name, Prune: true, }) } @@ -195,8 +195,8 @@ func (gui *Gui) setUpstreamToBranch(g *gocui.Gui, v *gocui.View) error { if err != gocui.ErrUnknownView { return err } - fmt.Fprintln(v, "branch."+r.Branch.Name+"."+"remote"+"="+r.Remote.Name) - fmt.Fprintln(v, "branch."+r.Branch.Name+"."+"merge"+"="+r.Branch.Reference.Name().String()) + fmt.Fprintln(v, "branch."+r.State.Branch.Name+"."+"remote"+"="+r.State.Remote.Name) + fmt.Fprintln(v, "branch."+r.State.Branch.Name+"."+"merge"+"="+r.State.Branch.Reference.Name().String()) } return gui.focusToView(confirmationViewFeature.Name) } @@ -206,17 +206,17 @@ func (gui *Gui) confirmSetUpstreamToBranch(g *gocui.Gui, v *gocui.View) error { var err error r := gui.getSelectedRepository() if err = command.AddConfig(r, command.ConfigOptions{ - Section: "branch." + r.Branch.Name, + Section: "branch." + r.State.Branch.Name, Option: "remote", Site: command.ConfigSiteLocal, - }, r.Remote.Name); err != nil { + }, r.State.Remote.Name); err != nil { return err } if err = command.AddConfig(r, command.ConfigOptions{ - Section: "branch." + r.Branch.Name, + Section: "branch." + r.State.Branch.Name, Option: "merge", Site: command.ConfigSiteLocal, - }, r.Branch.Reference.Name().String()); err != nil { + }, r.State.Branch.Reference.Name().String()); err != nil { return err } r.Refresh() diff --git a/gui/util-textstyle.go b/gui/util-textstyle.go index 01a24c3..d699acf 100644 --- a/gui/util-textstyle.go +++ b/gui/util-textstyle.go @@ -54,12 +54,13 @@ var ( func (gui *Gui) repositoryLabel(r *git.Repository) string { var prefix string - if r.Branch.Pushables != "?" { - prefix = prefix + pushable + ws + r.Branch.Pushables + - ws + pullable + ws + r.Branch.Pullables + b := r.State.Branch + if b.Pushables != "?" { + prefix = prefix + pushable + ws + b.Pushables + + ws + pullable + ws + b.Pullables } else { - prefix = prefix + pushable + ws + yellow.Sprint(r.Branch.Pushables) + - ws + pullable + ws + yellow.Sprint(r.Branch.Pullables) + prefix = prefix + pushable + ws + yellow.Sprint(b.Pushables) + + ws + pullable + ws + yellow.Sprint(b.Pullables) } var repoName string @@ -73,10 +74,10 @@ func (gui *Gui) repositoryLabel(r *git.Repository) string { } // some branch names can be really long, in that times I hope the first // characters are important and meaningful - branch := adjustTextLength(r.Branch.Name, maxBranchLength) + branch := adjustTextLength(b.Name, maxBranchLength) prefix = prefix + string(cyan.Sprint(branch)) - if !r.Branch.Clean { + if !b.Clean { prefix = prefix + ws + dirty + ws } else { prefix = prefix + ws @@ -84,7 +85,7 @@ func (gui *Gui) repositoryLabel(r *git.Repository) string { var suffix string // rendering the satus according to repository's state - if r.State() == git.Queued { + if r.WorkStatus() == git.Queued { if inQueue, j := gui.State.Queue.IsInTheQueue(r); inQueue { switch mode := j.JobType; mode { case job.FetchJob: @@ -98,15 +99,15 @@ func (gui *Gui) repositoryLabel(r *git.Repository) string { } } return prefix + repoName + ws + suffix - } else if r.State() == git.Working { + } else if r.WorkStatus() == git.Working { // TODO: maybe the type of the job can be written while its working? return prefix + repoName + ws + green.Sprint(workingSymbol) - } else if r.State() == git.Success { + } else if r.WorkStatus() == git.Success { return prefix + repoName + ws + green.Sprint(successSymbol) - } else if r.State() == git.Paused { + } else if r.WorkStatus() == git.Paused { return prefix + repoName + ws + yellow.Sprint("authentication required (u)") - } else if r.State() == git.Fail { - return prefix + repoName + ws + red.Sprint(failSymbol) + ws + red.Sprint(r.Message) + } else if r.WorkStatus() == git.Fail { + return prefix + repoName + ws + red.Sprint(failSymbol) + ws + red.Sprint(r.State.Message) } return prefix + repoName } @@ -119,7 +120,11 @@ func commitLabel(c *git.Commit) string { case git.LocalCommit: body = blue.Sprint(c.Hash[:hashLength]) + " " + c.Message case git.RemoteCommit: - body = yellow.Sprint(c.Hash[:hashLength]) + " " + c.Message + if len(c.Hash) > hashLength { + body = yellow.Sprint(c.Hash[:hashLength]) + " " + c.Message + } else { + body = yellow.Sprint(c.Hash[:len(c.Hash)]) + " " + c.Message + } default: body = c.Hash[:hashLength] + " " + c.Message } |
