gitext-rs / git-stack

Stacked branch management for Git
Apache License 2.0
505 stars 19 forks source link

Don't prune remote refs #161

Closed Bouke closed 2 years ago

Bouke commented 2 years ago

Description

Currently git-stack --pull prunes refs from remotes:

$ git stack --pull
Pruning origin/dx/invoice-no-preview
From XXX
 * branch                master     -> FETCH_HEAD
master XXX
⌽ dx/invoice-no-preview (ready) XXX
To undo, run `git branch-stash pop git-stack`

This causes git-stack --push to fail:

$ git stack --push
To XXX
 ! [rejected]            dx/invoice-no-preview -> dx/invoice-no-preview (stale info)
error: failed to push some refs to 'XXX'

To fix this, restore the remote refs:

$ git fetch
From XXX
 * [new branch]          dx/invoice-no-preview                  -> origin/dx/invoice-no-preview

And --push again:

$ git stack --push
To XXX
 + 47eef9f7a...d312b7eca dx/invoice-no-preview -> dx/invoice-no-preview (forced update)
Branch 'dx/invoice-no-preview' set up to track remote branch 'dx/invoice-no-preview' from 'origin' by rebasing.

Version

0.5.0

Steps to reproduce

No response

Actual Behaviour

No response

Expected Behaviour

No response

Debug Output

No response

epage commented 2 years ago

There are two things that stand out here:

To detect whether a branch is on the server or not, we run:

$ git ls-remote --heads origin <branch names>

We then strip off the remote names and compare that with the local branches.

Could you run the ls-remote command and report back the result? Anything else unusual or different about this that you can think of for why we might be thinking the branch no longer exists on the server and yet i does?

arxanas commented 2 years ago

Yep, if you delete your local copy of the remote ref, then pushing with --force-with-lease will fail. This is a problem with my git undo too, since if you delete (or otherwise change the position of) a remote ref, then Git will complain that it's out of sync with the actual remote and abort.

epage commented 2 years ago

Found the bug! I made the odd assumption that branch names won't have a / through them and do an rsplit_once('/') to strip off refs/heads. Going to go fix it!

epage commented 2 years ago

Just released v0.5.3 with the fix!

Bouke commented 2 years ago

This is working great, thanks!