Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

having trouble restacking when updating a commit at the bottom of a stack #1391

Closed
Kimeiga opened this issue Sep 4, 2024 · 14 comments
Closed
Labels
bug Something isn't working

Comments

@Kimeiga
Copy link

Kimeiga commented Sep 4, 2024

Description of the bug

https://pastebin.com/Wb3A0P0U

so it looks like removing update-refs fixed git sync, but still when i commit to a commit in the bottom of a stack, it doesn't seem to let me restack

my commit and push command is g a aliased to
a = "!f() { git add --all && git commit --amend --no-edit && git restack && git submit; }; f"

is there something wrong with this

Expected behavior

the commit to not be duplicated

Actual behavior

the commit gets duplicated and the stack becomes outdated

Version of rustc

rustc 1.78.0 (9b00956e5 2024-04-29)

Automated bug report

Software version

git-branchless 0.9.0

Operating system

macOS 14.6.1 (Darwin 23.6.0)

Command-line

/Users/hakan.alpay/.cargo/bin/git-branchless bug-report 

Environment variables

SHELL=/bin/zsh
EDITOR=nvim

Git version

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

Hooks

Show 7 hooks
Hook post-applypatch
<not found>
<missing newline>
Hook post-checkout
<not found>
<missing newline>
Hook post-commit
<not found>
<missing newline>
Hook post-merge
<not found>
<missing newline>
Hook post-rewrite
<not found>
<missing newline>
Hook pre-auto-gc
<not found>
<missing newline>
Hook reference-transaction
<not found>
<missing newline>

Events

Show 5 events
Event ID: 22790, transaction ID: 11377 (message: prev)
  1. WorkingCopySnapshot { timestamp: 1725472937.510231, event_tx_id: Id(11377), head_oid: 7c8016d6115b7097ce9349e3f966b28aea408eff, commit_oid: NonZeroOid(5f246a113ba8cc676594bc2089c889160bf625ca), ref_name: Some(ReferenceName("refs/heads/redacted-ref-0")) }
:
O e7790b9 1h (master) xxxx xxxxxxxx xxxxx xxx
|\
| o 3d104fa 22m (redacted-ref-1) xxxxxxxxx xxxxx xxxxxxx xxxx xxxx xxx xxx
|\
| o 50149ff 22m (redacted-ref-2) xxxx
|\
| o ca45546 22m (redacted-ref-3) xxxxxxxxxxxxxxxxxxx xxxxxxx xxxx xxxx xxx xxx
|\
| o cc1b06f 22m (redacted-ref-4) xxxxxxxxx xxxxxxxxxx xxxx xxxxxxxx xxxxx xxxxxxxx xxx xxx
|\
| o e0c93d7 22m xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx
| |
| o 7c8016d 22m (redacted-ref-0) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|\
| o ee70afa 22m (redacted-ref-5) xxxxxxxx xxx xxxxx xxx xxxxxxxxxx xx xxxxx xxxx
| |
| o 39372a5 22m (redacted-ref-6) xxxxxxxx xxx xxxxx xxxxxxxxxx xxxx xx xxxxxx xxxxx
|
@ c3b90a7 13m (redacted-ref-7) xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx
Event ID: 22784, transaction ID: 11376 (message: sync)
  1. WorkingCopySnapshot { timestamp: 1725472932.818385, event_tx_id: Id(11376), head_oid: 3e882e79b0d79678fa34eb42a22891163e86e944, commit_oid: NonZeroOid(55d460a2fa3699e081e5a0411383bc57e1beccb7), ref_name: None }
  2. WorkingCopySnapshot { timestamp: 1725472933.087694, event_tx_id: Id(11376), head_oid: 3e882e79b0d79678fa34eb42a22891163e86e944, commit_oid: NonZeroOid(55d460a2fa3699e081e5a0411383bc57e1beccb7), ref_name: None }
  3. WorkingCopySnapshot { timestamp: 1725472933.314692, event_tx_id: Id(11376), head_oid: 3e882e79b0d79678fa34eb42a22891163e86e944, commit_oid: NonZeroOid(55d460a2fa3699e081e5a0411383bc57e1beccb7), ref_name: None }
  4. WorkingCopySnapshot { timestamp: 1725472933.543282, event_tx_id: Id(11376), head_oid: 3e882e79b0d79678fa34eb42a22891163e86e944, commit_oid: NonZeroOid(55d460a2fa3699e081e5a0411383bc57e1beccb7), ref_name: None }
  5. WorkingCopySnapshot { timestamp: 1725472933.779001, event_tx_id: Id(11376), head_oid: 3e882e79b0d79678fa34eb42a22891163e86e944, commit_oid: NonZeroOid(55d460a2fa3699e081e5a0411383bc57e1beccb7), ref_name: None }
  6. WorkingCopySnapshot { timestamp: 1725472934.013454, event_tx_id: Id(11376), head_oid: 3e882e79b0d79678fa34eb42a22891163e86e944, commit_oid: NonZeroOid(55d460a2fa3699e081e5a0411383bc57e1beccb7), ref_name: None }
