Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #451 #459

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo, hasLocalBranch should not need an argument localBranches. It can fetch them itself. And if local branches are fetched multiple times, I still think its worth it. When I need to find out how to check if a localBranch exists in our code, and I find this function, I don't want it to make me search for yet another function.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same is probably applicable to determineBranches

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this line? It feels wrong

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @simonharrer, first I thought we need it, because the git command which is used to check if there are unpushed commits. But because of your comment I thought more about it and if there is no local base branch there can not be unpushed commits. but after implementing this change the test failed again. In the function sayLastCommitsList we look at the local basebranch. I now implemented it the way that we try this behavior if it fails we try to check against remote. Let me know if you think it is better to directly compare to the remote base branch instead of trying to compare to the local branch first. I think it could make sense but was not completely sure about it.

}

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("checkout", "-b", "basebranchwithouthyphen")
configuration.StartCreate = true
start(configuration)
assertOnBranch(t, "mob/basebranchwithouthyphen")
createFile(t, "file1.txt", "abc")
next(configuration)
assertOnBranch(t, "basebranchwithouthyphen")

setWorkingDir(tempDir + "/bob")
git("checkout", "-b", "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
Loading