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

Remote stays conflicted after jj git fetch #779

Closed
samhza opened this issue Nov 22, 2022 · 3 comments
Closed

Remote stays conflicted after jj git fetch #779

samhza opened this issue Nov 22, 2022 · 3 comments

Comments

@samhza
Copy link

samhza commented Nov 22, 2022

Description

If a remote's URL is removed and re-added after a force-push ocurred remotely but before the force pushed was fetched on the local repo, a subsequent jj git fetch will result in an unresolvable conflict for the remote branch.

Steps to Reproduce the Problem

#!/bin/sh
set -o xtrace

# dummy "remote"
git init --bare /tmp/jjbug.git
jj git clone /tmp/jjbug.git /tmp/jjbug-jj
git clone /tmp/jjbug.git /tmp/jjbug-git

cd /tmp/jjbug-git
git commit -m 'some commit' --allow-empty
git push
# the remote is now at commit 'some commit'

cd /tmp/jjbug-jj
jj git fetch
# jj's clone is now at commit 'some commit'

cd /tmp/jjbug-git
git commit --amend --allow-empty -m 'now a different commit'
git push --force
# the remote now has been force pushed such that 'some commit' no longer exists
# and master is at 'now a different commit'

cd /tmp/jjbug-jj
jj git remote remove origin
jj git remote add origin /tmp/jjbug.git
jj git fetch
jj st

Expected Behavior

There is no conflict

Actual Behavior

There is a conflict

Specifications

  • Platform: NixOS x86_64
  • Version: 6d500ed
@martinvonz
Copy link
Member

Thanks for the report and for making it so easy to reproduce. I think the issue is that jj git remote remove origin doesn't clean up its record of existing git refs, so we think that there's still a refs/remotes/origin/main pointing to "some commit". So I think the fix is to make sure we delete the branch in the git repo (https://github.com/rust-lang/git2-rs/blob/c93d29bebf9097da50505ff9d84a5c98b1a2e813/src/repo.rs#L672-L675 doesn't seem to be correct), and we also need remove the ref from our record.

@elasticdog
Copy link
Contributor

For what it's worth, I think I'm hitting this regularly with a repository that's using the Bors-NG merge bot, where there are permanent trying and staging branches that are force-pushed to by the bot on a regular basis. I can try to pay a bit closer attention, but I think it has manifested conflicts whether I'm using a colocated repository or not.

@samhza
Copy link
Author

samhza commented Oct 2, 2024

I believe this has been fixed, it no longer reproduces.

@samhza samhza closed this as completed Oct 2, 2024
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

3 participants