From b65195f02e3e09c5a74c8798d7d743db39156074 Mon Sep 17 00:00:00 2001 From: Thomas Koutcher Date: Sat, 7 Jul 2018 21:08:47 +0200 Subject: [PATCH] Use fully qualified ref name for tag when conflicting with branch name Closes #746 and #787 --- src/refdb.c | 9 +++++++-- test/refs/branch-tag-test | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100755 test/refs/branch-tag-test diff --git a/src/refdb.c b/src/refdb.c index 6d0c536de..25aa8ac04 100644 --- a/src/refdb.c +++ b/src/refdb.c @@ -195,8 +195,13 @@ add_to_refs(const char *id, size_t idlen, char *name, size_t namelen, struct ref type = REFERENCE_LOCAL_TAG; } - namelen -= STRING_SIZE("refs/tags/"); - name += STRING_SIZE("refs/tags/"); + /* Don't remove the prefix if there is already a branch + * with the same name. */ + ref = string_map_get(&refs_by_name, name + STRING_SIZE("refs/tags/")); + if (ref == NULL || ref_is_tag(ref)) { + namelen -= STRING_SIZE("refs/tags/"); + name += STRING_SIZE("refs/tags/"); + } } else if (!prefixcmp(name, "refs/remotes/")) { type = REFERENCE_REMOTE; diff --git a/test/refs/branch-tag-test b/test/refs/branch-tag-test new file mode 100755 index 000000000..cebc18207 --- /dev/null +++ b/test/refs/branch-tag-test @@ -0,0 +1,35 @@ +#!/bin/sh + +. libtest.sh +. libgit.sh + +export LINES=18 + +steps ' + :save-display refs-initial.screen +' + +in_work_dir create_repo_from_tgz "$base_dir/files/refs-repo.tgz" +in_work_dir git branch v2.0 v2.0.1 + +test_tig refs + +assert_equals 'refs-initial.screen' <