-
Notifications
You must be signed in to change notification settings - Fork 337
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
In a git colocated repo, commits are not rebased off of a deleted/moved branch #864
Comments
I'm not sure commits should be rebased. Deleting a branch should only delete the corresponding head, but the commits still exist, in particular if other commits are based on them (this is similar to having a nameless branch containing them). |
Here's my thought process:
I'm not sure I'm right, but that's my reasoning anyway. |
The reasoning Martin gave makes sense, but I'm still unsure whether this is what the user wants in every situation. In any case, however, it's a bug that colocated repos have a different behavior from non-colocated ones. I will probably try to understand why that happens; let me know if somebody already has an idea. |
I haven't gotten to the bottom of this, but I have managed to reproduce this bug by adding a 79466c6#diff-74189cdc6ab62f4f1f94ca016ba2c1fcc783cbc93ba19e075b2b949c81c63dfbR369-R385 Presumably, the Somehow, this results in |
iirc, in colocated repo, a local ref exists and it prevents the local commits from abandoned. Perhaps, |
Yes, that seems about right. |
I wonder if #779 might be related. |
I made some partial progress, but I'm quite confused. Here's a brief status report: (I can elaborate if people are interested) I tried to reproduce this bug in a non-colocated repository. The following test seemed to be it: A test that tries to reproduce this bug in a non-colocated repo.Note especially the line marked #[test]
fn test_git_colocated_fetch_deleted_branch() {
let test_env = TestEnvironment::default();
let origin_path = test_env.env_root().join("origin");
git2::Repository::init(&origin_path).unwrap();
test_env.jj_cmd_success(&origin_path, &["init", "--git-repo=."]);
test_env.jj_cmd_success(&origin_path, &["describe", "-m=A"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", "A"]);
test_env.jj_cmd_success(&origin_path, &["new", "-m=B"]);
test_env.jj_cmd_success(&origin_path, &["branch", "create", "B"]);
test_env.jj_cmd_success(&origin_path, &["new", "-m=C"]);
let clone_path = test_env.env_root().join("clone");
std::fs::create_dir(&clone_path).unwrap();
// git2::Repository::clone(origin_path.to_str().unwrap(), &clone_path).unwrap();
test_env.jj_cmd_success(
&clone_path,
&[
"git",
"clone",
origin_path.to_str().unwrap(),
&clone_path.to_str().unwrap(),
],
);
insta::assert_snapshot!(get_log_output(&test_env, &clone_path), @r###"
@ bc7d08e8de9b7bc248b9358a05e96f1671bbd4d9
◉ e1f4268fabd2c84e880c5eb5bd87e076180fc8e3 B
◉ a86754f975f953fa25da4265764adc0c62e9ce6b A master
◉ 0000000000000000000000000000000000000000
"###);
test_env.jj_cmd_success(&origin_path, &["branch", "delete", "B"]);
// NOTE: Removing this export fixes the test
let stdout = test_env.jj_cmd_success(&clone_path, &["git", "export"]);
insta::assert_snapshot!(stdout, @"");
let stdout = test_env.jj_cmd_success(&clone_path, &["git", "import"]);
insta::assert_snapshot!(stdout, @r###"
Nothing changed.
"###);
let stdout = test_env.jj_cmd_success(&clone_path, &["git", "fetch"]);
insta::assert_snapshot!(stdout, @"");
// TODO: e1f4 should have been abandoned (#864)
insta::assert_snapshot!(get_log_output(&test_env, &clone_path), @r###"
@ bc7d08e8de9b7bc248b9358a05e96f1671bbd4d9
◉ e1f4268fabd2c84e880c5eb5bd87e076180fc8e3
◉ a86754f975f953fa25da4265764adc0c62e9ce6b A master
◉ 0000000000000000000000000000000000000000
"###);
} See ilyagr@fetchdel-partial-fix for a fix to the above test. I may clean it up and turn it into a PR soon. However, to my great surprise, that commit does NOT fix the bug in colocated repos. In other words, the |
In a colocated repo, we have |
Good point, this is a likely explanation. I'll check whether #1592 fixed my problem, and what's going on with HEAD in general. Thank you! |
Nope, it tries to not abandon more, so wouldn't change the behavior. Maybe you can remove |
Yeah, I changed my mind about it being pretty likely and edited the comment too late. Still, I expect making the test show HEAD@git will clear things up significantly. |
Indeed, the problem was the HEAD. Adding |
Before, HEAD@git was at change `e1f4` mentioned in the test. So, as long as we consider the behavior added in 20eb9ec to be correct, that change should NOT have been abandoned after the fetch, in spite of what the comment in the test says. In other words, the test did NOT demonstrate a bug before this commit. Now, the test properly demonstrates the bug. Cc #864
While #1600 solves this exact bug, I think, I'm not sure it solves every related problem completely. At the moment, I don't have a minimal where there's a clear bug. For a not-so-minimal example where it's unclear whether there's a bug, here is a repo state: At operation 46e17, the Here are outputs of |
Indeed, it seems that what I described above is the same bug, just with moving the ref as opposed to deleting it. |
#864) This bug concerns the way `import_refs` that gets called by `fetch` computes the heads that should be visible after the import. Previously, the list of such heads was computed *before* local branches were updated based on changes to the remote branches. So, commits that should have been abandoned based on this update of the local branches weren't properly abandoned. Now, `import_refs` tracks the heads that need to be visible because of some ref in a mapping keyed by the ref. If the ref moves or is deleted, the corresponding heads are updated. Fixes #864
Description
After
jj git fetch
, once a local branch is deleted because the commits / branch is deleted on the remote, commits on top of the deleted branch should be rebased off of it. However this doesn't happen injj
repos colocated with.git
Steps to Reproduce the Problem
rp
in the snippet below)jj log
, you should have a few commitsjj git fetch
jj log
, the branch should have been deletedExpected Behavior
Actual Behavior
@martinvonz checked and confirmed that this problem doesn't happen in non co-located jj repos with git backend
Specifications
The text was updated successfully, but these errors were encountered: