Skip to content

Commit b09fc50

Browse files
Merge pull request remotemobprogramming#386 from remotemobprogramming/fixMissingParameterInFix
fix the logging how to fix uncommited changes
2 parents 38d09b6 + 3c7f02b commit b09fc50

File tree

6 files changed

+102
-24
lines changed

6 files changed

+102
-24
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ jobs:
3333
sudo make install install-info
3434
- name: Show git version
3535
run: git version
36-
- name: Use Go 1.16.x
37-
uses: actions/setup-go@v2
36+
- name: Use Go 1.20.x
37+
uses: actions/setup-go@v4
3838
with:
39-
go-version: '~1.16.0'
39+
go-version: '~1.20'
4040
- name: Test
4141
run: go test -test.v

.github/workflows/release.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
sha_linux: ${{ steps.shasum.outputs.sha_linux }}
1717
steps:
1818
- uses: actions/checkout@main
19-
- name: Use Go 1.16.x
20-
uses: actions/setup-go@v2
19+
- name: Use Go 1.20.x
20+
uses: actions/setup-go@v4
2121
with:
22-
go-version: '~1.16.0'
22+
go-version: '~1.20'
2323
- name: Test
2424
run: go test
2525
env:

.github/workflows/virustotal.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
uses: actions/checkout@v3
1212
-
1313
name: Set up Go
14-
uses: actions/setup-go@v3
14+
uses: actions/setup-go@v4
1515
with:
16-
go-version: '~1.16.0'
16+
go-version: '~1.20'
1717
-
1818
name: Build
1919
run: |

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/remotemobprogramming/mob/v4
22

3-
go 1.15
3+
go 1.20

