Skip to content

Commit

Permalink
Use fully qualified ref name for tag when conflicting with branch name
Browse files Browse the repository at this point in the history
Closes jonas#746 and jonas#787
  • Loading branch information
koutcher committed Jul 7, 2018
1 parent 3148151 commit b65195f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/refdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
35 changes: 35 additions & 0 deletions test/refs/branch-tag-test
Original file line number Diff line number Diff line change
@@ -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' <<EOF
All references
2010-04-07 05:37 +0000 Max Power master Commit 10 E
2009-02-13 23:31 +0000 Max Power mp/feature WIP: feature
2009-12-26 01:11 +0000 作者 r1.1.2 Commit 8 C
2009-12-26 01:11 +0000 作者 r1.1.x Commit 8 C
2009-12-17 12:49 +0000 René Lévesque r1.0 Commit 8 B
2010-03-12 16:31 +0000 René Lévesque v2.0 Commit 10 B
2010-04-07 05:37 +0000 Max Power origin/master Commit 10 E
2010-04-07 05:37 +0000 Max Power max-power/master Commit 10 E
2009-02-13 23:31 +0000 Max Power max-power/mp/feature WIP: feature
2009-11-30 12:05 +0000 Max Power max-power/mp/gh-123 Commit 7 E
2010-04-07 05:37 +0000 Max Power origin/HEAD Commit 10 E
2010-01-12 01:56 +0000 Max Power mp/good Commit 8 E
2010-03-04 04:09 +0000 A. U. Thor refs/tags/v2.0 Commit 10 A
2010-03-12 16:31 +0000 René Lévesque v2.0.1 Commit 10 B
2010-01-20 14:18 +0000 A. U. Thor v1.1.1 Commit 9 A
[refs] All references 88%
EOF

0 comments on commit b65195f

Please sign in to comment.