Skip to content

Commit cd33b41

Browse files
committed
Merge branch 'jk/remote-helper-with-signed-tags'
Allows remote-helpers to declare they can handle signed tags, and issue a warning when using those that don't. * jk/remote-helper-with-signed-tags: transport-helper: add 'signed-tags' capability transport-helper: pass --signed-tags=warn-strip to fast-export fast-export: add --signed-tags=warn-strip mode
2 parents 2d0b071 + 0d957a4 commit cd33b41

7 files changed

Lines changed: 50 additions & 6 deletions

File tree

Documentation/git-fast-export.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ OPTIONS
2727
Insert 'progress' statements every <n> objects, to be shown by
2828
'git fast-import' during import.
2929

30-
--signed-tags=(verbatim|warn|strip|abort)::
30+
--signed-tags=(verbatim|warn|warn-strip|strip|abort)::
3131
Specify how to handle signed tags. Since any transformation
3232
after the export can change the tag names (which can also happen
3333
when excluding revisions) the signatures will not match.
3434
+
3535
When asking to 'abort' (which is the default), this program will die
36-
when encountering a signed tag. With 'strip', the tags will be made
37-
unsigned, with 'verbatim', they will be silently exported
38-
and with 'warn', they will be exported, but you will see a warning.
36+
when encountering a signed tag. With 'strip', the tags will silently
37+
be made unsigned, with 'warn-strip' they will be made unsigned but a
38+
warning will be displayed, with 'verbatim', they will be silently
39+
exported and with 'warn', they will be exported, but you will see a
40+
warning.
3941

4042
--tag-of-filtered-object=(abort|drop|rewrite)::
4143
Specify how to handle tags whose tagged object is filtered out.

Documentation/gitremote-helpers.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ capability then it should advertise `refspec *:*`.
202202
marks specified in <file> before processing any input. For details,
203203
read up on '--import-marks=<file>' in linkgit:git-fast-export[1].
204204

205+
'signed-tags'::
206+
This modifies the 'export' capability, instructing Git to pass
207+
'--signed-tags=verbatim' to linkgit:git-fast-export[1]. In the
208+
absence of this capability, Git will use '--signed-tags=warn-strip'.
205209

206210

207211

builtin/fast-export.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static const char *fast_export_usage[] = {
2424
};
2525

2626
static int progress;
27-
static enum { ABORT, VERBATIM, WARN, STRIP } signed_tag_mode = ABORT;
27+
static enum { ABORT, VERBATIM, WARN, WARN_STRIP, STRIP } signed_tag_mode = ABORT;
2828
static enum { ERROR, DROP, REWRITE } tag_of_filtered_mode = ERROR;
2929
static int fake_missing_tagger;
3030
static int use_done_feature;
@@ -40,6 +40,8 @@ static int parse_opt_signed_tag_mode(const struct option *opt,
4040
signed_tag_mode = VERBATIM;
4141
else if (!strcmp(arg, "warn"))
4242
signed_tag_mode = WARN;
43+
else if (!strcmp(arg, "warn-strip"))
44+
signed_tag_mode = WARN_STRIP;
4345
else if (!strcmp(arg, "strip"))
4446
signed_tag_mode = STRIP;
4547
else
@@ -428,6 +430,10 @@ static void handle_tag(const char *name, struct tag *tag)
428430
/* fallthru */
429431
case VERBATIM:
430432
break;
433+
case WARN_STRIP:
434+
warning ("Stripping signature from tag %s",
435+
sha1_to_hex(tag->object.sha1));
436+
/* fallthru */
431437
case STRIP:
432438
message_size = signature + 1 - message;
433439
break;

git-remote-testgit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ do
3838
echo "*import-marks $gitmarks"
3939
echo "*export-marks $gitmarks"
4040
fi
41+
test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
4142
echo
4243
;;
4344
list)

t/t5801-remote-helpers.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
test_description='Test remote-helper import and export commands'
77

88
. ./test-lib.sh
9+
. "$TEST_DIRECTORY"/lib-gpg.sh
910

1011
if ! type "${BASH-bash}" >/dev/null 2>&1; then
1112
skip_all='skipping remote-testgit tests, bash not available'
@@ -166,4 +167,23 @@ test_expect_success 'push ref with existing object' '
166167
compare_refs local dup server dup
167168
'
168169

170+
test_expect_success GPG 'push signed tag' '
171+
(cd local &&
172+
git checkout master &&
173+
git tag -s -m signed-tag signed-tag &&
174+
git push origin signed-tag
175+
) &&
176+
compare_refs local signed-tag^{} server signed-tag^{} &&
177+
test_must_fail compare_refs local signed-tag server signed-tag
178+
'
179+
180+
test_expect_success GPG 'push signed tag with signed-tags capability' '
181+
(cd local &&
182+
git checkout master &&
183+
git tag -s -m signed-tag signed-tag-2 &&
184+
GIT_REMOTE_TESTGIT_SIGNED_TAGS=1 git push origin signed-tag-2
185+
) &&
186+
compare_refs local signed-tag-2 server signed-tag-2
187+
'
188+
169189
test_done

t/t9350-fast-export.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ test_expect_success 'signed-tags=strip' '
146146
147147
'
148148

149+
test_expect_success 'signed-tags=warn-strip' '
150+
git fast-export --signed-tags=warn-strip sign-your-name >output 2>err &&
151+
! grep PGP output &&
152+
test -s err
153+
'
154+
149155
test_expect_success 'setup submodule' '
150156
151157
git checkout -f master &&

transport-helper.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ struct helper_data {
2525
option : 1,
2626
push : 1,
2727
connect : 1,
28+
signed_tags : 1,
2829
no_disconnect_req : 1;
2930
char *export_marks;
3031
char *import_marks;
@@ -191,6 +192,8 @@ static struct child_process *get_helper(struct transport *transport)
191192
refspecs[refspec_nr++] = xstrdup(capname + strlen("refspec "));
192193
} else if (!strcmp(capname, "connect")) {
193194
data->connect = 1;
195+
} else if (!strcmp(capname, "signed-tags")) {
196+
data->signed_tags = 1;
194197
} else if (!prefixcmp(capname, "export-marks ")) {
195198
struct strbuf arg = STRBUF_INIT;
196199
strbuf_addstr(&arg, "--export-marks=");
@@ -410,9 +413,11 @@ static int get_exporter(struct transport *transport,
410413
/* we need to duplicate helper->in because we want to use it after
411414
* fastexport is done with it. */
412415
fastexport->out = dup(helper->in);
413-
fastexport->argv = xcalloc(5 + revlist_args->nr, sizeof(*fastexport->argv));
416+
fastexport->argv = xcalloc(6 + revlist_args->nr, sizeof(*fastexport->argv));
414417
fastexport->argv[argc++] = "fast-export";
415418
fastexport->argv[argc++] = "--use-done-feature";
419+
fastexport->argv[argc++] = data->signed_tags ?
420+
"--signed-tags=verbatim" : "--signed-tags=warn-strip";
416421
if (data->export_marks)
417422
fastexport->argv[argc++] = data->export_marks;
418423
if (data->import_marks)

0 commit comments

Comments
 (0)