From c0c3f87574fb5df47e5d2486025fd46b4ec8b041 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Sun, 12 Feb 2023 01:43:38 +0100 Subject: [PATCH] git fetch: prune old branch names before adding new ones --- CHANGELOG.md | 3 +++ lib/src/git.rs | 4 ++-- tests/test_git_fetch.rs | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a62c7e8b5..9639322eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -174,6 +174,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Fix the output of `jj debug completion --help` by reversing fish and zsh text. +* Fixed edge case in `jj git fetch` when a pruned branch is a prefix of another + branch. + ### Contributors Thanks to the people who made this release happen! diff --git a/lib/src/git.rs b/lib/src/git.rs index cca2fd653..13943d30f 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -364,10 +364,10 @@ pub fn fetch( let refspec: &[&str] = &[]; tracing::debug!("remote.download"); remote.download(refspec, Some(&mut fetch_options))?; - tracing::debug!("remote.update_tips"); - remote.update_tips(None, false, git2::AutotagOption::Unspecified, None)?; tracing::debug!("remote.prune"); remote.prune(None)?; + tracing::debug!("remote.update_tips"); + remote.update_tips(None, false, git2::AutotagOption::Unspecified, None)?; // TODO: We could make it optional to get the default branch since we only care // about it on clone. let mut default_branch = None; diff --git a/tests/test_git_fetch.rs b/tests/test_git_fetch.rs index 6ad12faf3..b11dbb5c5 100644 --- a/tests/test_git_fetch.rs +++ b/tests/test_git_fetch.rs @@ -144,8 +144,10 @@ fn test_git_fetch_prune_before_updating_tips() { .rename("origin/subname", false) .unwrap(); - // Exhibit bug: origin will prevent origin/subname from being created - let _ = test_env.jj_cmd_failure(&repo_path, &["git", "fetch"]); + test_env.jj_cmd_success(&repo_path, &["git", "fetch"]); + insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###" + origin/subname: 9f01a0e04879 message + "###); } /// Add a remote containing a branch with the same name