Skip to content

Commit

Permalink
#451 adjusted fix to not checkout basebranch
Browse files Browse the repository at this point in the history
  • Loading branch information
hollesse committed Oct 12, 2024
1 parent 61c53ca commit a36976f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
33 changes: 17 additions & 16 deletions mob.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,7 @@ func start(configuration config.Configuration) error {

createRemoteBranch(configuration, currentBaseBranch)

if !currentBaseBranch.hasLocalBranch(localBranches) {
silentgit("checkout", "-b", currentBaseBranch.Name)
silentgit("checkout", currentBranch.Name)
}

if currentBaseBranch.hasUnpushedCommits(configuration) {
if currentBaseBranch.hasLocalBranch(localBranches) && currentBaseBranch.hasUnpushedCommits(configuration) {
say.Error("cannot start; unpushed changes on base branch must be pushed upstream")
say.Fix("to fix this, push those commits and try again", "git push "+configuration.RemoteName+" "+currentBaseBranch.String())
return errors.New("cannot start; unpushed changes on base branch must be pushed upstream")
Expand Down Expand Up @@ -610,7 +605,7 @@ func start(configuration config.Configuration) error {
}

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

openLastModifiedFileIfPresent(configuration)

Expand Down Expand Up @@ -1021,12 +1016,16 @@ func squashOrCommit(configuration config.Configuration) string {
}
}

func sayLastCommitsList(currentBaseBranch string, currentWipBranch string) {
commitsBaseWipBranch := currentBaseBranch + ".." + currentWipBranch
log := silentgit("--no-pager", "log", commitsBaseWipBranch, "--pretty=format:%h %cr <%an>", "--abbrev-commit")
func sayLastCommitsList(currentBaseBranch Branch, currentWipBranch Branch, configuration config.Configuration) {
commitsBaseWipBranch := currentBaseBranch.String() + ".." + currentWipBranch.String()
log, err := silentgitignorefailure("--no-pager", "log", commitsBaseWipBranch, "--pretty=format:%h %cr <%an>", "--abbrev-commit")
if err != nil {
commitsBaseWipBranch = currentBaseBranch.remote(configuration).String() + ".." + currentWipBranch.String()
log = silentgit("--no-pager", "log", commitsBaseWipBranch, "--pretty=format:%h %cr <%an>", "--abbrev-commit")
}
lines := strings.Split(log, "\n")
if len(lines) > 5 {
say.Info("wip branch '" + currentWipBranch + "' contains " + strconv.Itoa(len(lines)) + " commits. The last 5 were:")
say.Info("wip branch '" + currentWipBranch.String() + "' contains " + strconv.Itoa(len(lines)) + " commits. The last 5 were:")
lines = lines[:5]
}
ReverseSlice(lines)
Expand Down Expand Up @@ -1094,7 +1093,8 @@ func doBranchesDiverge(ancestor string, successor string) bool {
}

func gitUserName() string {
return silentgitignorefailure("config", "--get", "user.name")
output, _ := silentgitignorefailure("config", "--get", "user.name")
return output
}

func gitUserEmail() string {
Expand Down Expand Up @@ -1150,13 +1150,13 @@ func silentgit(args ...string) string {
return strings.TrimSpace(output)
}

func silentgitignorefailure(args ...string) string {
func silentgitignorefailure(args ...string) (string, error) {
_, output, err := runCommandSilent("git", args...)

if err != nil {
return ""
return "", err
}
return strings.TrimSpace(output)
return strings.TrimSpace(output), nil
}

func deleteEmptyStrings(s []string) []string {
Expand Down Expand Up @@ -1225,7 +1225,8 @@ func gitIgnoreFailure(args ...string) error {
}

func gitCommitHash() string {
return silentgitignorefailure("rev-parse", "HEAD")
output, _ := silentgitignorefailure("rev-parse", "HEAD")
return output
}

func gitVersion() string {
Expand Down
4 changes: 4 additions & 0 deletions mob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,10 @@ func TestMobStartOnWipBranchWithoutCheckedOutBaseBranchWithoutHyphens(t *testing
assertNoError(t, start(configuration))
assertOnBranch(t, "mob/basebranchwithouthyphen")
assertOutputContains(t, output, "joining existing session from origin/mob/basebranchwithouthyphen")

createFile(t, "file2.txt", "abc")
done(configuration)
assertOnBranch(t, "basebranchwithouthyphen")
}

func TestGitVersionParse(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func status(configuration config.Configuration) {
currentBaseBranch, currentWipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
say.Info("you are on wip branch " + currentWipBranch.String() + " (base branch " + currentBaseBranch.String() + ")")

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

0 comments on commit a36976f

Please sign in to comment.