Skip to content

Commit

Permalink
git: make fetch() import local tags in addition to remote branches
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Sep 25, 2023
1 parent 88129a3 commit 0ca5cf4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,13 +914,14 @@ pub fn fetch(
tracing::debug!("remote.disconnect");
remote.disconnect()?;

// `import_some_refs` will import the remote-tracking branches into the jj repo
// and update jj's local branches.
// Import the remote-tracking branches into the jj repo and update jj's
// local branches. We also import local tags since remote tags should have
// been merged by Git.
tracing::debug!("import_refs");
import_some_refs(mut_repo, git_repo, git_settings, |ref_name| {
to_remote_branch(ref_name, remote_name)
.map(&branch_name_filter)
.unwrap_or(false)
.unwrap_or_else(|| matches!(ref_name, RefName::Tag(_)))
})?;
Ok(default_branch)
}
Expand Down
13 changes: 12 additions & 1 deletion lib/tests/test_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,10 @@ fn test_fetch_success() {
"refs/heads/main",
&[&initial_git_commit],
);
test_data
.origin_repo
.reference("refs/tags/v1.0", new_git_commit.id(), false, "")
.unwrap();

let mut tx = test_data
.repo
Expand All @@ -1708,6 +1712,7 @@ fn test_fetch_success() {
*view.git_refs(),
btreemap! {
"refs/remotes/origin/main".to_string() => new_commit_target.clone(),
"refs/tags/v1.0".to_string() => new_commit_target.clone(),
}
);
assert_eq!(
Expand All @@ -1716,11 +1721,17 @@ fn test_fetch_success() {
"main".to_string() => BranchTarget {
local_target: new_commit_target.clone(),
remote_targets: btreemap! {
"origin".to_string() => new_commit_target,
"origin".to_string() => new_commit_target.clone(),
},
},
}
);
assert_eq!(
*view.tags(),
btreemap! {
"v1.0".to_string() => new_commit_target.clone(),
}
);
}

#[test]
Expand Down

0 comments on commit 0ca5cf4

Please sign in to comment.