Skip to content

Commit

Permalink
fix: prepare-commit-msg script fails when cannot find git mob
Browse files Browse the repository at this point in the history
fix: GH-141
  • Loading branch information
davidalpert committed May 6, 2024
1 parent 2771323 commit 3228273
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
8 changes: 0 additions & 8 deletions features/git-mob/mob-init.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ Feature: mob-init
Then the file ".git/hooks/prepare-commit-msg" should exist
And the file ".git/hooks/prepare-commit-msg" should contain:
"""
#!/bin/sh
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3
set -e
git mob hooks prepare-commit-msg "$COMMIT_MSG_FILE" $COMMIT_SOURCE $SHA1
"""
And the output should contain:
Expand Down
15 changes: 6 additions & 9 deletions features/git-mob/uninstall.feature
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Feature: uninstall
And a file named "local_bin/git-solo" should not exist
And a file named "local_bin/git-suggest-coauthors" should not exist

Scenario: uninstall can break hook scripts
Scenario: uninstall no longer breaks hook scripts

`git mob` doesn't track the initialization of hook scripts
so it doesn't know what hook scripts to remove when it
Expand All @@ -60,18 +60,15 @@ Feature: uninstall
check your `.git/hooks/prepare-commit-msg` hook script
and remove or comment out references to `git mob`

:warning: if you have `git-mob` in your path when you run
this scenario it may fail as it expects to find
no `git-mob` instance after running `uninstall`
:information_source: this bug was fixed in GH-141 by updating
the prepare-commit-msg script to fail
silently if it cannot find the git mob
plugin

Given a simple git repo at "example"
And I cd to "example"
And I successfully run `git mob init`
And I successfully run `git commit --allow-empty -m "empty mobbed commit"`
When I successfully run `git mob uninstall`
And I run `git commit --allow-empty -m "empty mobbed commit"`
Then the exit status should be 1
And the output should contain:
"""
git: 'mob' is not a git command. See 'git --help'.
"""
Then the exit status should be 0
2 changes: 1 addition & 1 deletion internal/cmd/mob_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ SHA1=$3
set -e
git mob hooks prepare-commit-msg "$COMMIT_MSG_FILE" $COMMIT_SOURCE $SHA1
if [ -z "$(which git-mob)" ]; then echo "WARNING: could not locate 'git-mob'; commits will not be prepared"; else git mob hooks prepare-commit-msg "$COMMIT_MSG_FILE" $COMMIT_SOURCE $SHA1; fi
`
if err := os.WriteFile(fileName, []byte(fileContents), 0755); err != nil {
return fmt.Errorf("writing git hook: %v", err)
Expand Down

0 comments on commit 3228273

Please sign in to comment.