From: Chris Rorvick <chris@rorvick.com>
To: git@vger.kernel.org
Cc: Chris Rorvick <chris@rorvick.com>,
Angelo Borsotti <angelo.borsotti@gmail.com>,
Drew Northup <n1xim.email@gmail.com>,
Michael Haggerty <mhagger@alum.mit.edu>,
Philip Oakley <philipoakley@iee.org>,
Johannes Sixt <j6t@kdbg.org>,
Kacper Kornet <draenog@pld-linux.org>, Jeff King <peff@peff.net>,
Felipe Contreras <felipe.contreras@gmail.com>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 6/7] push: require force for annotated tags
Date: Thu, 22 Nov 2012 22:21:54 -0600 [thread overview]
Message-ID: <1353644515-17349-7-git-send-email-chris@rorvick.com> (raw)
In-Reply-To: <1353644515-17349-1-git-send-email-chris@rorvick.com>
Do not allow fast-forwarding of references that point to a tag object.
This keeps the behavior consistent with lightweight tags. Additionally,
allowing the reference to update could leave the old object dangling.
Signed-off-by: Chris Rorvick <chris@rorvick.com>
---
Documentation/git-push.txt | 10 +++++-----
remote.c | 11 +++++++++--
t/t5516-fetch-push.sh | 21 +++++++++++++++++++++
3 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 09bdec7..7a04ce5 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -52,11 +52,11 @@ updated.
+
The object referenced by <src> is used to update the <dst> reference
on the remote side. By default this is only allowed if <dst> is not
-under refs/tags/, and then only if it can fast-forward <dst>. By having
-the optional leading `+`, you can tell git to update the <dst> ref even
-if it is not allowed by default (e.g., it is not a fast-forward.) This
-does *not* attempt to merge <src> into <dst>. See EXAMPLES below for
-details.
+a tag (annotated or lightweight), and then only if it can fast-forward
+<dst>. By having the optional leading `+`, you can tell git to update
+the <dst> ref even if it is not allowed by default (e.g., it is not a
+fast-forward.) This does *not* attempt to merge <src> into <dst>. See
+EXAMPLES below for details.
+
`tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`.
+
diff --git a/remote.c b/remote.c
index 012b52f..f5bc4e7 100644
--- a/remote.c
+++ b/remote.c
@@ -1281,9 +1281,16 @@ int match_push_refs(struct ref *src, struct ref **dst,
static inline int is_forwardable(struct ref* ref)
{
+ struct object *o;
+
if (!prefixcmp(ref->name, "refs/tags/"))
return 0;
+ /* old object must be a commit */
+ o = parse_object(ref->old_sha1);
+ if (!o || o->type != OBJ_COMMIT)
+ return 0;
+
return 1;
}
@@ -1323,8 +1330,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
* to overwrite it; you would not know what you are losing
* otherwise.
*
- * (4) if both new and old are commit-ish, and new is a
- * descendant of old, it is OK.
+ * (4) if old is a commit and new is a descendant of old
+ * (implying new is commit-ish), it is OK.
*
* (5) regardless of all of the above, removing :B is
* always allowed.
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 8f024a0..6009372 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -950,6 +950,27 @@ test_expect_success 'push requires --force to update lightweight tag' '
)
'
+test_expect_success 'push requires --force to update annotated tag' '
+ mk_test heads/master &&
+ mk_child child1 &&
+ mk_child child2 &&
+ (
+ cd child1 &&
+ git tag -a -m "message 1" Tag &&
+ git push ../child2 Tag:refs/tmp/Tag &&
+ git push ../child2 Tag:refs/tmp/Tag &&
+ >file1 &&
+ git add file1 &&
+ git commit -m "file1" &&
+ git tag -f -a -m "message 2" Tag &&
+ test_must_fail git push ../child2 Tag:refs/tmp/Tag &&
+ git push --force ../child2 Tag:refs/tmp/Tag &&
+ git tag -f -a -m "message 3" Tag HEAD~ &&
+ test_must_fail git push ../child2 Tag:refs/tmp/Tag &&
+ git push --force ../child2 Tag:refs/tmp/Tag
+ )
+'
+
test_expect_success 'push --porcelain' '
mk_empty &&
echo >.git/foo "To testrepo" &&
--
1.8.0.209.gf3828dc
next prev parent reply other threads:[~2012-11-23 4:23 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-23 4:21 [PATCH v5 0/7] push: update remote tags only with force Chris Rorvick
2012-11-23 4:21 ` [PATCH 1/7] push: return reject reasons via a mask Chris Rorvick
2012-11-26 18:43 ` Junio C Hamano
2012-11-27 3:00 ` Chris Rorvick
2012-11-23 4:21 ` [PATCH 2/7] push: add advice for rejected tag reference Chris Rorvick
2012-11-23 4:21 ` [PATCH 3/7] push: flag updates Chris Rorvick
2012-11-23 4:21 ` [PATCH 4/7] push: flag updates that require force Chris Rorvick
2012-11-23 4:21 ` [PATCH 5/7] push: require force for refs under refs/tags/ Chris Rorvick
2012-11-26 18:57 ` Junio C Hamano
2012-11-27 4:17 ` Chris Rorvick
2012-11-27 17:12 ` Junio C Hamano
2012-11-28 5:18 ` [PATCH] push: cleanup push rules comment Chris Rorvick
2012-11-28 16:58 ` Junio C Hamano
2012-11-23 4:21 ` Chris Rorvick [this message]
2012-11-23 4:21 ` [PATCH 7/7] push: clarify rejection of update to non-commit-ish Chris Rorvick
2012-11-26 18:53 ` Junio C Hamano
2012-11-27 3:52 ` Chris Rorvick
2012-11-27 17:11 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1353644515-17349-7-git-send-email-chris@rorvick.com \
--to=chris@rorvick.com \
--cc=angelo.borsotti@gmail.com \
--cc=draenog@pld-linux.org \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=mhagger@alum.mit.edu \
--cc=n1xim.email@gmail.com \
--cc=peff@peff.net \
--cc=philipoakley@iee.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).