tag: add --edit option
Add a --edit option whichs allows modifying the messages provided by -m or -F, the same way git commit --edit does. Signed-off-by: Nicolas Morey-Chaisemartin <NMoreyChaisemartin@suse.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
2512f15446
commit
9eed6e40c0
|
@ -9,7 +9,7 @@ git-tag - Create, list, delete or verify a tag object signed with GPG
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
[verse]
|
[verse]
|
||||||
'git tag' [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>]
|
'git tag' [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>] [-e]
|
||||||
<tagname> [<commit> | <object>]
|
<tagname> [<commit> | <object>]
|
||||||
'git tag' -d <tagname>...
|
'git tag' -d <tagname>...
|
||||||
'git tag' [-n[<num>]] -l [--contains <commit>] [--no-contains <commit>]
|
'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.
|
||||||
Implies `-a` if none of `-a`, `-s`, or `-u <keyid>`
|
Implies `-a` if none of `-a`, `-s`, or `-u <keyid>`
|
||||||
is given.
|
is given.
|
||||||
|
|
||||||
|
-e::
|
||||||
|
--edit::
|
||||||
|
The message taken from file with `-F` and command line with
|
||||||
|
`-m` are usually used as the tag message unmodified.
|
||||||
|
This option lets you further edit the message taken from these sources.
|
||||||
|
|
||||||
--cleanup=<mode>::
|
--cleanup=<mode>::
|
||||||
This option sets how the tag message is cleaned up.
|
This option sets how the tag message is cleaned up.
|
||||||
The '<mode>' can be one of 'verbatim', 'whitespace' and 'strip'. The
|
The '<mode>' can be one of 'verbatim', 'whitespace' and 'strip'. The
|
||||||
|
|
|
@ -194,6 +194,7 @@ static int build_tag_object(struct strbuf *buf, int sign, struct object_id *resu
|
||||||
|
|
||||||
struct create_tag_options {
|
struct create_tag_options {
|
||||||
unsigned int message_given:1;
|
unsigned int message_given:1;
|
||||||
|
unsigned int use_editor:1;
|
||||||
unsigned int sign;
|
unsigned int sign;
|
||||||
enum {
|
enum {
|
||||||
CLEANUP_NONE,
|
CLEANUP_NONE,
|
||||||
|
@ -224,7 +225,7 @@ static void create_tag(const struct object_id *object, const char *tag,
|
||||||
tag,
|
tag,
|
||||||
git_committer_info(IDENT_STRICT));
|
git_committer_info(IDENT_STRICT));
|
||||||
|
|
||||||
if (!opt->message_given) {
|
if (!opt->message_given || opt->use_editor) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
/* write the template message before editing: */
|
/* write the template message before editing: */
|
||||||
|
@ -233,7 +234,10 @@ static void create_tag(const struct object_id *object, const char *tag,
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
die_errno(_("could not create file '%s'"), path);
|
die_errno(_("could not create file '%s'"), path);
|
||||||
|
|
||||||
if (!is_null_oid(prev)) {
|
if (opt->message_given) {
|
||||||
|
write_or_die(fd, buf->buf, buf->len);
|
||||||
|
strbuf_reset(buf);
|
||||||
|
} else if (!is_null_oid(prev)) {
|
||||||
write_tag_body(fd, prev);
|
write_tag_body(fd, prev);
|
||||||
} else {
|
} else {
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
|
@ -372,6 +376,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
|
||||||
static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
|
static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
|
||||||
struct ref_format format = REF_FORMAT_INIT;
|
struct ref_format format = REF_FORMAT_INIT;
|
||||||
int icase = 0;
|
int icase = 0;
|
||||||
|
int edit_flag = 0;
|
||||||
struct option options[] = {
|
struct option options[] = {
|
||||||
OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
|
OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
|
||||||
{ OPTION_INTEGER, 'n', NULL, &filter.lines, N_("n"),
|
{ OPTION_INTEGER, 'n', NULL, &filter.lines, N_("n"),
|
||||||
|
@ -386,6 +391,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
|
||||||
OPT_CALLBACK('m', "message", &msg, N_("message"),
|
OPT_CALLBACK('m', "message", &msg, N_("message"),
|
||||||
N_("tag message"), parse_msg_arg),
|
N_("tag message"), parse_msg_arg),
|
||||||
OPT_FILENAME('F', "file", &msgfile, N_("read message from file")),
|
OPT_FILENAME('F', "file", &msgfile, N_("read message from file")),
|
||||||
|
OPT_BOOL('e', "edit", &edit_flag, N_("force edit of tag message")),
|
||||||
OPT_BOOL('s', "sign", &opt.sign, N_("annotated and GPG-signed tag")),
|
OPT_BOOL('s', "sign", &opt.sign, N_("annotated and GPG-signed tag")),
|
||||||
OPT_STRING(0, "cleanup", &cleanup_arg, N_("mode"),
|
OPT_STRING(0, "cleanup", &cleanup_arg, N_("mode"),
|
||||||
N_("how to strip spaces and #comments from message")),
|
N_("how to strip spaces and #comments from message")),
|
||||||
|
@ -524,6 +530,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
|
||||||
die(_("tag '%s' already exists"), tag);
|
die(_("tag '%s' already exists"), tag);
|
||||||
|
|
||||||
opt.message_given = msg.given || msgfile;
|
opt.message_given = msg.given || msgfile;
|
||||||
|
opt.use_editor = edit_flag;
|
||||||
|
|
||||||
if (!cleanup_arg || !strcmp(cleanup_arg, "strip"))
|
if (!cleanup_arg || !strcmp(cleanup_arg, "strip"))
|
||||||
opt.cleanup_mode = CLEANUP_ALL;
|
opt.cleanup_mode = CLEANUP_ALL;
|
||||||
|
|
|
@ -452,6 +452,21 @@ test_expect_success \
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
get_tag_header annotated-tag-edit $commit commit $time >expect
|
||||||
|
echo "An edited message" >>expect
|
||||||
|
test_expect_success 'set up editor' '
|
||||||
|
write_script fakeeditor <<-\EOF
|
||||||
|
sed -e "s/A message/An edited message/g" <"$1" >"$1-"
|
||||||
|
mv "$1-" "$1"
|
||||||
|
EOF
|
||||||
|
'
|
||||||
|
test_expect_success \
|
||||||
|
'creating an annotated tag with -m message --edit should succeed' '
|
||||||
|
GIT_EDITOR=./fakeeditor git tag -m "A message" --edit annotated-tag-edit &&
|
||||||
|
get_tag_msg annotated-tag-edit >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
cat >msgfile <<EOF
|
cat >msgfile <<EOF
|
||||||
Another message
|
Another message
|
||||||
in a file.
|
in a file.
|
||||||
|
@ -465,6 +480,21 @@ test_expect_success \
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
get_tag_header file-annotated-tag-edit $commit commit $time >expect
|
||||||
|
sed -e "s/Another message/Another edited message/g" msgfile >>expect
|
||||||
|
test_expect_success 'set up editor' '
|
||||||
|
write_script fakeeditor <<-\EOF
|
||||||
|
sed -e "s/Another message/Another edited message/g" <"$1" >"$1-"
|
||||||
|
mv "$1-" "$1"
|
||||||
|
EOF
|
||||||
|
'
|
||||||
|
test_expect_success \
|
||||||
|
'creating an annotated tag with -F messagefile --edit should succeed' '
|
||||||
|
GIT_EDITOR=./fakeeditor git tag -F msgfile --edit file-annotated-tag-edit &&
|
||||||
|
get_tag_msg file-annotated-tag-edit >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
cat >inputmsg <<EOF
|
cat >inputmsg <<EOF
|
||||||
A message from the
|
A message from the
|
||||||
standard input
|
standard input
|
||||||
|
|
Loading…
Reference in New Issue