From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 2/2] merge: allow fast-forwarding to an annotated but unsigned tag
Date: Tue, 5 Jun 2012 12:58:32 -0700 [thread overview]
Message-ID: <1338926312-4239-3-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1338926312-4239-1-git-send-email-gitster@pobox.com>
Update the merging_signed_tag() helper to check if the tag object
actually has a signature-looking string, so that we do not forbid
fast-forwarding to an annotated but unsigned tag. By definition,
there will be no signed payload in such a tag to be moved to the
mergetag header, so we are not losing anything by fast-forwarding.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin/merge.c | 14 +++++++++++++-
t/t7600-merge.sh | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index 23389f2..82d343c 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -28,6 +28,7 @@
#include "remote.h"
#include "fmt-merge-msg.h"
#include "gpg-interface.h"
+#include "tag.h"
#define DEFAULT_TWOHEAD (1<<0)
#define DEFAULT_OCTOPUS (1<<1)
@@ -1102,10 +1103,21 @@ static void write_merge_state(void)
static int merging_signed_tag(struct commit *parent)
{
struct merge_remote_desc *desc = merge_remote_util(parent);
+ unsigned long size;
+ enum object_type type;
+ char *buf;
+ size_t sig_offset;
if (!desc || !desc->obj || desc->obj->type != OBJ_TAG)
return 0;
- return 1;
+
+ buf = read_sha1_file(desc->obj->sha1, &type, &size);
+ if (!buf || type != OBJ_TAG) {
+ free(buf);
+ return 0; /* error will be caught downstream */
+ }
+ sig_offset = parse_signature(buf, size);
+ return (sig_offset < size);
}
int cmd_merge(int argc, const char **argv, const char *prefix)
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 9e27bbf..3c48327 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -695,4 +695,42 @@ test_expect_success GPG 'merge --no-edit tag should skip editor' '
test_cmp actual expect
'
+test_expect_success 'merge ff annotated tag should just ff' '
+ git reset --hard c0 &&
+ git commit --allow-empty -m "A newer commit" &&
+ git tag -a -m "An annotated tag" anno &&
+ git reset --hard c0 &&
+
+ # This should not even bother with an editor session; "false"
+ # will ensure that an attempt to run the editor is caught.
+ EDITOR=false git merge anno &&
+
+ git rev-parse anno^0 >expect &&
+ git rev-parse HEAD >actual &&
+ test_cmp actual expect &&
+
+ git rev-parse c0^0 >expect &&
+ git rev-parse HEAD^ >actual &&
+ test_cmp actual expect
+'
+
+test_expect_success 'merge --no-ff annotated tag' '
+ git reset --hard c0 &&
+ git commit --allow-empty -m "A newer commit" &&
+ git tag -f -a -m "An annotated tag" anno &&
+ git reset --hard c0 &&
+
+ EDITOR=./editor git merge --no-ff --edit anno &&
+ git rev-parse anno^0 >expect &&
+ git rev-parse HEAD^2 >actual &&
+ test_cmp actual expect &&
+
+ git rev-parse c0^0 >expect &&
+ git rev-parse HEAD^ >actual &&
+ test_cmp actual expect &&
+
+ git cat-file commit HEAD >raw &&
+ grep "An annotated tag" raw
+'
+
test_done
--
1.7.11.rc1.37.g09843ac
next prev parent reply other threads:[~2012-06-05 19:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-05 19:58 [PATCH 0/2] Feeding an annotated but unsigned tag to "git merge" Junio C Hamano
2012-06-05 19:58 ` [PATCH 1/2] merge: separte the logic to check for a signed tag Junio C Hamano
2012-06-05 19:58 ` Junio C Hamano [this message]
2012-06-06 13:42 ` [PATCH 0/2] Feeding an annotated but unsigned tag to "git merge" Jeff King
2012-06-06 16:37 ` Junio C Hamano
2012-06-07 9:09 ` Jeff King
2012-06-07 16:17 ` 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=1338926312-4239-3-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.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).