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' <