mob.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const (
3333

3434
var (
3535
workingDir = ""
36+
args []string
3637
GitPassthroughStderrStdout = false // hack to get git hooks to print to stdout/stderr
3738
)
3839

@@ -233,7 +234,8 @@ func main() {
233234
run(os.Args)
234235
}
235236

236-
func run(args []string) {
237+
func run(osArgs []string) {
238+
args = osArgs
237239
say.TurnOnDebuggingByArgs(args)
238240
say.Debug(runtime.Version())
239241

@@ -818,11 +820,7 @@ func start(configuration config.Configuration) error {
818820
say.Info("cannot start; clean working tree required")
819821
sayUnstagedChangesInfo()
820822
sayUntrackedFilesInfo()
821-
if configuration.StartCreate {
822-
say.Fix("To start, including uncommitted changes and create the remote branch, use", configuration.Mob("start --create --include-uncommitted-changes"))
823-
} else {
824-
say.Fix("To start, including uncommitted changes, use", configuration.Mob("start --include-uncommitted-changes"))
825-
}
823+
sayFixUncommitedChanges(configuration)
826824
return errors.New("cannot start; clean working tree required")
827825
}
828826

@@ -880,6 +878,36 @@ func start(configuration config.Configuration) error {
880878
return nil // no error
881879
}
882880

881+
func sayFixUncommitedChanges(configuration config.Configuration) {
882+
fixCommand := configuration.CliName + " start"
883+
instruction := "To start, including uncommitted changes, use"
884+
if configuration.StartCreate {
885+
instruction = "To start, including uncommitted changes and create the remote branch, use"
886+
fixCommand += " --create"
887+
}
888+
if containsAny(args, "-b", "--branch") && configuration.WipBranchQualifier != "" {
889+
fixCommand += " --branch " + configuration.WipBranchQualifier
890+
}
891+
fixCommand += " --include-uncommitted-changes"
892+
893+
say.Fix(instruction, fixCommand)
894+
}
895+
896+
func branchParameter(configuration config.Configuration) bool {
897+
return containsAny(args, "-b", "--branch") && configuration.WipBranchQualifier != ""
898+
}
899+
900+
func containsAny(list []string, elements ...string) bool {
901+
for _, value := range list {
902+
for _, element := range elements {
903+
if value == element {
904+
return true
905+
}
906+
}
907+
}
908+
return false
909+
}
910+
883911
func createRemoteBranch(configuration config.Configuration, currentBaseBranch Branch) {
884912
if !currentBaseBranch.hasRemoteBranch(configuration) && configuration.StartCreate {
885913
git("push", configuration.RemoteName, currentBaseBranch.String(), "--set-upstream")

mob_test.go

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,53 @@ func TestStartNextPushManualCommits(t *testing.T) {
14061406
assertFileExist(t, "example.txt")
14071407
}
14081408

1409+
func TestStartBranchWithUncommitedChangesFixWithBranch(t *testing.T) {
1410+
output, _ := setup(t)
1411+
1412+
setWorkingDir(tempDir + "/local")
1413+
1414+
createFile(t, "uncommited.txt", "contentIrrelevant")
1415+
runMob(t, tempDir+"/local", "start", "-b", "green")
1416+
1417+
assertOutputContains(t, output, "mob start --branch green --include-uncommitted-changes")
1418+
}
1419+
1420+
func TestStartBranchEnvWithUncommitedChangesFixWithoutBranch(t *testing.T) {
1421+
output, _ := setup(t)
1422+
1423+
setWorkingDir(tempDir + "/local")
1424+
t.Setenv("MOB_WIP_BRANCH_QUALIFIER", "red")
1425+
createFile(t, "uncommited.txt", "contentIrrelevant")
1426+
runMob(t, tempDir+"/local", "start")
1427+
1428+
assertOutputContains(t, output, "mob start --include-uncommitted-changes")
1429+
}
1430+
1431+
func TestStartCreateBranchWithUncommitedChangesFixWithBranch(t *testing.T) {
1432+
output, _ := setup(t)
1433+
1434+
setWorkingDir(tempDir + "/local")
1435+
1436+
git("checkout", "-b", "unpushedBranch")
1437+
createFile(t, "uncommited.txt", "contentIrrelevant")
1438+
runMob(t, tempDir+"/local", "start", "--create", "-b", "green")
1439+
1440+
assertOutputContains(t, output, "mob start --create --branch green --include-uncommitted-changes")
1441+
}
1442+
1443+
func TestStartCreateBranchEnvWithUncommitedChangesFixWithoutBranch(t *testing.T) {
1444+
output, _ := setup(t)
1445+
1446+
setWorkingDir(tempDir + "/local")
1447+
os.Setenv("MOB_WIP_BRANCH_QUALIFIER", "red")
1448+
git("checkout", "-b", "unpushedBranch")
1449+
createFile(t, "uncommited.txt", "contentIrrelevant")
1450+
runMob(t, tempDir+"/local", "start", "--create")
1451+
1452+
os.Unsetenv("MOB_WIP_BRANCH_QUALIFIER")
1453+
assertOutputContains(t, output, "mob start --create --include-uncommitted-changes")
1454+
}
1455+
14091456
func TestStartNextPushManualCommitsFeatureBranch(t *testing.T) {
14101457
_, configuration := setup(t)
14111458

@@ -1783,46 +1830,49 @@ func TestGitVersionCompare(t *testing.T) {
17831830
}
17841831

17851832
func TestMobConfigWorksOutsideOfGitRepository(t *testing.T) {
1786-
output := runMob(t, t.TempDir(), "config")
1833+
output := captureOutput(t)
1834+
runMob(t, t.TempDir(), "config")
17871835

17881836
assertOutputNotContains(t, output, "ERROR")
17891837
assertOutputContains(t, output, "MOB_CLI_NAME=\"mob\"")
17901838
}
17911839

17921840
func TestMobHelpWorksOutsideOfGitRepository(t *testing.T) {
1793-
output := runMob(t, t.TempDir(), "help")
1841+
output := captureOutput(t)
1842+
runMob(t, t.TempDir(), "help")
17941843

17951844
assertOutputNotContains(t, output, "ERROR")
17961845
assertOutputContains(t, output, "Basic Commands:")
17971846
}
17981847

17991848
func TestMobShowsHelpIfCommandIsUnknownAndOutsideOfGitRepository(t *testing.T) {
1800-
output := runMob(t, t.TempDir(), "unknown")
1849+
output := captureOutput(t)
1850+
runMob(t, t.TempDir(), "unknown")
18011851

18021852
assertOutputNotContains(t, output, "ERROR")
18031853
assertOutputContains(t, output, "Basic Commands:")
18041854
}
18051855

18061856
func TestMobMooWorksOutsideOfGitRepository(t *testing.T) {
1807-
output := runMob(t, t.TempDir(), "help")
1857+
output := captureOutput(t)
1858+
runMob(t, t.TempDir(), "help")
18081859

18091860
assertOutputNotContains(t, output, "ERROR")
18101861
assertOutputContains(t, output, "moo")
18111862
}
18121863

18131864
func TestMobVersionWorksOutsideOfGitRepository(t *testing.T) {
1814-
output := runMob(t, t.TempDir(), "version")
1865+
output := captureOutput(t)
1866+
runMob(t, t.TempDir(), "version")
18151867

18161868
assertOutputNotContains(t, output, "ERROR")
18171869
assertOutputContains(t, output, "v"+versionNumber)
18181870
}
18191871

1820-
func runMob(t *testing.T, workingDir string, args ...string) *string {
1872+
func runMob(t *testing.T, workingDir string, args ...string) {
18211873
setWorkingDir(workingDir)
1822-
output := captureOutput(t)
18231874
newArgs := append([]string{"mob"}, args...)
18241875
run(newArgs)
1825-
return output
18261876
}
18271877

18281878
func gitStatus() GitStatus {
@@ -1842,13 +1892,13 @@ func gitStatus() GitStatus {
18421892
func setup(t *testing.T) (output *string, configuration config.Configuration) {
18431893
configuration = config.GetDefaultConfiguration()
18441894
configuration.NextStay = false
1845-
output = captureOutput(t)
18461895
createTestbed(t, configuration)
18471896
assertOnBranch(t, "master")
18481897
equals(t, []string{"master"}, gitBranches())
18491898
equals(t, []string{"origin/master"}, gitRemoteBranches())
18501899
assertNoMobSessionBranches(t, configuration, "mob-session")
18511900
abortRunningTimers()
1901+
output = captureOutput(t)
18521902
return output, configuration
18531903
}
18541904

0 commit comments

Comments
 (0)