Repository: remotemobprogramming/mob
Pull request #161 (2021-04-01 18:24:46)

silentgit always trims


Patch:
diff --git a/mob.go b/mob.go
index 090981d..f2cd0d8 100644
--- a/mob.go
+++ b/mob.go
@@ -636,11 +636,11 @@ func next(configuration Configuration) {
 }
 
 func getChangesOfLastCommit() string {
-	return strings.TrimSpace(silentgit("diff", "HEAD^1", "--stat"))
+	return silentgit("diff", "HEAD^1", "--stat")
 }
 
 func getCachedChanges() string {
-	return strings.TrimSpace(silentgit("diff", "--cached", "--stat"))
+	return silentgit("diff", "--cached", "--stat")
 }
 
 func makeWipCommit(configuration Configuration) {
@@ -690,7 +690,7 @@ func done(configuration Configuration) {
 }
 
 func gitDir() string {
-	return strings.TrimSpace(silentgit("rev-parse", "--absolute-git-dir"))
+	return silentgit("rev-parse", "--absolute-git-dir")
 }
 
 func squashOrNoCommit(configuration Configuration) string {
@@ -720,7 +720,7 @@ func status(configuration Configuration) {
 
 func sayLastCommitsList(currentBaseBranch string, currentWipBranch string) {
 	log := silentgit("--no-pager", "log", currentBaseBranch+".."+currentWipBranch, "--pretty=format:%h %cr <%an>", "--abbrev-commit")
-	lines := strings.Split(strings.TrimSpace(log), "\n")
+	lines := strings.Split(log, "\n")
 	if len(lines) > 5 {
 		sayInfo("This mob branch contains " + strconv.Itoa(len(lines)) + " commits. The last 5 were:")
 		lines = lines[:5]
@@ -731,7 +731,7 @@ func sayLastCommitsList(currentBaseBranch string, currentWipBranch string) {
 
 func isNothingToCommit() bool {
 	output := silentgit("status", "--short")
-	return len(strings.TrimSpace(output)) == 0
+	return len(output) == 0
 }
 
 func hasLocalCommits(branch string, configuration Configuration) bool {
@@ -739,7 +739,7 @@ func hasLocalCommits(branch string, configuration Configuration) bool {
 		"refs/heads/"+branch)
 	remote := silentgit("for-each-ref", "--format=%(objectname)",
 		"refs/remotes/"+configuration.RemoteName+"/"+branch)
-	return strings.TrimSpace(local) != strings.TrimSpace(remote)
+	return local != remote
 }
 
 func hasUncommittedChanges() bool {
@@ -783,24 +783,24 @@ func hasRemoteBranch(branch string, configuration Configuration) bool {
 }
 
 func gitBranches() []string {
-	return strings.Split(strings.TrimSpace(silentgit("branch", "--format=%(refname:short)")), "\n")
+	return strings.Split(silentgit("branch", "--format=%(refname:short)"), "\n")
 }
 
 func gitRemoteBranches() []string {
-	return strings.Split(strings.TrimSpace(silentgit("branch", "--remotes", "--format=%(refname:short)")), "\n")
+	return strings.Split(silentgit("branch", "--remotes", "--format=%(refname:short)"), "\n")
 }
 
 func gitCurrentBranch() string {
 	// upgrade to branch --show-current when git v2.21 is more widely spread
-	return strings.TrimSpace(silentgit("rev-parse", "--abbrev-ref", "HEAD"))
+	return silentgit("rev-parse", "--abbrev-ref", "HEAD")
 }
 
 func gitUserName() string {
-	return strings.TrimSpace(silentgit("config", "--get", "user.name"))
+	return silentgit("config", "--get", "user.name")
 }
 
 func gitUserEmail() string {
-	return strings.TrimSpace(silentgit("config", "--get", "user.email"))
+	return silentgit("config", "--get", "user.email")
 }
 
 func showNext(configuration Configuration) {
@@ -808,7 +808,7 @@ func showNext(configuration Configuration) {
 
 	currentBaseBranch, currentWipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
 
-	changes := strings.TrimSpace(silentgit("--no-pager", "log", currentBaseBranch+".."+currentWipBranch, "--pretty=format:%an", "--abbrev-commit"))
+	changes := silentgit("--no-pager", "log", currentBaseBranch+".."+currentWipBranch, "--pretty=format:%an", "--abbrev-commit")
 	lines := strings.Split(strings.Replace(changes, "\r\n", "\n", -1), "\n")
 	numberOfLines := len(lines)
 	debugInfo("there have been " + strconv.Itoa(numberOfLines) + " changes")
@@ -883,7 +883,7 @@ func silentgit(args ...string) string {
 		sayGitError(commandString, output, err)
 		exit(1)
 	}
-	return output
+	return strings.TrimSpace(output)
 }
 
 func git(args ...string) {


Test patch:
diff --git a/mob_test.go b/mob_test.go
index dc94ffe..aa7056b 100644
--- a/mob_test.go
+++ b/mob_test.go
@@ -520,7 +520,7 @@ func TestStartNextStay(t *testing.T) {
 
 	next(configuration)
 
-	equals(t, strings.TrimSpace(silentgit("log", "--format=%B", "-n", "1", "HEAD")), configuration.WipCommitMessage)
+	equals(t, silentgit("log", "--format=%B", "-n", "1", "HEAD"), configuration.WipCommitMessage)
 	assertOnBranch(t, "mob-session")
 }
 
@@ -941,7 +941,7 @@ func assertCommits(t *testing.T, commits int) {
 
 func assertCommitsOnBranch(t *testing.T, commits int, branchName string) {
 	result := silentgit("rev-list", "--count", branchName)
-	number, _ := strconv.Atoi(strings.TrimSpace(result))
+	number, _ := strconv.Atoi(result)
 	if number != commits {
 		failWithFailure(t, strconv.Itoa(commits)+" commits in "+workingDir, strconv.Itoa(number)+" commits in "+workingDir)
 	}