Skip to content

Commit

Permalink
fix #451
Browse files Browse the repository at this point in the history
  • Loading branch information
hollesse committed Oct 11, 2024
1 parent f37f16b commit 91f02ae
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 5.3.3
- Fix: `mob start` now functions correctly on WIP branches when the base branch is not checked out, applicable to branch names that do not contain a `-` character.

# 5.3.2
- Fix: Removed wrong warning about diverging wip branch when joining a new session

Expand Down
24 changes: 22 additions & 2 deletions mob.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

const (
versionNumber = "5.3.2"
versionNumber = "5.3.3"
minimumGitVersion = "2.13.0"
)

Expand Down Expand Up @@ -122,6 +122,19 @@ func (branch Branch) hasRemoteBranch(configuration config.Configuration) bool {
return false
}

func (branch Branch) hasLocalBranch(localBranches []string) bool {
say.Debug("Local Branches: " + strings.Join(localBranches, "\n"))
say.Debug("Local Branch: " + branch.Name)

for i := 0; i < len(localBranches); i++ {
if localBranches[i] == branch.Name {
return true
}
}

return false
}

func (branch Branch) IsWipBranch(configuration config.Configuration) bool {
if branch.Name == "mob-session" {
return true
Expand Down Expand Up @@ -536,7 +549,9 @@ func start(configuration config.Configuration) error {
}

git("fetch", configuration.RemoteName, "--prune")
currentBaseBranch, currentWipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
currentBranch := gitCurrentBranch()
localBranches := gitBranches()
currentBaseBranch, currentWipBranch := determineBranches(currentBranch, localBranches, configuration)

if !currentWipBranch.hasRemoteBranch(configuration) && configuration.StartJoin {
say.Error("Remote wip branch " + currentWipBranch.remote(configuration).String() + " is missing")
Expand All @@ -551,6 +566,11 @@ 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) {
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())
Expand Down
23 changes: 22 additions & 1 deletion mob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,27 @@ func TestMobClean(t *testing.T) {
assertNoMobSessionBranches(t, configuration, "mob-session")
}

func TestMobStartOnWipBranchWithoutCheckedOutBaseBranchWithoutHyphens(t *testing.T) {
output, configuration := setup(t)

setWorkingDir(tempDir + "/alice")
git("switch", "-C", "basebranchwithouthyphen")
configuration.StartCreate = true
start(configuration)
assertOnBranch(t, "mob/basebranchwithouthyphen")
createFile(t, "file1.txt", "abc")
next(configuration)
assertOnBranch(t, "basebranchwithouthyphen")

setWorkingDir(tempDir + "/bob")
git("switch", "-C", "mob/basebranchwithouthyphen")
configuration.StartCreate = false

assertNoError(t, start(configuration))
assertOnBranch(t, "mob/basebranchwithouthyphen")
assertOutputContains(t, output, "joining existing session from origin/mob/basebranchwithouthyphen")
}

func TestGitVersionParse(t *testing.T) {
// Check real examples
equals(t, GitVersion{2, 34, 1}, parseGitVersion("git version 2.34.1"))
Expand Down Expand Up @@ -2093,7 +2114,7 @@ func setWorkingDir(dir string) {

func assertNoError(t *testing.T, err error) {
if err != nil {
failWithFailure(t, err, nil)
failWithFailure(t, nil, err)
}

}
Expand Down

0 comments on commit 91f02ae

Please sign in to comment.