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

restack appears to enter infinite loop when it encounters a merge conflict #33

Closed
jacobsimpson-addepar opened this issue Jun 25, 2021 · 2 comments

Comments

@jacobsimpson-addepar
Copy link

jacobsimpson-addepar commented Jun 25, 2021

When I amend to an older commit in the stack that results in a merge conflict, I get repeated errors indicating a rebase is in progress:

branchless: git rebase b5ed1de43634dc9e64ab9a0e0d1555f6a2c41297 06e73bfc36ab4f7b83a6abbda1e24c55aa3435c5 --onto 69feacd33c46f8c4bdf053d7f778e2077bdfee56
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Rebasing (1/1)^Mbranchless: processing 1 update to a branch/ref
branchless: processing 1 update to a branch/ref
error: could not apply 06e73bf... Make line 2 extra verbose
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
branchless: processing 1 update to a branch/ref
Recorded preimage for 'README.md'
branchless: processing 1 update to a branch/ref
Could not apply 06e73bf... Make line 2 extra verbose
branchless: resolve rebase, then run 'git restack' again
branchless: git rebase b5ed1de43634dc9e64ab9a0e0d1555f6a2c41297 06e73bfc36ab4f7b83a6abbda1e24c55aa3435c5 --onto 69feacd33c46f8c4bdf053d7f778e2077bdfee56
fatal: It seems that there is already a rebase-merge directory, and
I wonder if you are in the middle of another rebase.  If that is the
case, please try
        git rebase (--continue | --abort | --skip)
If that is not the case, please
        rm -fr ".git/rebase-merge"
and run me again.  I am stopping in case you still have something
valuable there.

branchless: resolve rebase, then run 'git restack' again
branchless: git rebase b5ed1de43634dc9e64ab9a0e0d1555f6a2c41297 06e73bfc36ab4f7b83a6abbda1e24c55aa3435c5 --onto 69feacd33c46f8c4bdf053d7f778e2077bdfee56
fatal: It seems that there is already a rebase-merge directory, and
I wonder if you are in the middle of another rebase.  If that is the
case, please try
        git rebase (--continue | --abort | --skip)
If that is not the case, please
        rm -fr ".git/rebase-merge"
and run me again.  I am stopping in case you still have something
valuable there.

The last bit repeats endlessly.

Repro:

mkdir -p origin-repo
cd origin-repo
git init .
printf "one\ntwo\nthree\n" > README.md
git add .
git commit -am "Initial commit."
cd ..
git clone origin-repo/.git cloned-repo
cd cloned-repo
git branchless init
git checkout -b feature-1
cp README.md tmp && sed '2s/^/lin /' < tmp > README.md && rm tmp
git commit -am "Update line 2."
git checkout -b feature-2
cp README.md tmp && sed '2s/^/this is /' < tmp > README.md && rm tmp
git commit -am "Make line 2 extra verbose"
git prev
cp README.md tmp && sed '2s/^lin /line /' < tmp > README.md && rm tmp
git amend -a
git restack

If you run into this in the wild:

  1. Break the loop w/ Ctrl-C
  2. Resolve the conflict by editing the conflicted file (README.md in the repro).
  3. git add README.md
  4. git rebase --continue
  5. git restack
@arxanas
Copy link
Owner

arxanas commented Jun 25, 2021

Thanks for the detailed report and repro steps. I wasn't able to to reproduce this, with this slightly modified script (git amend doesn't exist in stock Git):

mkdir -p origin-repo
cd origin-repo
git init .
printf "one\ntwo\nthree\n" > README.md
git add .
git commit -am "Initial commit."
cd ..
git clone origin-repo/.git cloned-repo
cd cloned-repo
git branchless init
git checkout -b feature-1
cp README.md tmp && sed '2s/^/lin /' < tmp > README.md && rm tmp
git commit -am "Update line 2."
git checkout -b feature-2
cp README.md tmp && sed '2s/^/this is /' < tmp > README.md && rm tmp
git commit -am "Make line 2 extra verbose"
git prev
cp README.md tmp && sed '2s/^lin /line /' < tmp > README.md && rm tmp
git commit -a --amend
git restack

Most likely this was fixed in 15fe104, released in https://github.com/arxanas/git-branchless/releases/tag/v0.3.2. I would ask what version of git-branchless you're using, but it might be hard to say, given that git-branchless doesn't correctly report its version number (9d4f4f1)... Reopen if the issue persists after upgrading to v0.3.2 or later.

git restack is implemented in kind of a hacky way for now. In the long run, I'd like to use the git move machinery to form a rebase plan and execute it all in one go, rather than iterating until we reach a fixed point. This should make it much harder to hit an infinite loop bug because we won't be doing any looping.

@arxanas arxanas closed this as completed Jun 25, 2021
@arxanas arxanas mentioned this issue Jun 25, 2021
14 tasks
@jacobsimpson-addepar
Copy link
Author

Oops, I forgot that amend is an alias. You guessed it correctly in any case.

Issue is gone after upgrading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants