fix regression where 'got send -T' failed if same tag already exists on server Problem reported and fix tested by Omar Polo.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/lib/send.c b/lib/send.c
index 7250f24..0576ad4 100644
--- a/lib/send.c
+++ b/lib/send.c
@@ -511,6 +511,8 @@ got_send_pack(const char *remote_name, struct got_pathlist_head *branch_names,
if (!got_ref_name_is_valid(refname))
continue;
+ if (strncmp(refname, "refs/tags/", 10) == 0)
+ is_tag = 1;
/*
* Find out whether this is a reference we want to upload.
* Otherwise we can still use this reference as a hint to
@@ -522,20 +524,17 @@ got_send_pack(const char *remote_name, struct got_pathlist_head *branch_names,
err = got_ref_resolve(&my_id, repo, my_ref);
if (err)
goto done;
- if (got_object_id_cmp(my_id, their_id) != 0)
+ if (got_object_id_cmp(my_id, their_id) != 0) {
+ if (!overwrite_refs && is_tag) {
+ err = got_error_fmt(
+ GOT_ERR_SEND_TAG_EXISTS,
+ "%s", refname);
+ free(my_id);
+ goto done;
+ }
refs_to_send++;
+ }
free(my_id);
-
- }
-
- if (strncmp(refname, "refs/tags/", 10) == 0)
- is_tag = 1;
-
- /* Prevent tags from being overwritten by default. */
- if (!overwrite_refs && my_ref && is_tag) {
- err = got_error_fmt(GOT_ERR_SEND_TAG_EXISTS,
- "%s", refname);
- goto done;
}
/* Check if their object exists locally. */
diff --git a/regress/cmdline/send.sh b/regress/cmdline/send.sh
index bf73786..3eb8e7e 100755
--- a/regress/cmdline/send.sh
+++ b/regress/cmdline/send.sh
@@ -687,6 +687,24 @@ EOF
return 1
fi
+ # Send the same tags again. This should be a no-op.
+ got send -q -r $testroot/repo -T > $testroot/stdout 2> $testroot/stderr
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got send command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo -n > $testroot/stdout.expected
+ cmp -s $testroot/stdout $testroot/stdout.expected
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
# Overwriting an existing tag 'got send -f'.
got ref -r $testroot/repo -d refs/tags/1.0 >/dev/null
got tag -r $testroot/repo -m '1.0' 1.0 >/dev/null