From 32282739ce33aac808791c5665b27f731803718f Mon Sep 17 00:00:00 2001 From: David Alpert Date: Mon, 6 May 2024 18:51:04 -0500 Subject: [PATCH] fix: prepare-commit-msg script fails when cannot find git mob fix: GH-141 --- features/git-mob/mob-init.feature | 8 -------- features/git-mob/uninstall.feature | 15 ++++++--------- internal/cmd/mob_init.go | 2 +- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/features/git-mob/mob-init.feature b/features/git-mob/mob-init.feature index 6c23000..41fca2c 100644 --- a/features/git-mob/mob-init.feature +++ b/features/git-mob/mob-init.feature @@ -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: diff --git a/features/git-mob/uninstall.feature b/features/git-mob/uninstall.feature index d6aa606..882916b 100644 --- a/features/git-mob/uninstall.feature +++ b/features/git-mob/uninstall.feature @@ -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 @@ -60,9 +60,10 @@ 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" @@ -70,8 +71,4 @@ Feature: uninstall 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'. - """ \ No newline at end of file + Then the exit status should be 0 \ No newline at end of file diff --git a/internal/cmd/mob_init.go b/internal/cmd/mob_init.go index 442edc6..6a80980 100644 --- a/internal/cmd/mob_init.go +++ b/internal/cmd/mob_init.go @@ -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)