:
O e7790b9 1h (master) xxxx xxxxxxxx xxxxx xxx
|\
| o 3d104fa 22m (redacted-ref-1) xxxxxxxxx xxxxx xxxxxxx xxxx xxxx xxx xxx
|\
| o 50149ff 22m (redacted-ref-2) xxxx
|\
| o ca45546 22m (redacted-ref-3) xxxxxxxxxxxxxxxxxxx xxxxxxx xxxx xxxx xxx xxx
|\
| o cc1b06f 22m (redacted-ref-4) xxxxxxxxx xxxxxxxxxx xxxx xxxxxxxx xxxxx xxxxxxxx xxx xxx
|\
| o e0c93d7 22m xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx
| |
| o 7c8016d 22m (redacted-ref-0) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|\
| o ee70afa 22m (redacted-ref-5) xxxxxxxx xxx xxxxx xxx xxxxxxxxxx xx xxxxx xxxx
| |
| o 39372a5 22m (redacted-ref-6) xxxxxxxx xxx xxxxx xxxxxxxxxx xxxx xx xxxxxx xxxxx
|
@ c3b90a7 13m (redacted-ref-7) xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx
Event ID: 22783, transaction ID: 11370 (message: prev)
  1. WorkingCopySnapshot { timestamp: 1725472900.30404, event_tx_id: Id(11370), head_oid: d81fe052e6129b28e7d66e482b39ad2e545fc2ad, commit_oid: NonZeroOid(a792cd0e665f3b823477f8553bc1e134a8541857), ref_name: Some(ReferenceName("refs/heads/redacted-ref-0")) }
:
O e7790b9 1h (master) xxxx xxxxxxxx xxxxx xxx
|\
| o 3d104fa 22m (redacted-ref-1) xxxxxxxxx xxxxx xxxxxxx xxxx xxxx xxx xxx
|\
| o 50149ff 22m (redacted-ref-2) xxxx
|\
| o ca45546 22m (redacted-ref-3) xxxxxxxxxxxxxxxxxxx xxxxxxx xxxx xxxx xxx xxx
|\
| o cc1b06f 22m (redacted-ref-4) xxxxxxxxx xxxxxxxxxx xxxx xxxxxxxx xxxxx xxxxxxxx xxx xxx
|\
| o e0c93d7 22m xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx
| |
| o 7c8016d 22m (redacted-ref-0) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|\
| o ee70afa 22m (redacted-ref-5) xxxxxxxx xxx xxxxx xxx xxxxxxxxxx xx xxxxx xxxx
| |
| o 39372a5 22m (redacted-ref-6) xxxxxxxx xxx xxxxx xxxxxxxxxx xxxx xx xxxxxx xxxxx
|
@ c3b90a7 13m (redacted-ref-7) xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx
Event ID: 22782, transaction ID: 11365 (message: next)
  1. WorkingCopySnapshot { timestamp: 1725465141.043426, event_tx_id: Id(11365), head_oid: a8d9d07e940abe48745cbcad6a8631430e1e85a7, commit_oid: NonZeroOid(7ae90a2819cb02fab3c107e4e7eaafef636533ae), ref_name: Some(ReferenceName("refs/heads/redacted-ref-7")) }
