Skip to content

Commit a36976f

Browse files
committed
#451 adjusted fix to not checkout basebranch
1 parent 61c53ca commit a36976f

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

mob.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,7 @@ func start(configuration config.Configuration) error {
566566

567567
createRemoteBranch(configuration, currentBaseBranch)
568568

569-
if !currentBaseBranch.hasLocalBranch(localBranches) {
570-
silentgit("checkout", "-b", currentBaseBranch.Name)
571-
silentgit("checkout", currentBranch.Name)
572-
}
573-
574-
if currentBaseBranch.hasUnpushedCommits(configuration) {
569+
if currentBaseBranch.hasLocalBranch(localBranches) && currentBaseBranch.hasUnpushedCommits(configuration) {
575570
say.Error("cannot start; unpushed changes on base branch must be pushed upstream")
576571
say.Fix("to fix this, push those commits and try again", "git push "+configuration.RemoteName+" "+currentBaseBranch.String())
577572
return errors.New("cannot start; unpushed changes on base branch must be pushed upstream")
@@ -610,7 +605,7 @@ func start(configuration config.Configuration) error {
610605
}
611606

612607
say.Info("you are on wip branch '" + currentWipBranch.String() + "' (base branch '" + currentBaseBranch.String() + "')")
613-
sayLastCommitsList(currentBaseBranch.String(), currentWipBranch.String())
608+
sayLastCommitsList(currentBaseBranch, currentWipBranch, configuration)
614609

615610
openLastModifiedFileIfPresent(configuration)
616611

@@ -1021,12 +1016,16 @@ func squashOrCommit(configuration config.Configuration) string {
10211016
}
10221017
}
10231018

1024-
func sayLastCommitsList(currentBaseBranch string, currentWipBranch string) {
1025-
commitsBaseWipBranch := currentBaseBranch + ".." + currentWipBranch
1026-
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+
}
10271026
lines := strings.Split(log, "\n")
10281027
if len(lines) > 5 {
1029-
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:")
10301029
lines = lines[:5]
10311030
}
10321031
ReverseSlice(lines)
@@ -1094,7 +1093,8 @@ func doBranchesDiverge(ancestor string, successor string) bool {
10941093
}
10951094

10961095
func gitUserName() string {
1097-
return silentgitignorefailure("config", "--get", "user.name")
1096+
output, _ := silentgitignorefailure("config", "--get", "user.name")
1097+
return output
10981098
}
10991099

11001100
func gitUserEmail() string {
@@ -1150,13 +1150,13 @@ func silentgit(args ...string) string {
11501150
return strings.TrimSpace(output)
11511151
}
11521152

1153-
func silentgitignorefailure(args ...string) string {
1153+
func silentgitignorefailure(args ...string) (string, error) {
11541154
_, output, err := runCommandSilent("git", args...)
11551155

11561156
if err != nil {
1157-
return ""
1157+
return "", err
11581158
}
1159-
return strings.TrimSpace(output)
1159+
return strings.TrimSpace(output), nil
11601160
}
11611161

11621162
func deleteEmptyStrings(s []string) []string {
@@ -1225,7 +1225,8 @@ func gitIgnoreFailure(args ...string) error {
12251225
}
12261226

12271227
func gitCommitHash() string {
1228-
return silentgitignorefailure("rev-parse", "HEAD")
1228+
output, _ := silentgitignorefailure("rev-parse", "HEAD")
1229+
return output
12291230
}
12301231

12311232
func gitVersion() string {

mob_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,10 @@ func TestMobStartOnWipBranchWithoutCheckedOutBaseBranchWithoutHyphens(t *testing
19031903
assertNoError(t, start(configuration))
19041904
assertOnBranch(t, "mob/basebranchwithouthyphen")
19051905
assertOutputContains(t, output, "joining existing session from origin/mob/basebranchwithouthyphen")
1906+
1907+
createFile(t, "file2.txt", "abc")
1908+
done(configuration)
1909+
assertOnBranch(t, "basebranchwithouthyphen")
19061910
}
19071911

19081912
func TestGitVersionParse(t *testing.T) {

status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func status(configuration config.Configuration) {
1010
currentBaseBranch, currentWipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
1111
say.Info("you are on wip branch " + currentWipBranch.String() + " (base branch " + currentBaseBranch.String() + ")")
1212

13-
sayLastCommitsList(currentBaseBranch.String(), currentWipBranch.String())
13+
sayLastCommitsList(currentBaseBranch, currentWipBranch, configuration)
1414
} else {
1515
currentBaseBranch, _ := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
1616
say.Info("you are on base branch '" + currentBaseBranch.String() + "'")

0 commit comments

Comments
 (0)