Repository: remotemobprogramming/mob
Pull request #148 (2021-03-16 22:11:00)

Refactor to configuration param


Patch:
diff --git a/mob.go b/mob.go
index a7118c1..5973f6c 100644
--- a/mob.go
+++ b/mob.go
@@ -280,17 +280,17 @@ func execute(command string, parameter []string) {
 			startTimer(configuration.MobTimer)
 		}
 
-		status()
+		status(configuration)
 	case "n", "next":
 		next(configuration)
 	case "d", "done":
-		done()
+		done(configuration)
 	case "reset":
-		reset()
+		reset(configuration)
 	case "config":
 		config(configuration)
 	case "status":
-		status()
+		status(configuration)
 	case "t", "timer":
 		if len(parameter) > 0 {
 			timer := parameter[0]
@@ -478,7 +478,7 @@ func moo() {
 	}
 }
 
-func reset() {
+func reset(configuration Configuration) {
 	git("fetch", configuration.RemoteName)
 
 	currentBaseBranch, currentWipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
@@ -487,7 +487,7 @@ func reset() {
 	if hasLocalBranch(currentWipBranch) {
 		git("branch", "--delete", "--force", currentWipBranch)
 	}
-	if hasRemoteBranch(currentWipBranch) {
+	if hasRemoteBranch(currentWipBranch, configuration) {
 		git("push", "--no-verify", configuration.RemoteName, "--delete", currentWipBranch)
 	}
 	sayInfo("Branches " + currentWipBranch + " and " + configuration.RemoteName + "/" + currentWipBranch + " deleted")
@@ -521,7 +521,7 @@ func start(configuration Configuration) {
 		return
 	}
 
-	if !hasRemoteBranch(currentBaseBranch) {
+	if !hasRemoteBranch(currentBaseBranch, configuration) {
 		sayError("Remote branch " + configuration.RemoteName + "/" + currentBaseBranch + " is missing")
 		sayTodo("To set the upstream branch, use", "git push "+configuration.RemoteName+" "+currentBaseBranch+" --set-upstream")
 		return
@@ -531,7 +531,7 @@ func start(configuration Configuration) {
 		git("merge", "FETCH_HEAD", "--ff-only")
 	}
 
-	if hasRemoteBranch(currentWipBranch) {
+	if hasRemoteBranch(currentWipBranch, configuration) {
 		startJoinMobSession()
 	} else {
 		startNewMobSession()
@@ -645,7 +645,7 @@ func getCachedChanges() string {
 	return strings.TrimSpace(silentgit("diff", "--cached", "--stat"))
 }
 
-func done() {
+func done(configuration Configuration) {
 	if !isMobProgramming(configuration) {
 		sayError("you aren't mob programming")
 		sayTodo("to start mob programming, use", "mob start")
@@ -656,7 +656,7 @@ func done() {
 
 	currentBaseBranch, currentWipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
 
-	if hasRemoteBranch(currentWipBranch) {
+	if hasRemoteBranch(currentWipBranch, configuration) {
 		if !isNothingToCommit() {
 			git("add", "--all")
 			git("commit", "--message", configuration.WipCommitMessage, "--no-verify")
@@ -665,7 +665,7 @@ func done() {
 
 		git("checkout", currentBaseBranch)
 		git("merge", configuration.RemoteName+"/"+currentBaseBranch, "--ff-only")
-		mergeFailed := gitignorefailure("merge", squashOrNoCommit(), "--ff", currentWipBranch)
+		mergeFailed := gitignorefailure("merge", squashOrNoCommit(configuration), "--ff", currentWipBranch)
 		if mergeFailed != nil {
 			return
 		}
@@ -682,7 +682,7 @@ func done() {
 	}
 }
 
-func squashOrNoCommit() string {
+func squashOrNoCommit(configuration Configuration) string {
 	if configuration.MobDoneSquash {
 		return "--squash"
 	} else {
@@ -690,7 +690,7 @@ func squashOrNoCommit() string {
 	}
 }
 
-func status() {
+func status(configuration Configuration) {
 	if isMobProgramming(configuration) {
 		sayInfo("you are mob programming")
 
@@ -756,7 +756,7 @@ func hasLocalBranch(localBranch string) bool {
 	return false
 }
 
-func hasRemoteBranch(branch string) bool {
+func hasRemoteBranch(branch string, configuration Configuration) bool {
 	remoteBranches := gitRemoteBranches()
 	remoteBranch := configuration.RemoteName + "/" + branch
 	debugInfo("Remote Branches: " + strings.Join(remoteBranches, "\n"))


Test patch:
diff --git a/mob_test.go b/mob_test.go
index cf5033b..44c16ec 100644
--- a/mob_test.go
+++ b/mob_test.go
@@ -221,7 +221,7 @@ func TestVersion(t *testing.T) {
 func TestStatusNotMobProgramming(t *testing.T) {
 	output := setup(t)
 
-	status()
+	status(configuration)
 
 	assertOutputContains(t, output, "you aren't mob programming")
 }
@@ -269,7 +269,7 @@ func TestRequireCommitMessage(t *testing.T) {
 func TestDoneNotMobProgramming(t *testing.T) {
 	output := setup(t)
 
-	done()
+	done(configuration)
 
 	assertOutputContains(t, output, "you aren't mob programming")
 }
@@ -278,7 +278,7 @@ func TestStatusMobProgramming(t *testing.T) {
 	output := setup(t)
 	start(configuration)
 
-	status()
+	status(configuration)
 
 	assertOutputContains(t, output, "you are mob programming")
 }
@@ -294,7 +294,7 @@ func TestStatusWithMoreThan5LinesOfLog(t *testing.T) {
 	}
 
 	output := captureOutput()
-	status()
+	status(configuration)
 	assertOutputContains(t, output, "This mob branch contains 6 commits.")
 }
 
@@ -393,7 +393,7 @@ func TestStartNextWithBranch(t *testing.T) {
 	assertOnBranch(t, "master")
 
 	configuration.WipBranchQualifier = "green"
-	reset()
+	reset(configuration)
 	assertNoMobSessionBranches(t, "mob/master-green")
 }
 
@@ -445,7 +445,7 @@ func TestStartNextWithBranchContainingHyphen(t *testing.T) {
 func TestReset(t *testing.T) {
 	setup(t)
 
-	reset()
+	reset(configuration)
 
 	assertOnBranch(t, "master")
 	assertNoMobSessionBranches(t, "mob-session")
@@ -458,7 +458,7 @@ func TestResetCommit(t *testing.T) {
 	next(configuration)
 	assertMobSessionBranches(t, "mob-session")
 
-	reset()
+	reset(configuration)
 
 	assertOnBranch(t, "master")
 	assertNoMobSessionBranches(t, "mob-session")
@@ -539,7 +539,7 @@ func TestStartDoneWithMobDoneSquashTrue(t *testing.T) {
 	start(configuration)
 	assertOnBranch(t, "mob-session")
 
-	done()
+	done(configuration)
 
 	assertOnBranch(t, "master")
 	assertNoMobSessionBranches(t, "mob-session")
@@ -595,7 +595,7 @@ func TestStartDoneWithMobDoneSquashFalse(t *testing.T) {
 	start(configuration)
 	assertOnBranch(t, "mob-session")
 
-	done()
+	done(configuration)
 
 	assertOnBranch(t, "master")
 	assertNoMobSessionBranches(t, "mob-session")
@@ -613,7 +613,7 @@ func TestStartDonePublishingOneManualCommit(t *testing.T) {
 	createFileAndCommitIt(t, "example.txt", "content", "[manual-commit-1] publish this commit to master")
 	assertCommits(t, 2)
 
-	done() // without squash (configuration)
+	done(configuration) // without squash (configuration)
 
 	assertOnBranch(t, "master")
 	assertCommitsOnBranch(t, 2, "master")
@@ -634,7 +634,7 @@ func TestStartDoneSquashTheOneManualCommit(t *testing.T) {
 	createFileAndCommitIt(t, "example.txt", "content", "[manual-commit-1] publish this commit to master")
 	assertCommits(t, 2)
 
-	done()
+	done(configuration)
 
 	// MAYBE assertUnstagedChanges()
 	assertOnBranch(t, "master")
@@ -651,7 +651,7 @@ func TestStartDoneFeatureBranch(t *testing.T) {
 	start(configuration)
 	assertOnBranch(t, "mob/feature1")
 
-	done()
+	done(configuration)
 
 	assertOnBranch(t, "feature1")
 	assertNoMobSessionBranches(t, "mob-session")
@@ -786,7 +786,7 @@ func TestConflictingMobSessions(t *testing.T) {
 
 	setWorkingDir("/tmp/mob/local")
 	start(configuration)
-	done()
+	done(configuration)
 	git("commit", "-m", "\"finished mob session\"")
 
 	setWorkingDir("/tmp/mob/local")
@@ -813,7 +813,7 @@ func TestConflictingMobSessionsNextStay(t *testing.T) {
 
 	setWorkingDir("/tmp/mob/local")
 	start(configuration)
-	done()
+	done(configuration)
 	git("commit", "-m", "\"finished mob session\"")
 
 	setWorkingDir("/tmp/mob/localother")
@@ -834,7 +834,7 @@ func TestDoneMergeConflict(t *testing.T) {
 
 	setWorkingDir("/tmp/mob/local")
 	start(configuration)
-	done()
+	done(configuration)
 	assertOutputContains(t, output, "Automatic merge failed; fix conflicts and then commit the result.")
 }
 
@@ -852,7 +852,7 @@ func TestDoneMerge(t *testing.T) {
 
 	setWorkingDir("/tmp/mob/local")
 	start(configuration)
-	done()
+	done(configuration)
 	assertOutputContains(t, output, "   git commit")
 }
 
@@ -980,7 +980,7 @@ func assertOutputNotContains(t *testing.T, output *string, notContains string) {
 }
 
 func assertMobSessionBranches(t *testing.T, branch string) {
-	if !hasRemoteBranch(branch) {
+	if !hasRemoteBranch(branch, configuration) {
 		failWithFailure(t, configuration.RemoteName+"/"+branch, "none")
 	}
 	if !hasLocalBranch(branch) {
@@ -989,7 +989,7 @@ func assertMobSessionBranches(t *testing.T, branch string) {
 }
 
 func assertNoMobSessionBranches(t *testing.T, branch string) {
-	if hasRemoteBranch(branch) {
+	if hasRemoteBranch(branch, configuration) {
 		failWithFailure(t, "none", configuration.RemoteName+"/"+branch)
 	}
 	if hasLocalBranch(branch) {