Skip to content

Commit

Permalink
Fixes a bug where git hook is not ignored on start
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorriegler committed Sep 8, 2023
1 parent 8484ec5 commit ebb9c64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mob.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ func startNewMobSession(configuration config.Configuration) {

say.Info("starting new session from " + currentBaseBranch.remote(configuration).String())
git("checkout", "-B", currentWipBranch.Name, currentBaseBranch.remote(configuration).Name)
git("commit", "--allow-empty", "-m", configuration.StartCommitMessage)
git("commit", gitHooksOption(configuration), "--allow-empty", "-m", configuration.StartCommitMessage)
gitPush(gitHooksOption(configuration), "--set-upstream", configuration.RemoteName, currentWipBranch.Name+":"+currentWipBranch.Name)
}

Expand Down
20 changes: 20 additions & 0 deletions mob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ func TestStart(t *testing.T) {
assertMobSessionBranches(t, configuration, "mob-session")
}

func TestStartDespiteGitHook(t *testing.T) {
_, configuration := setup(t)
createExecutableFileInPath(t, workingDir+"/.git/hooks", "pre-commit", "#!/bin/sh\necho 'boo'\nexit 1\n")

start(configuration)

assertOnBranch(t, "mob-session")
assertMobSessionBranches(t, configuration, "mob-session")
}

func TestStartWithCISkip(t *testing.T) {
_, configuration := setup(t)

Expand Down Expand Up @@ -2050,6 +2060,16 @@ func createFileInPath(t *testing.T, path, filename, content string) (pathToFile
return
}

func createExecutableFileInPath(t *testing.T, path, filename, content string) (pathToFile string) {
contentAsBytes := []byte(content)
pathToFile = path + "/" + filename
err := os.WriteFile(pathToFile, contentAsBytes, 0755)
if err != nil {
failWithFailure(t, "creating file "+filename+" with content "+content, "error")
}
return
}

func createDirectory(t *testing.T, directory string) (pathToFile string) {
return createDirectoryInPath(t, workingDir, directory)
}
Expand Down

0 comments on commit ebb9c64

Please sign in to comment.