From: Lucas Oshiro <lucasseikioshiro@gmail.com>
To: git@vger.kernel.org
Cc: kernel-usp@googlegroups.com, rcdailey.lists@gmail.com,
me@ttaylorr.com, peff@peff.net, matheus.bernardino@usp.br,
"Bárbara Fernandes" <barbara.dcf@gmail.com>
Subject: [RFC WIP PATCH 3/3] tag: add full support for --edit and --no-edit
Date: Tue, 8 Oct 2019 15:47:27 -0300 [thread overview]
Message-ID: <20191008184727.14337-4-lucasseikioshiro@gmail.com> (raw)
In-Reply-To: <20191008184727.14337-1-lucasseikioshiro@gmail.com>
git tag --edit and --no-edit flags are not currently fully supported.
This patch fixes the functionality that allows the editor to be opened
on demand.
Co-authored-by: Bárbara Fernandes <barbara.dcf@gmail.com>
Signed-off-by: Lucas Oshiro <lucasseikioshiro@gmail.com>
Signed-off-by: Bárbara Fernandes <barbara.dcf@gmail.com>
---
builtin/tag.c | 16 +++++++++++++---
t/t7004-tag.sh | 4 ++--
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/builtin/tag.c b/builtin/tag.c
index 0322bdbdfb..7dff61d45a 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -230,6 +230,7 @@ static int build_tag_object(struct strbuf *buf, int sign, struct object_id *resu
struct create_tag_options {
unsigned int message_given:1;
unsigned int use_editor:1;
+ unsigned int force_editor:1;
unsigned int sign;
enum {
CLEANUP_NONE,
@@ -307,13 +308,21 @@ static void create_tag(const struct object_id *object, const char *object_ref,
tag,
git_committer_info(IDENT_STRICT));
- if (!opt->message_given || opt->use_editor) {
+ if (opt->force_editor && !opt->message_given && is_null_oid(prev) &&
+ !opt->use_editor) {
+ die(_("no tag message?"));
+ } else if ((!opt->force_editor && !opt->message_given && is_null_oid(prev))
+ || (opt->force_editor && opt->use_editor)) {
+ /* Editor must be opened */
prepare_tag_template(buf, opt, prev, path, tag);
if (launch_editor(path, buf, NULL)) {
fprintf(stderr,
_("Please supply the message using either -m or -F option.\n"));
exit(1);
}
+ } else if (!opt->message_given) {
+ /* Tag already exists and user doesn't want to change it */
+ strbuf_addstr(buf, get_tag_body(prev, NULL));
}
if (opt->cleanup_mode != CLEANUP_NONE)
@@ -436,7 +445,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
static struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;
struct ref_format format = REF_FORMAT_INIT;
int icase = 0;
- int edit_flag = 0;
+ int edit_flag = -1;
struct option options[] = {
OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
{ OPTION_INTEGER, 'n', NULL, &filter.lines, N_("n"),
@@ -592,7 +601,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
die(_("tag '%s' already exists"), tag);
opt.message_given = msg.given || msgfile;
- opt.use_editor = edit_flag;
+ opt.force_editor = edit_flag >= 0;
+ opt.use_editor = opt.force_editor ? edit_flag : 0;
if (!cleanup_arg || !strcmp(cleanup_arg, "strip"))
opt.cleanup_mode = CLEANUP_ALL;
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index 80eb13d94e..bf43d2c750 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1313,7 +1313,7 @@ test_expect_success GPG,RFC1991 \
'reediting a signed tag body omits signature' '
echo "rfc1991" >gpghome/gpg.conf &&
echo "RFC1991 signed tag" >expect &&
- GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
+ GIT_EDITOR=./fakeeditor git tag -f --edit -s rfc1991-signed-tag $commit &&
test_cmp expect actual
'
@@ -1356,7 +1356,7 @@ test_expect_success GPG,RFC1991 \
test_expect_success GPG,RFC1991 \
'reediting a signed tag body omits signature' '
echo "RFC1991 signed tag" >expect &&
- GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
+ GIT_EDITOR=./fakeeditor git tag -f --edit -s rfc1991-signed-tag $commit &&
test_cmp expect actual
'
--
2.23.0
next prev parent reply other threads:[~2019-10-08 18:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-08 18:47 [RFC WIP PATCH 0/3] tag: fix --edit and --no-edit flags Lucas Oshiro
2019-10-08 18:47 ` [RFC WIP PATCH 1/3] tag: factor out tag reading from write_tag_body() Lucas Oshiro
2019-10-09 1:48 ` Matheus Tavares Bernardino
2019-10-10 2:42 ` Junio C Hamano
2019-10-08 18:47 ` [RFC WIP PATCH 2/3] tag: factor out prepare tag template code Lucas Oshiro
2019-10-09 3:02 ` Matheus Tavares Bernardino
2019-10-10 2:51 ` Junio C Hamano
2019-10-10 4:29 ` Junio C Hamano
2019-10-08 18:47 ` Lucas Oshiro [this message]
2019-10-09 9:19 ` [RFC WIP PATCH 3/3] tag: add full support for --edit and --no-edit Matheus Tavares Bernardino
2019-10-10 3:34 ` Junio C Hamano
2019-10-10 2:13 ` [RFC WIP PATCH 0/3] tag: fix --edit and --no-edit flags 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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191008184727.14337-4-lucasseikioshiro@gmail.com \
--to=lucasseikioshiro@gmail.com \
--cc=barbara.dcf@gmail.com \
--cc=git@vger.kernel.org \
--cc=kernel-usp@googlegroups.com \
--cc=matheus.bernardino@usp.br \
--cc=me@ttaylorr.com \
--cc=peff@peff.net \
--cc=rcdailey.lists@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).