:
O e7790b9 1h (master) xxxx xxxxxxxx xxxxx xxx
|\
| o 3d104fa 22m (redacted-ref-1) xxxxxxxxx xxxxx xxxxxxx xxxx xxxx xxx xxx
|\
| o 50149ff 22m (redacted-ref-2) xxxx
|\
| o ca45546 22m (redacted-ref-3) xxxxxxxxxxxxxxxxxxx xxxxxxx xxxx xxxx xxx xxx
|\
| o cc1b06f 22m (redacted-ref-4) xxxxxxxxx xxxxxxxxxx xxxx xxxxxxxx xxxxx xxxxxxxx xxx xxx
|\
| o e0c93d7 22m xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx
| |
| o 7c8016d 22m (redacted-ref-0) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|\
| o ee70afa 22m (redacted-ref-5) xxxxxxxx xxx xxxxx xxx xxxxxxxxxx xx xxxxx xxxx
| |
| o 39372a5 22m (redacted-ref-6) xxxxxxxx xxx xxxxx xxxxxxxxxx xxxx xx xxxxxx xxxxx
|
@ c3b90a7 13m (redacted-ref-7) xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx
Event ID: 22781, transaction ID: 11364 (message: move)
  1. WorkingCopySnapshot { timestamp: 1725465135.834757, event_tx_id: Id(11364), head_oid: a8d9d07e940abe48745cbcad6a8631430e1e85a7, commit_oid: NonZeroOid(e4055e7b36b6e36f291059b6888cbe65a01f22b9), ref_name: None }
:
O e7790b9 1h (master) xxxx xxxxxxxx xxxxx xxx
|\
| o 3d104fa 22m (redacted-ref-1) xxxxxxxxx xxxxx xxxxxxx xxxx xxxx xxx xxx
|\
| o 50149ff 22m (redacted-ref-2) xxxx
|\
| o ca45546 22m (redacted-ref-3) xxxxxxxxxxxxxxxxxxx xxxxxxx xxxx xxxx xxx xxx
|\
| o cc1b06f 22m (redacted-ref-4) xxxxxxxxx xxxxxxxxxx xxxx xxxxxxxx xxxxx xxxxxxxx xxx xxx
|\
| o e0c93d7 22m xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx
| |
| o 7c8016d 22m (redacted-ref-0) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|\
| o ee70afa 22m (redacted-ref-5) xxxxxxxx xxx xxxxx xxx xxxxxxxxxx xx xxxxx xxxx
| |
| o 39372a5 22m (redacted-ref-6) xxxxxxxx xxx xxxxx xxxxxxxxxx xxxx xx xxxxxx xxxxx
|
@ c3b90a7 13m (redacted-ref-7) xxxxxxxx xxxxx xxxxxx xxxxx xxx xxxxxxxxxx xxxxx xxxxxxx xxxxxxxxx

Version of git-branchless

No response

Version of git

No response

@Kimeiga Kimeiga added the bug Something isn't working label Sep 4, 2024
@Kimeiga
Copy link
Author

Kimeiga commented Sep 4, 2024

image
it happens right when i commit

@claytonrcarter
Copy link
Collaborator

  1. check that the git branchless hooks are all intact and correct, esp if you had conflicts w/ other hooks; it could be that one of them is no longer installed and is not catching the changes
  2. git add --all && git commit --amend --no-edit && git restack something in here may be getting in the way; perhaps try git amend instead, which should replace all 3 of these commands

