ok/jj
1
0
Fork 0
forked from mirrors/jj

git_fetch: when removing a remote branch, remove git ref as well

This commit is contained in:
Samuel Tardieu 2023-02-24 18:24:48 +01:00
parent 1056cfa41a
commit b515d14f18
3 changed files with 54 additions and 1 deletions

View file

@ -34,6 +34,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed a bug that could get partially resolved conflicts to be interpreted
incorrectly.
* `jj git fetch`: when re-adding a remote repository that had been previously
removed, in some situations the remote branches were not recreated.
## [0.7.0] - 2023-02-16
### Breaking changes

View file

@ -192,12 +192,22 @@ fn cmd_git_remote_remove(
branches_to_delete.push(branch.clone());
}
}
if !branches_to_delete.is_empty() {
let prefix = format!("refs/remotes/{}/", args.remote);
let git_refs_to_delete = repo
.view()
.git_refs()
.keys()
.filter_map(|r| r.starts_with(&prefix).then(|| r.clone()))
.collect_vec();
if !branches_to_delete.is_empty() || !git_refs_to_delete.is_empty() {
let mut tx =
workspace_command.start_transaction(&format!("remove git remote {}", &args.remote));
for branch in branches_to_delete {
tx.mut_repo().remove_remote_branch(&branch, &args.remote);
}
for git_ref in git_refs_to_delete {
tx.mut_repo().remove_git_ref(&git_ref);
}
tx.finish(ui)?;
}
Ok(())

View file

@ -665,3 +665,43 @@ fn test_git_fetch_undo() {
o 000000000000
"###);
}
#[test]
fn test_git_fetch_remove_fetch() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
add_git_remote(&test_env, &repo_path, "origin");
test_env.jj_cmd_success(&repo_path, &["branch", "set", "origin"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin: 230dd059e1b0 (no description set)
"###);
test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin (conflicted):
+ 230dd059e1b0 (no description set)
+ ffecd2d67827 message
@origin (behind by 1 commits): ffecd2d67827 message
"###);
test_env.jj_cmd_success(&repo_path, &["git", "remote", "remove", "origin"]);
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin (conflicted):
+ 230dd059e1b0 (no description set)
+ ffecd2d67827 message
"###);
test_env.jj_cmd_success(&repo_path, &["git", "remote", "add", "origin", "../origin"]);
// Check that origin@origin is properly recreated
let stdout = test_env.jj_cmd_success(&repo_path, &["git", "fetch"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
origin (conflicted):
+ 230dd059e1b0 (no description set)
+ ffecd2d67827 message
@origin (behind by 1 commits): ffecd2d67827 message
"###);
}