Skip to content

Commit

Permalink
Merge pull request #147 from davidalpert/GH-141-hook-scripts-fail-wit…
Browse files Browse the repository at this point in the history
…hout-login-shell

fix: prepare-commit-msg script fails when cannot find git mob
  • Loading branch information
davidalpert authored May 7, 2024
2 parents 2771323 + 63f9560 commit 12807a6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ jobs:

- name: Setup build dependencies
run: |
go install github.com/kisielk/godepgraph@latest
echo skipping: go install github.com/kisielk/godepgraph@latest
go install github.com/restechnica/semverbot/cmd/sbot@latest
go install github.com/siderolabs/conform/cmd/conform@latest
echo skipping: go install github.com/siderolabs/conform/cmd/conform@latest
go install github.com/git-chglog/git-chglog/cmd/git-chglog@v0.15.1
- name: Validate build dependencies
Expand Down
75 changes: 38 additions & 37 deletions .tools/doctor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,50 +173,51 @@ grepVersion 'ruby' 'ruby --version' "$REQUIRED_RUBY_VERSION"
findCmd gem
findCmd bundle 'gem install bundler'

findCmd godepgraph "go install github.com/kisielk/godepgraph@latest"
# see: https://github.com/siderolabs/conform/issues/251
#findCmd godepgraph "go install github.com/kisielk/godepgraph@latest"

findCmd sbot "go install github.com/restechnica/semverbot/cmd/sbot@latest"
if [ ! -f .semverbot.toml ]; then
note "initializing sbot"
sbot init
fi

findCmd conform "go install github.com/siderolabs/conform/cmd/conform@latest"
if [ ! -f .conform.yaml ]; then
note "initializing conform"
cat << EOD > .conform.yaml
policies: []
- type: commit
spec:
header:
length: 80
imperative: true
case: lower
invalidLastCharacters: .
body:
required: false
gpg:
required: false
spellcheck:
locale: US
maximumOfOneCommit: false
conventional:
types:
- "build" # Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
- "ci" # Changes to our CI configuration files and scripts (examples: CircleCi, SauceLabs)
- "docs" # Documentation only changes
- "feat" # A new feature
- "fix" # A bug fix
- "perf" # A code change that improves performance
- "refactor" # A code change that neither fixes a bug nor adds a feature
- "test" # Adding missing tests or correcting existing tests
scopes:
- "migration"
- "import"
- "frontend"
descriptionLength: 72
EOD
fi
#findCmd conform "go install github.com/siderolabs/conform/cmd/conform@latest"
#if [ ! -f .conform.yaml ]; then
# note "initializing conform"
# cat << EOD > .conform.yaml
#policies: []
# - type: commit
# spec:
# header:
# length: 80
# imperative: true
# case: lower
# invalidLastCharacters: .
# body:
# required: false
# gpg:
# required: false
# spellcheck:
# locale: US
# maximumOfOneCommit: false
# conventional:
# types:
# - "build" # Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
# - "ci" # Changes to our CI configuration files and scripts (examples: CircleCi, SauceLabs)
# - "docs" # Documentation only changes
# - "feat" # A new feature
# - "fix" # A bug fix
# - "perf" # A code change that improves performance
# - "refactor" # A code change that neither fixes a bug nor adds a feature
# - "test" # Adding missing tests or correcting existing tests
# scopes:
# - "migration"
# - "import"
# - "frontend"
# descriptionLength: 72
#EOD
#fi

findCmd git-chglog "go install github.com/git-chglog/git-chglog/cmd/git-chglog@v0.15.1"
if [ ! -f .chglog/config.yml ]; then
Expand Down
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
2 changes: 1 addition & 1 deletion features/git-mob/parity/git-mob.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Feature: git-mob.spec
Then the output should contain "/home/.git-coauthors"

#@announce-stderr
@not-windows
@not-windows @wip
Scenario: --help prints help
# --help is intercepted by the git plugin launcher which returns a 404 (help not found)
When I run `git mob --help`
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 12807a6

Please sign in to comment.