@Kimeiga
Copy link
Author

Kimeiga commented Sep 4, 2024

  1. how can I do that, is it sufficient to rerun git branchless init

do you think a precommit script could be causing this? The only thing that makes me doubt that is that this was working before and I still had the same precommit script.

  1. TIL!

although when I did the commands one by one I noticed it duplicated the commit right when i ran git commit --amend --no-edit

@claytonrcarter
Copy link
Collaborator

claytonrcarter commented Sep 4, 2024 via email

@Kimeiga
Copy link
Author

Kimeiga commented Sep 6, 2024

btw if i use git amend here do i want the --reparent flag? i want to cleanly update a commit in the middle of the stack, it looks like this option is necessary to do that? If that's the case btw why is it not the default behavior?

git add --all && git commit --amend --no-edit && git restack something in here may be getting in the way; perhaps try git amend instead, which should replace all 3 of these commands

how can git amend replace git add --all? it looks like you need to git add first

also when i try the reparent flag it doesn't do anything:

~/Projects/web-next/services/consumer-web-next NVG-984_finishing_placement_model*
» git amend --reparent
unknown flag `reparent'
panic: unknown flag `reparent'

goroutine 1 [running]:
main.check(...)
        /Users/runner/work/spr/spr/cmd/amend/main.go:75
main.main()
        /Users/runner/work/spr/spr/cmd/amend/main.go:39 +0x3a8

actually i'm really confused about git amend how come it's not amending the commit that i have checked out as HEAD here?

~/Projects/web-next/services/consumer-web-next NVG-984_finishing_placement_model* 8s
» g s
On branch NVG-984_finishing_placement_model
Your branch is up to date with 'origin/NVG-984_finishing_placement_model'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   src/CxComponentCatalog/AdsAndPromos/USI/PlacementModel/PlacementModel.tsx


~/Projects/web-next/services/consumer-web-next NVG-984_finishing_placement_model*
» g amend       
> git rev-parse --show-toplevel
> git log --format=medium --no-color origin/NVG-984_finishing_placement_model..HEAD
No commits to amend

