@@ -21,7 +21,7 @@ import (
2121)
2222
2323const (
24- versionNumber = "5.3.2 "
24+ versionNumber = "5.3.3 "
2525 minimumGitVersion = "2.13.0"
2626)
2727
@@ -122,6 +122,20 @@ func (branch Branch) hasRemoteBranch(configuration config.Configuration) bool {
122122 return false
123123}
124124
125+ func (branch Branch ) hasLocalBranch () bool {
126+ localBranches := gitBranches ()
127+ say .Debug ("Local Branches: " + strings .Join (localBranches , "\n " ))
128+ say .Debug ("Local Branch: " + branch .Name )
129+
130+ for i := 0 ; i < len (localBranches ); i ++ {
131+ if localBranches [i ] == branch .Name {
132+ return true
133+ }
134+ }
135+
136+ return false
137+ }
138+
125139func (branch Branch ) IsWipBranch (configuration config.Configuration ) bool {
126140 if branch .Name == "mob-session" {
127141 return true
@@ -516,7 +530,7 @@ func deleteRemoteWipBranch(configuration config.Configuration) {
516530 currentBaseBranch , currentWipBranch := determineBranches (gitCurrentBranch (), gitBranches (), configuration )
517531
518532 git ("checkout" , currentBaseBranch .String ())
519- if hasLocalBranch ( currentWipBranch .String () ) {
533+ if currentWipBranch .hasLocalBranch ( ) {
520534 git ("branch" , "--delete" , "--force" , currentWipBranch .String ())
521535 }
522536 if currentWipBranch .hasRemoteBranch (configuration ) {
@@ -536,7 +550,8 @@ func start(configuration config.Configuration) error {
536550 }
537551
538552 git ("fetch" , configuration .RemoteName , "--prune" )
539- currentBaseBranch , currentWipBranch := determineBranches (gitCurrentBranch (), gitBranches (), configuration )
553+ currentBranch := gitCurrentBranch ()
554+ currentBaseBranch , currentWipBranch := determineBranches (currentBranch , gitBranches (), configuration )
540555
541556 if ! currentWipBranch .hasRemoteBranch (configuration ) && configuration .StartJoin {
542557 say .Error ("Remote wip branch " + currentWipBranch .remote (configuration ).String () + " is missing" )
@@ -551,7 +566,7 @@ func start(configuration config.Configuration) error {
551566
552567 createRemoteBranch (configuration , currentBaseBranch )
553568
554- if currentBaseBranch .hasUnpushedCommits (configuration ) {
569+ if currentBaseBranch .hasLocalBranch () && currentBaseBranch . hasUnpushedCommits (configuration ) {
555570 say .Error ("cannot start; unpushed changes on base branch must be pushed upstream" )
556571 say .Fix ("to fix this, push those commits and try again" , "git push " + configuration .RemoteName + " " + currentBaseBranch .String ())
557572 return errors .New ("cannot start; unpushed changes on base branch must be pushed upstream" )
@@ -590,7 +605,7 @@ func start(configuration config.Configuration) error {
590605 }
591606
592607 say .Info ("you are on wip branch '" + currentWipBranch .String () + "' (base branch '" + currentBaseBranch .String () + "')" )
593- sayLastCommitsList (currentBaseBranch . String () , currentWipBranch . String () )
608+ sayLastCommitsList (currentBaseBranch , currentWipBranch , configuration )
594609
595610 openLastModifiedFileIfPresent (configuration )
596611
@@ -751,7 +766,7 @@ func startJoinMobSession(configuration config.Configuration) {
751766 baseBranch , currentWipBranch := determineBranches (gitCurrentBranch (), gitBranches (), configuration )
752767
753768 say .Info ("joining existing session from " + currentWipBranch .remote (configuration ).String ())
754- if hasLocalBranch ( currentWipBranch .Name ) && doBranchesDiverge (baseBranch .remote (configuration ).Name , currentWipBranch .Name ) {
769+ if currentWipBranch .hasLocalBranch ( ) && doBranchesDiverge (baseBranch .remote (configuration ).Name , currentWipBranch .Name ) {
755770 say .Warning ("Careful, your wip branch (" + currentWipBranch .Name + ") diverges from your main branch (" + baseBranch .remote (configuration ).Name + ") !" )
756771 }
757772
@@ -1001,12 +1016,16 @@ func squashOrCommit(configuration config.Configuration) string {
10011016 }
10021017}
10031018
1004- func sayLastCommitsList (currentBaseBranch string , currentWipBranch string ) {
1005- commitsBaseWipBranch := currentBaseBranch + ".." + currentWipBranch
1006- log := silentgit ("--no-pager" , "log" , commitsBaseWipBranch , "--pretty=format:%h %cr <%an>" , "--abbrev-commit" )
1019+ func sayLastCommitsList (currentBaseBranch Branch , currentWipBranch Branch , configuration config.Configuration ) {
1020+ commitsBaseWipBranch := currentBaseBranch .String () + ".." + currentWipBranch .String ()
1021+ log , err := silentgitignorefailure ("--no-pager" , "log" , commitsBaseWipBranch , "--pretty=format:%h %cr <%an>" , "--abbrev-commit" )
1022+ if err != nil {
1023+ commitsBaseWipBranch = currentBaseBranch .remote (configuration ).String () + ".." + currentWipBranch .String ()
1024+ log = silentgit ("--no-pager" , "log" , commitsBaseWipBranch , "--pretty=format:%h %cr <%an>" , "--abbrev-commit" )
1025+ }
10071026 lines := strings .Split (log , "\n " )
10081027 if len (lines ) > 5 {
1009- say .Info ("wip branch '" + currentWipBranch + "' contains " + strconv .Itoa (len (lines )) + " commits. The last 5 were:" )
1028+ say .Info ("wip branch '" + currentWipBranch . String () + "' contains " + strconv .Itoa (len (lines )) + " commits. The last 5 were:" )
10101029 lines = lines [:5 ]
10111030 }
10121031 ReverseSlice (lines )
@@ -1038,20 +1057,6 @@ func isMobProgramming(configuration config.Configuration) bool {
10381057 return currentWipBranch == currentBranch
10391058}
10401059
1041- func hasLocalBranch (localBranch string ) bool {
1042- localBranches := gitBranches ()
1043- say .Debug ("Local Branches: " + strings .Join (localBranches , "\n " ))
1044- say .Debug ("Local Branch: " + localBranch )
1045-
1046- for i := 0 ; i < len (localBranches ); i ++ {
1047- if localBranches [i ] == localBranch {
1048- return true
1049- }
1050- }
1051-
1052- return false
1053- }
1054-
10551060func gitBranches () []string {
10561061 return strings .Split (silentgit ("branch" , "--format=%(refname:short)" ), "\n " )
10571062}
@@ -1074,7 +1079,8 @@ func doBranchesDiverge(ancestor string, successor string) bool {
10741079}
10751080
10761081func gitUserName () string {
1077- return silentgitignorefailure ("config" , "--get" , "user.name" )
1082+ output , _ := silentgitignorefailure ("config" , "--get" , "user.name" )
1083+ return output
10781084}
10791085
10801086func gitUserEmail () string {
@@ -1130,13 +1136,13 @@ func silentgit(args ...string) string {
11301136 return strings .TrimSpace (output )
11311137}
11321138
1133- func silentgitignorefailure (args ... string ) string {
1139+ func silentgitignorefailure (args ... string ) ( string , error ) {
11341140 _ , output , err := runCommandSilent ("git" , args ... )
11351141
11361142 if err != nil {
1137- return ""
1143+ return "" , err
11381144 }
1139- return strings .TrimSpace (output )
1145+ return strings .TrimSpace (output ), nil
11401146}
11411147
11421148func deleteEmptyStrings (s []string ) []string {
@@ -1205,7 +1211,8 @@ func gitIgnoreFailure(args ...string) error {
12051211}
12061212
12071213func gitCommitHash () string {
1208- return silentgitignorefailure ("rev-parse" , "HEAD" )
1214+ output , _ := silentgitignorefailure ("rev-parse" , "HEAD" )
1215+ return output
12091216}
12101217
12111218func gitVersion () string {
0 commit comments