Repository: remotemobprogramming/mob
Pull request #305 (2022-09-16 15:48:30)

added reset warning and delete-remote-wip-branch parameter
adds functionality of #298

simonharrer: Be aware that this is a breaking change.
hollesse: I also see there is another parameter for reset. I did not test it with this parameter. I will add a test for this.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 941d018..b20629d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
-# 3.3.0
+# 4.0.0
+- **NEW** Feature: `mob reset` doesn't reset the mob branch anymore. It now warns you that it deletes the mob branch for everyone and if you want to continue do `mob reset --delete-remote-wip-branch`.
 - Feature: `mob start --create` will create the remote branch and start the mob session on that branch. 
 
 # 3.2.0
diff --git a/mob.go b/mob.go
index d55f0e5..d689dfe 100644
--- a/mob.go
+++ b/mob.go
@@ -22,7 +22,7 @@ import (
 )
 
 const (
-	versionNumber = "3.3.0"
+	versionNumber = "4.0.0"
 )
 
 var (
@@ -74,6 +74,7 @@ type Configuration struct {
 	TimerUser                      string // override with MOB_TIMER_USER
 	TimerUrl                       string // override with MOB_TIMER_URL
 	TimerInsecure                  bool   // override with MOB_TIMER_INSECURE
+	ResetDeleteRemoteWipBranch     bool   // override with MOB_RESET_DELETE_REMOTE_WIP_BRANCH
 }
 
 func (c Configuration) wipBranchQualifierSuffix() string {
@@ -333,6 +334,7 @@ func getDefaultConfiguration() Configuration {
 		TimerUrl:                       "https://timer.mob.sh/",
 		WipBranchPrefix:                "mob/",
 		StashName:                      "mob-stash-name",
+		ResetDeleteRemoteWipBranch:     false,
 	}
 }
 
@@ -424,6 +426,8 @@ func parseUserConfiguration(configuration Configuration, path string) Configurat
 			setUnquotedString(&configuration.StashName, key, value)
 		case "MOB_TIMER_INSECURE":
 			setBoolean(&configuration.TimerInsecure, key, value)
+		case "MOB_RESET_DELETE_REMOTE_WIP_BRANCH":
+			setBoolean(&configuration.ResetDeleteRemoteWipBranch, key, value)
 
 		default:
 			continue
@@ -503,6 +507,8 @@ func parseProjectConfiguration(configuration Configuration, path string) Configu
 			setUnquotedString(&configuration.StashName, key, value)
 		case "MOB_TIMER_INSECURE":
 			setBoolean(&configuration.TimerInsecure, key, value)
+		case "MOB_RESET_DELETE_REMOTE_WIP_BRANCH":
+			setBoolean(&configuration.ResetDeleteRemoteWipBranch, key, value)
 
 		default:
 			continue
@@ -593,6 +599,8 @@ func parseEnvironmentVariables(configuration Configuration) Configuration {
 	setStringFromEnvVariable(&configuration.TimerUrl, "MOB_TIMER_URL")
 	setBoolFromEnvVariable(&configuration.TimerInsecure, "MOB_TIMER_INSECURE")
 
+	setBoolFromEnvVariable(&configuration.ResetDeleteRemoteWipBranch, "MOB_RESET_DELETE_REMOTE_WIP_BRANCH")
+
 	return configuration
 }
 
@@ -743,6 +751,8 @@ func parseArgs(args []string, configuration Configuration) (command string, para
 			newConfiguration.DoneSquash = SquashWip
 		case "--create":
 			newConfiguration.StartCreate = true
+		case "--delete-remote-wip-branch":
+			newConfiguration.ResetDeleteRemoteWipBranch = true
 		default:
 			if i == 1 {
 				command = arg
@@ -1144,6 +1154,14 @@ func moo(configuration Configuration) {
 }
 
 func reset(configuration Configuration) {
+	if configuration.ResetDeleteRemoteWipBranch {
+		deleteRemoteWipBranch(configuration)
+	} else {
+		sayFix("Executing this command deletes the mob branch for everyone. If you're sure you want that, use", configuration.mob("reset --delete-remote-wip-branch"))
+	}
+}
+
+func deleteRemoteWipBranch(configuration Configuration) {
 	git("fetch", configuration.RemoteName)
 
 	currentBaseBranch, currentWipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration)


Test patch:
diff --git a/mob_test.go b/mob_test.go
index be26115..0675116 100644
--- a/mob_test.go
+++ b/mob_test.go
@@ -504,6 +504,7 @@ func TestStartWithMultipleExistingBranchesWithStay(t *testing.T) {
 
 func TestStartNextWithBranch(t *testing.T) {
 	_, configuration := setup(t)
+	configuration.ResetDeleteRemoteWipBranch = true
 	assertOnBranch(t, "master")
 	configuration.WipBranchQualifier = "green"
 
@@ -595,7 +596,16 @@ func TestStartNextWithBranchContainingHyphen(t *testing.T) {
 }
 
 func TestReset(t *testing.T) {
+	output, configuration := setup(t)
+
+	reset(configuration)
+
+	assertOutputContains(t, output, "mob reset --delete-remote-wip-branch")
+}
+
+func TestResetDeleteRemoteWipBranch(t *testing.T) {
 	_, configuration := setup(t)
+	configuration.ResetDeleteRemoteWipBranch = true
 
 	reset(configuration)
 
@@ -604,7 +614,23 @@ func TestReset(t *testing.T) {
 }
 
 func TestResetCommit(t *testing.T) {
+	output, configuration := setup(t)
+
+	start(configuration)
+	createFile(t, "example.txt", "contentIrrelevant")
+	next(configuration)
+	assertMobSessionBranches(t, configuration, "mob-session")
+
+	reset(configuration)
+
+	assertOutputContains(t, output, "mob reset --delete-remote-wip-branch")
+	assertMobSessionBranches(t, configuration, "mob-session")
+}
+
+func TestResetDeleteRemoteWipBranchCommit(t *testing.T) {
 	_, configuration := setup(t)
+	configuration.ResetDeleteRemoteWipBranch = true
+
 	start(configuration)
 	createFile(t, "example.txt", "contentIrrelevant")
 	next(configuration)