Repository: remotemobprogramming/mob
Pull request #301 (2022-08-16 18:36:25)

Fix done squashWip fails on uncommitted modification of previously co…
…mmitted file.

Addresses #300 


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7194f18..e33dd30 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,8 @@
+# 3.1.6
+- Fix: `mob done --squash-wip` won't fail if a previously committed file has uncommitted modifications.
+
 # 3.1.5
 - Add a more specific error message if `git` is not installed.
-- Allow for using `mob timer` outside of git repositories.
 - Fix: `mob done --squash-wip` now successfully auto-merges auto-mergeable diverging changes.
 - Print the help output whenever any kind of help argument (`help`, `--help`, `-h`) is present in the command, e.g. `mob s 10 -h`.
 - Adds a warning to `mob start` in case the wip branch diverges from the main branch.
diff --git a/mob.go b/mob.go
index 089fbbf..1927c6f 100644
--- a/mob.go
+++ b/mob.go
@@ -19,7 +19,7 @@ import (
 )
 
 const (
-	versionNumber = "3.1.5"
+	versionNumber = "3.1.4"
 )
 
 var (
@@ -964,11 +964,6 @@ func startTimer(timerInMinutes string, configuration Configuration) {
 }
 
 func getMobTimerRoom(configuration Configuration) string {
-	if !isGit() {
-		debugInfo("timer not in git repository, using MOB_TIMER_ROOM for room name")
-		return configuration.TimerRoom
-	}
-
 	currentWipBranchQualifier := configuration.WipBranchQualifier
 	if currentWipBranchQualifier == "" {
 		currentBranch := gitCurrentBranch()
@@ -984,7 +979,6 @@ func getMobTimerRoom(configuration Configuration) string {
 		sayInfo("Using wip branch qualifier for room name")
 		return currentWipBranchQualifier
 	}
-
 	return configuration.TimerRoom
 }
 
@@ -1451,15 +1445,14 @@ func done(configuration Configuration) {
 		return
 	}
 
-	if configuration.DoneSquash == SquashWip {
-		squashWip(configuration)
-	}
-
 	git("fetch", configuration.RemoteName, "--prune")
 
 	baseBranch, wipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
 
 	if wipBranch.hasRemoteBranch(configuration) {
+		if configuration.DoneSquash == SquashWip {
+			squashWip(configuration)
+		}
 		uncommittedChanges := hasUncommittedChanges()
 		if uncommittedChanges {
 			makeWipCommit(configuration)
diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
index c162ac3..8fe8b5c 100644
--- a/snap/snapcraft.yaml
+++ b/snap/snapcraft.yaml
@@ -1,6 +1,6 @@
 name: mob-sh
 base: core18
-version: "3.1.5"
+version: "3.1.3"
 summary: Fast git handover with mob
 description: |
   Smooth git handover with 'mob' for remote mob or pair programming.
diff --git a/squash_wip.go b/squash_wip.go
index 792d07b..e081283 100644
--- a/squash_wip.go
+++ b/squash_wip.go
@@ -11,6 +11,9 @@ import (
 type Replacer func(string) string
 
 func squashWip(configuration Configuration) {
+	if hasUncommittedChanges() {
+		makeWipCommit(configuration)
+	}
 	currentBaseBranch, currentWipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
 	mergeBase := silentgit("merge-base", currentWipBranch.String(), currentBaseBranch.remote(configuration).String())
 


Test patch:
diff --git a/mob_test.go b/mob_test.go
index f0d3e0d..cdd2ffa 100644
--- a/mob_test.go
+++ b/mob_test.go
@@ -1099,6 +1099,26 @@ func TestStartDoneSquashWipWithUncommittedChanges(t *testing.T) {
 	assertNoMobSessionBranches(t, configuration, "mob-session")
 }
 
+func TestStartDoneSquashWipPublishingOneManualCommitHasUncommittedModifications(t *testing.T) {
+	_, configuration := setup(t)
+	configuration.DoneSquash = SquashWip
+
+	start(configuration)
+	createFileAndCommitIt(t, "example.txt", "contentIrrelevant", "[manual-commit-1] publish this commit to master")
+
+	createFile(t, "example.txt", "contentIrrelevant2") // modify previously committed file
+	done(configuration)
+
+	assertOnBranch(t, "master")
+	assertGitStatus(t, GitStatus{
+		"example.txt": "M",
+	})
+	assertCommitsOnBranch(t, 2, "master")
+	assertCommitLogContainsMessage(t, "master", "[manual-commit-1] publish this commit to master")
+	assertCommitsOnBranch(t, 1, "origin/master")
+	assertNoMobSessionBranches(t, configuration, "mob-session")
+}
+
 func TestStartDoneSquashWipOneWipCommitAfterManualCommit(t *testing.T) {
 	_, configuration := setup(t)
 
diff --git a/squash_wip_test.go b/squash_wip_test.go
index 6512149..2bdca8d 100644
--- a/squash_wip_test.go
+++ b/squash_wip_test.go
@@ -90,6 +90,21 @@ func TestSquashWipCommits_onlyWipCommits(t *testing.T) {
 	equals(t, []string{""}, commitsOnCurrentBranch(configuration))
 }
 
+func TestSquashWipCommits_uncommittedModificationOfCommittedFile(t *testing.T) {
+	_, configuration := setup(t)
+	manualCommit(t, configuration, "file1.txt", "first manual commit")
+	start(configuration)
+	createFile(t, "file1.txt", "change")
+
+	squashWip(configuration)
+
+	assertOnBranch(t, "mob-session")
+	assertGitStatus(t, GitStatus{
+		"file1.txt": "M",
+	})
+	equals(t, []string{"first manual commit"}, commitsOnCurrentBranch(configuration))
+}
+
 func TestSquashWipCommits_resetsEnv(t *testing.T) {
 	_, configuration := setup(t)
 	start(configuration)