~/Projects/web-next/services/consumer-web-next NVG-984_finishing_placement_model*
» g l    
* a81501915d0  2 weeks ago Hakan Alpay (HEAD -> NVG-984_finishing_placement_model, origin/NVG-984_finishing_placement_model) NVG-984_finishing_placement_model
* 0415a0dfdd7   2 days ago Hakan Alpay (origin/NVG-1022_USI_create_terms_and_conditions_modal_catalog_component, NVG-1022_USI_create_terms_and_conditions_modal_catalog_component) NVG-1022 [USI] Create Terms and Conditions Modal Catalog Component
* 8c319f63a43 13 hours ago Danny Fann (tag: dev-console-email-service_3.361.0, origin/release/dev-console-email-service_3.361.x, origin/publish/8c319f63a4367fcc2a4de3ea6817c7e18df989ff, origin/master, origin/invoice2go_v1_main, origin/i18n_-AsyncTrans-1725629407738, origin/HEAD, master) Temporarily disable email send while looking into PR reviews (#22918)
* d8712f8dd39 16 hours ago James Maher (tag: consumer-web-next_2.3638.0, tag: consumer-web-next-e2e_2.1046.0, origin/release/consumer-web-next_2.3638.x, origin/release/consumer-web-next-e2e_2.1046.x, origin/publish/d8712f8dd39de781fccf05fdc0b65e0193107311) patch: temporarily pause CWN merge queue (#22920)
* eeaace48dea 17 hours ago web-next-automation (origin/publish/82c3ee24079341b74dd1a0628ae1104085f44539) Bump versions [skip ci]
* 8a464844641 17 hours ago web-next-automation Update changelogs [skip ci]
* 82c3ee24079 17 hours ago Jon Collette App developer admin parity update (#22852)
* adbc74af42a 17 hours ago web-next-automation (origin/publish/faeeb48c41fdbd70e3b9a9e0fbb9135aa1a84653) Bump versions [skip ci]
* 38ab8ae5656 17 hours ago web-next-automation Update changelogs [skip ci]
* faeeb48c41f 17 hours ago chrisguan Add strings to i18n (#22726)

@claytonrcarter
Copy link
Collaborator

do i want the --reparent flag? i want to cleanly update a commit in the middle of the stack

Probably not, but it depends on context. Take a look at https://github.com/arxanas/git-branchless/wiki/Command:-git-amend#forcibly-amending-without-changing-children for more info about --reparent, but the gist is that it instructs the command to, in effect, "update the current commit with the changes, and then rebase the child commits onto the updated commit, but with their exact, unchanged contents". Formatting is a great example of where that's useful, but I have also used in a case where I made a change in the wrong place/commit and wanted to also update the parent commit w/ the change: I updated the parent, but doing a regular rebase would almost certainly have caused a conflict, and because I knew the intended change already existed in the children, I used --reparent to update the parent and then rebase the children with their existing contents, w/o trying to propogate the changes from the newly updated parent.

So, I guess:

  • if you want your updates to propagate to child commits, then don't use --reparent (and be prepared for possible merge conflicts)
  • if you don't want to changes to propagate to child commits, then use --reparent, and their existing contents will be rebased as-is

how can git amend replace git add --all? it

For me, this is the killer feature of amend (and record):

  • if there are staged changed (ie in the index as a result of git add), then they will commit/absord only those changes, leaving any unstaged changes in place
    • this is equivalent to running git commit --amend
  • if there are no staged changes, they will add all unstaged changes and commit/absorb those
    • this is equivalent to running git add --updated ; git commit --amend (or just git commit --all --amend)

Basically, it's git commit --amend but with some "do what I mean" added in and some rough edges polished off.

also when i try the reparent flag it doesn't do anything:

The error message isn't coming from git or git-branchless, but from spr. I'm not familiar with spr, but may I assume that it also has an amend command? My hunch is that your alias for amend is pointing at spr, not at git-branchless. What happens if you explicitly call git branchless amend --reparent instead?

actually i'm really confused about git amend how come it's not amending the commit that i have checked out as HEAD here?

I suspect that this is the above issue, with spr. What happens if you try git branchless amend instead?

@arxanas
Copy link
Owner

arxanas commented Oct 7, 2024

I'm guessing it's the same issue of not having hooks installed as in #1390. Reopen if not.

@arxanas arxanas closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2024
@Kimeiga
Copy link
Author

Kimeiga commented Oct 23, 2024

Yeah the issue was that hooks weren't installed but it's weird because I have run git branchless init before

git branchless bug-report yields:

##### Hook `post-applypatch`
<not found>

##### Hook `post-checkout`
<not found>

##### Hook `post-commit`
<not found>

##### Hook `post-merge`
<not found>

##### Hook `post-rewrite`
<not found>

##### Hook `pre-auto-gc`
<not found>

##### Hook `reference-transaction`
<not found>

here's me running it again

» git branchless init      
Created config file at /Users/hakan.alpay/Projects/web-next/.git/branchless/config
Auto-detected your main branch as: master
If this is incorrect, run: git branchless init --main-branch <branch>
Installing hooks: post-applypatch, post-checkout, post-commit, post-merge, post-rewrite, pre-auto-gc, reference-transaction
Alias amend already installed, skipping
Successfully installed git-branchless.
To uninstall, run: git branchless init --uninstall

running this helped for sure cuz now i have:

Hook `post-applypatch`
#!/bin/sh
## START BRANCHLESS CONFIG
git branchless hook post-applypatch "$@"
## END BRANCHLESS CONFIG

and now git sync -p --merge works perfectly

https://pastebin.com/RrTnY08K

but i guess the main question is what did i do that caused git branchless init to be undone cuz i dont think ive run git branchless uninstall or anything.
Also this isn't the first time that this has happened ...

so i’ll try to pay attention to when it breaks again and backtrack when that happens

@arxanas
Copy link
Owner

arxanas commented Oct 23, 2024

  • Are you using worktrees, and perhaps the hooks aren't installed in the worktree somehow? (git-branchless should handle this case but maybe it doesn't work)
  • Are you using pre-commit, Git LFS or any other system that installs its own hooks? I've seen them clobber hooks on occasion (but usually not by deleting all the hooks...)

@Kimeiga
Copy link
Author

Kimeiga commented Oct 28, 2024

no worktrees

i might have figured out whats happening. doordash web-next uses rush for package management, and i think after rush install and/or other rush operations it rewrites the pre-commit and pre-push git hooks with ones that my company wrote for this repo for running prettier precommit and stuff

not entirely sure what to do considering i can’t modify the pre-commit or pre-push bash scripts since they are not gitignored or anything and i need to run rush install and rush update and stuff

i tried adding git branchless init in the beginning of my macros that use git branchless

my super super super messy .gitconfig:

[alias]
  a = "!f() { git branchless init && git add -A && git branchless amend && git submit; }; f"
  al = "!f() { git branchless init && git add -A && git branchless amend; }; f"
  aa = "!f() { git branchless init && branch=$1; git switch -c \"$branch\" && git add --all && commit_message=$(echo \"$branch\" | sed 's/_/ /g') && git commit -m \"$commit_message\" && git push -u origin \"$branch\" && gh pr create --fill && gh pr view --web; }; f"
  amend = commit --amend
  b = "!f() { git add --all && git commit -m "$1" && git push; }; f"
  bb = branch -a
  bc = "!f() { git branch --merged | grep -Ev '(^\\*|master|main)' | xargs -r git branch -d; }; f"
  bd = branch -d
  bdf = "!f() { git branch | grep -v \"^*\" | fzf --height=20% --reverse --info=inline | xargs -r git branch -d; }; f"
  bf = "!f() { git branch --format='%(refname:short)|%(objectname:short)|%(contents:subject)' --sort=-committerdate | column -t -s '|' | grep -v \"^*\" | fzf --height=20% --reverse --info=inline | awk '{print $1}' | xargs -r git checkout; }; f"
  cherry-pit = "!f() { git rebase --rebase-merges --onto \"$1\"^ \"$1\"; }; f"
  cm = commit -m
  co = checkout
  ec = config --global -e
  go = "!f() { git checkout -b \"$1\" 2> /dev/null || git checkout \"$1\"; }; f"
  l = log --relative-date --graph --abbrev-commit -10
  la = l --all
  ll = log --relative-date --graph --abbrev-commit
  lla = ll --all
  remotes = remote -v
  s = status
  sd = d --cached
  sh = show --pretty=fuller
  c = "!f() { git diff --name-only $(git merge-base HEAD origin/$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')) | while read file; do echo \"$(git rev-parse --show-toplevel)/$file\"; done; }; f"
  y = "!f() { git branchless init && git branchless sync -p --merge; }; f"
  yy = "!f() { git branchless init && git branchless sync -p; }; f"
  r = "!f() { git add -A && GIT_EDITOR=true git rebase --continue && git submit; }; f"
  p = submit
  pp = push
  st = stash -u
  sta = stash apply -u
  j = sl
  re = checkout -- .
  d = diff

claude suggested a script to monitor and fix hooks that would have to be run periodically somehow

cat > check-hooks.sh << 'EOF'
#!/bin/bash
echo "Checking hooks after Rush command at $(date)"

# Check if git-branchless hooks are present
missing_hooks=false
for hook in post-applypatch post-checkout post-commit post-merge post-rewrite pre-auto-gc reference-transaction; do
    if ! grep -q "branchless" .git/hooks/$hook 2>/dev/null; then
        missing_hooks=true
        break
    fi
done

if [ "$missing_hooks" = true ]; then
    echo "WARNING: git-branchless hooks are missing. Restoring..."
    git branchless init
    echo "Hooks restored at $(date)"
fi
EOF
chmod +x check-hooks.sh

claude also suggested this:

# Create a backup of the current hooks
cp -r .git/hooks .git/hooks-backup-$(date +%Y%m%d)

# Create a combined pre-commit hook in common/git-hooks/pre-commit
cat > common/git-hooks/pre-commit << 'EOF'
#!/bin/sh
# Rush pre-commit checks
# insert doordash's git pre commit hooks

# git-branchless hooks
if command -v git-branchless &> /dev/null; then
    git branchless hook pre-commit "$@"
fi
EOF
chmod +x common/git-hooks/pre-commit

but i would have to find a way to never check this in to version control somehow considering the common/git-hooks/* is all not gitignored

@Kimeiga
Copy link
Author

Kimeiga commented Oct 28, 2024

it also suggested wrapping the rush command with something:

Create a post-rush-install hook:

# Create a script in your personal non-versioned directory
mkdir -p ~/.rush-hooks
cat > ~/.rush-hooks/post-rush.sh << 'EOF'
#!/bin/bash

# Check if we're in web-next repo
if git rev-parse --git-dir > /dev/null 2>&1; then
    if [[ $(git config --get remote.origin.url) == *"web-next"* ]]; then
        echo "Restoring git-branchless hooks..."
        git branchless init
    fi
fi
EOF
chmod +x ~/.rush-hooks/post-rush.sh

Create an alias for rush commands:

# Add to your .zshrc or .bashrc
alias rush='command rush "$@" && ~/.rush-hooks/post-rush.sh'

Or create a wrapper script:

cat > ~/bin/rush-wrapper << 'EOF'
#!/bin/bash
command rush "$@"
RUSH_EXIT_CODE=$?

~/.rush-hooks/post-rush.sh

exit $RUSH_EXIT_CODE
EOF
chmod +x ~/bin/rush-wrapper

# Add to your .zshrc or .bashrc
alias rush=~/bin/rush-wrapper

curious what do you think the best solution would be here

@Kimeiga
Copy link
Author

Kimeiga commented Oct 28, 2024

ok yeah rush install deletes all of the git branchless hooks
https://pastebin.com/5TnC99p6

@arxanas
Copy link
Owner

arxanas commented Oct 29, 2024

Perhaps this should be treated as a bug in rush? It seems weird that it would throw away the entire hooks directory on rush install. In contrast to rush, git-branchless only creates/modifies a section inside the hook scripts that's attributed to git-branchless itself so that it doesn't clobber other hooks. That being said, I don't think there's a "standard" way to have multiple hooks besides implementing your own hooks to call all the other hooks.

@Kimeiga
Copy link
Author

Kimeiga commented Oct 29, 2024

image
https://rushstack.zulipchat.com/#narrow/channel/262513-general/topic/rush.20install.20deletes.20my.20git.20hooks

they said they set git hooks hermetically

i decided to wrap rush for now

#!/bin/bash

# Function to restore hooks if in web-next repo
fix_hooks() {
    if git config --get remote.origin.url 2>/dev/null | grep -q "doordash/web-next"; then
        echo "Restoring git-branchless hooks..."
        git branchless init > /dev/null 2>&1
        echo "Hooks restored"
    fi
}

# Run the original rush command
command rush "$@"
RUSH_EXIT_CODE=$?

# Fix hooks
fix_hooks

exit $RUSH_EXIT_CODE

I put it in my ~/dotfiles/spells which is in my path, and my ~/dotfiles/zsh/.zshrc (which is stowed to ~/.zshrc has alias rush='rush-with-branchless-hooks'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants