arxanas / git-branchless

High-velocity, monorepo-scale workflow for Git
Apache License 2.0
3.37k stars 80 forks source link

git-branchless amend skips pre-commit hook #1275

Closed peeeeter closed 1 month ago

peeeeter commented 3 months ago

Description of the bug

git-branchless amend has some deviations from git commit amend, notably, it doesn't resign and it doesn't run the pre-commit hook.

Expected behavior

Expect that git-branchless amend has similar side-effects to

git commit --amend --no-edit

Actual behavior

the precommit hook is not called, and it is not resigned.

Version of rustc

No response

Automated bug report

Software version

git-branchless 0.8.0

Operating system

macOS 14.4 (Darwin 23.4.0)

Command-line

git-branchless bug-report 

Environment variables

SHELL=/bin/zsh
EDITOR=<not set>

Git version

> git version 
git version 2.39.3 (Apple Git-146)

Hooks

Show 7 hooks ##### Hook `post-applypatch` ``` #!/bin/sh ## START BRANCHLESS CONFIG git branchless hook post-applypatch "$@" ## END BRANCHLESS CONFIG ``` ##### Hook `post-checkout` ``` #!/bin/sh command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-checkout' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } git lfs post-checkout "$@" ## START BRANCHLESS CONFIG git branchless hook post-checkout "$@" ## END BRANCHLESS CONFIG ``` ##### Hook `post-commit` ``` #!/bin/sh command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-commit' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } git lfs post-commit "$@" ## START BRANCHLESS CONFIG git branchless hook post-commit "$@" ## END BRANCHLESS CONFIG ``` ##### Hook `post-merge` ``` #!/bin/sh command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting the 'post-merge' file in the hooks directory (set by 'core.hookspath'; usually '.git/hooks').\n"; exit 2; } git lfs post-merge "$@" ## START BRANCHLESS CONFIG git branchless hook post-merge "$@" ## END BRANCHLESS CONFIG ``` ##### Hook `post-rewrite` ``` #!/bin/sh ## START BRANCHLESS CONFIG git branchless hook post-rewrite "$@" ## END BRANCHLESS CONFIG ``` ##### Hook `pre-auto-gc` ``` #!/bin/sh ## START BRANCHLESS CONFIG git branchless hook pre-auto-gc "$@" ## END BRANCHLESS CONFIG ``` ##### Hook `reference-transaction` ``` #!/bin/sh ## START BRANCHLESS CONFIG # Avoid canceling the reference transaction in the case that `branchless` fails # for whatever reason. git branchless hook reference-transaction "$@" || ( echo 'branchless: Failed to process reference transaction!' echo 'branchless: Some events (e.g. branch updates) may have been lost.' echo 'branchless: This is a bug. Please report it.' ) ## END BRANCHLESS CONFIG ```

Events

Show 5 events ##### Event ID: 3826, transaction ID: 3499 (message: amend) 1. `WorkingCopySnapshot { timestamp: 1710189822.835143, event_tx_id: EventTransactionId(3499), head_oid: af5c2fd61a0f0514da635b632daee65292cb0d96, commit_oid: NonZeroOid(60431129a47ff8408ab9991c87797199bcdd79bf), ref_name: Some(ReferenceName("refs/heads/main")) }` 1. `RewriteEvent { timestamp: 1710189822.835143, event_tx_id: EventTransactionId(3499), old_commit_oid: af5c2fd61a0f0514da635b632daee65292cb0d96, new_commit_oid: 91c12164ef67d64102ecadf5ba6598e2f5001ade }` 1. `RefUpdateEvent { timestamp: 1710189822.919142, event_tx_id: EventTransactionId(3499), ref_name: ReferenceName("refs/heads/main"), old_oid: af5c2fd61a0f0514da635b632daee65292cb0d96, new_oid: 91c12164ef67d64102ecadf5ba6598e2f5001ade, message: None }` 1. `WorkingCopySnapshot { timestamp: 1710189822.944098, event_tx_id: EventTransactionId(3499), head_oid: 91c12164ef67d64102ecadf5ba6598e2f5001ade, commit_oid: NonZeroOid(99bcca5a392a9b1ac0db4472d382324c9429f805), ref_name: Some(ReferenceName("refs/heads/main")) }` 1. `RefUpdateEvent { timestamp: 1710189823.022823, event_tx_id: EventTransactionId(3499), ref_name: ReferenceName("HEAD"), old_oid: 91c12164ef67d64102ecadf5ba6598e2f5001ade, new_oid: 91c12164ef67d64102ecadf5ba6598e2f5001ade, message: None }` 1. `RefUpdateEvent { timestamp: 1710189823.022823, event_tx_id: EventTransactionId(3499), ref_name: ReferenceName("refs/heads/main"), old_oid: 91c12164ef67d64102ecadf5ba6598e2f5001ade, new_oid: 91c12164ef67d64102ecadf5ba6598e2f5001ade, message: None }` ``` : @ 91c1216 26s (> main) xxx xxxxxxx ``` ##### Event ID: 3822, transaction ID: 3498 (message: commit) 1. `RefUpdateEvent { timestamp: 1710189218.659835, event_tx_id: EventTransactionId(3498), ref_name: ReferenceName("HEAD"), old_oid: ff58c33216744586f43ad266a89c13bb3f2b0bd1, new_oid: af5c2fd61a0f0514da635b632daee65292cb0d96, message: None }` 1. `RefUpdateEvent { timestamp: 1710189218.659835, event_tx_id: EventTransactionId(3498), ref_name: ReferenceName("refs/heads/main"), old_oid: ff58c33216744586f43ad266a89c13bb3f2b0bd1, new_oid: af5c2fd61a0f0514da635b632daee65292cb0d96, message: None }` 1. `CommitEvent { timestamp: 1710189216.0, event_tx_id: EventTransactionId(3498), commit_oid: NonZeroOid(af5c2fd61a0f0514da635b632daee65292cb0d96) }` 1. `RewriteEvent { timestamp: 1710189218.80025, event_tx_id: EventTransactionId(3498), old_commit_oid: ff58c33216744586f43ad266a89c13bb3f2b0bd1, new_commit_oid: af5c2fd61a0f0514da635b632daee65292cb0d96 }` ``` : @ 91c1216 26s (> main) xxx xxxxxxx ``` ##### Event ID: 3818, transaction ID: 3495 (message: commit) 1. `RefUpdateEvent { timestamp: 1710188955.626579, event_tx_id: EventTransactionId(3495), ref_name: ReferenceName("HEAD"), old_oid: 8930af0f0f1147f27dc8ea047e1cc4fa57effb49, new_oid: ff58c33216744586f43ad266a89c13bb3f2b0bd1, message: None }` 1. `RefUpdateEvent { timestamp: 1710188955.626579, event_tx_id: EventTransactionId(3495), ref_name: ReferenceName("refs/heads/main"), old_oid: 8930af0f0f1147f27dc8ea047e1cc4fa57effb49, new_oid: ff58c33216744586f43ad266a89c13bb3f2b0bd1, message: None }` 1. `CommitEvent { timestamp: 1710188946.0, event_tx_id: EventTransactionId(3495), commit_oid: NonZeroOid(ff58c33216744586f43ad266a89c13bb3f2b0bd1) }` 1. `RewriteEvent { timestamp: 1710188955.763559, event_tx_id: EventTransactionId(3495), old_commit_oid: 8930af0f0f1147f27dc8ea047e1cc4fa57effb49, new_commit_oid: ff58c33216744586f43ad266a89c13bb3f2b0bd1 }` ``` : @ 91c1216 26s (> main) xxx xxxxxxx ``` ##### Event ID: 3814, transaction ID: 3492 (message: commit) 1. `RefUpdateEvent { timestamp: 1710188925.2088, event_tx_id: EventTransactionId(3492), ref_name: ReferenceName("HEAD"), old_oid: f0a0246e535f797e991551a692c2155531c6bb94, new_oid: 8930af0f0f1147f27dc8ea047e1cc4fa57effb49, message: None }` 1. `RefUpdateEvent { timestamp: 1710188925.2088, event_tx_id: EventTransactionId(3492), ref_name: ReferenceName("refs/heads/main"), old_oid: f0a0246e535f797e991551a692c2155531c6bb94, new_oid: 8930af0f0f1147f27dc8ea047e1cc4fa57effb49, message: None }` 1. `CommitEvent { timestamp: 1710188908.0, event_tx_id: EventTransactionId(3492), commit_oid: NonZeroOid(8930af0f0f1147f27dc8ea047e1cc4fa57effb49) }` 1. `RewriteEvent { timestamp: 1710188925.364901, event_tx_id: EventTransactionId(3492), old_commit_oid: f0a0246e535f797e991551a692c2155531c6bb94, new_commit_oid: 8930af0f0f1147f27dc8ea047e1cc4fa57effb49 }` ``` : @ 91c1216 26s (> main) xxx xxxxxxx ``` ##### Event ID: 3813, transaction ID: 3491 (message: push) 1. `RefUpdateEvent { timestamp: 1710188527.902115, event_tx_id: EventTransactionId(3491), ref_name: ReferenceName("refs/remotes/redacted-ref-0"), old_oid: 0000000000000000000000000000000000000000, new_oid: f0a0246e535f797e991551a692c2155531c6bb94, message: None }` ``` : @ 91c1216 26s (> main) xxx xxxxxxx ```

Version of git-branchless

No response

Version of git

No response

bsima commented 3 months ago

I was just about to file this bug. I use pre-commit hooks to run a linter so using git amend often means I'm liable to commit un-linted code. A minor annoyance, but an annoyance nonetheless.