Skip to content

Commit 05d290e

Browse files
committed
Merge branch 'nm/tag-edit'
"git tag" learned an explicit "--edit" option that allows the message given via "-m" and "-F" to be further edited. * nm/tag-edit: tag: add --edit option
2 parents 7e31236 + 9eed6e4 commit 05d290e

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

Documentation/git-tag.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-tag - Create, list, delete or verify a tag object signed with GPG
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git tag' [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>]
12+
'git tag' [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>] [-e]
1313
<tagname> [<commit> | <object>]
1414
'git tag' -d <tagname>...
1515
'git tag' [-n[<num>]] -l [--contains <commit>] [--no-contains <commit>]
@@ -167,6 +167,12 @@ This option is only applicable when listing tags without annotation lines.
167167
Implies `-a` if none of `-a`, `-s`, or `-u <keyid>`
168168
is given.
169169

170+
-e::
171+
--edit::
172+
The message taken from file with `-F` and command line with
173+
`-m` are usually used as the tag message unmodified.
174+
This option lets you further edit the message taken from these sources.
175+
170176
--cleanup=<mode>::
171177
This option sets how the tag message is cleaned up.
172178
The '<mode>' can be one of 'verbatim', 'whitespace' and 'strip'. The

builtin/tag.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ static int build_tag_object(struct strbuf *buf, int sign, struct object_id *resu
194194

195195
struct create_tag_options {
196196
unsigned int message_given:1;
197+
unsigned int use_editor:1;
197198
unsigned int sign;
198199
enum {
199200
CLEANUP_NONE,
@@ -224,7 +225,7 @@ static void create_tag(const struct object_id *object, const char *tag,
224225
tag,
225226
git_committer_info(IDENT_STRICT));
226227

227-
if (!opt->message_given) {
228+
if (!opt->message_given || opt->use_editor) {
228229
int fd;
229230

230231
/* write the template message before editing: */
@@ -233,7 +234,10 @@ static void create_tag(const struct object_id *object, const char *tag,
233234
if (fd < 0)
234235
die_errno(_("could not create file '%s'"), path);
235236

236-
if (!is_null_oid(prev)) {
237+
if (opt->message_given) {
238+
write_or_die(fd, buf->buf, buf->len);
239+
strbuf_reset(buf);
240+
} else if (!is_null_oid(prev)) {
237241
write_tag_body(fd, prev);
238242
} else {
239243
struct strbuf buf = STRBUF_INIT;
@@ -372,6 +376,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
372376
static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
373377
struct ref_format format = REF_FORMAT_INIT;
374378
int icase = 0;
379+
int edit_flag = 0;
375380
struct option options[] = {
376381
OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
377382
{ OPTION_INTEGER, 'n', NULL, &filter.lines, N_("n"),
@@ -386,6 +391,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
386391
OPT_CALLBACK('m', "message", &msg, N_("message"),
387392
N_("tag message"), parse_msg_arg),
388393
OPT_FILENAME('F', "file", &msgfile, N_("read message from file")),
394+
OPT_BOOL('e', "edit", &edit_flag, N_("force edit of tag message")),
389395
OPT_BOOL('s', "sign", &opt.sign, N_("annotated and GPG-signed tag")),
390396
OPT_STRING(0, "cleanup", &cleanup_arg, N_("mode"),
391397
N_("how to strip spaces and #comments from message")),
@@ -524,6 +530,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
524530
die(_("tag '%s' already exists"), tag);
525531

526532
opt.message_given = msg.given || msgfile;
533+
opt.use_editor = edit_flag;
527534

528535
if (!cleanup_arg || !strcmp(cleanup_arg, "strip"))
529536
opt.cleanup_mode = CLEANUP_ALL;

t/t7004-tag.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,21 @@ test_expect_success \
452452
test_cmp expect actual
453453
'
454454

455+
get_tag_header annotated-tag-edit $commit commit $time >expect
456+
echo "An edited message" >>expect
457+
test_expect_success 'set up editor' '
458+
write_script fakeeditor <<-\EOF
459+
sed -e "s/A message/An edited message/g" <"$1" >"$1-"
460+
mv "$1-" "$1"
461+
EOF
462+
'
463+
test_expect_success \
464+
'creating an annotated tag with -m message --edit should succeed' '
465+
GIT_EDITOR=./fakeeditor git tag -m "A message" --edit annotated-tag-edit &&
466+
get_tag_msg annotated-tag-edit >actual &&
467+
test_cmp expect actual
468+
'
469+
455470
cat >msgfile <<EOF
456471
Another message
457472
in a file.
@@ -465,6 +480,21 @@ test_expect_success \
465480
test_cmp expect actual
466481
'
467482

483+
get_tag_header file-annotated-tag-edit $commit commit $time >expect
484+
sed -e "s/Another message/Another edited message/g" msgfile >>expect
485+
test_expect_success 'set up editor' '
486+
write_script fakeeditor <<-\EOF
487+
sed -e "s/Another message/Another edited message/g" <"$1" >"$1-"
488+
mv "$1-" "$1"
489+
EOF
490+
'
491+
test_expect_success \
492+
'creating an annotated tag with -F messagefile --edit should succeed' '
493+
GIT_EDITOR=./fakeeditor git tag -F msgfile --edit file-annotated-tag-edit &&
494+
get_tag_msg file-annotated-tag-edit >actual &&
495+
test_cmp expect actual
496+
'
497+
468498
cat >inputmsg <<EOF
469499
A message from the
470500
standard input

0 commit comments

Comments
 (0)