diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-02-27 10:08:56 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-02-27 10:08:56 -0800 |
commit | 21522cf5d0a719ceb7c4b935294be7737062763a (patch) | |
tree | 7690959a0d04b8fba68c4357a449c10544465be3 /sequencer.c | |
parent | dadc8e6dacb629f46aee39bde90b6f09b73722eb (diff) | |
parent | 16b3880dd7e617f909b2a3bc3672e29a897842bd (diff) | |
download | git-21522cf5d0a719ceb7c4b935294be7737062763a.tar.gz |
Merge branch 'pw/rebase-i-validate-labels-early'
An invalid label or ref in the "rebase -i" todo file used to
trigger an runtime error. SUch an error is now diagnosed while the
todo file is parsed.
* pw/rebase-i-validate-labels-early:
rebase -i: check labels and refs when parsing todo list
Diffstat (limited to 'sequencer.c')
-rw-r--r-- | sequencer.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/sequencer.c b/sequencer.c index 65a34f9676..a7e6db4f78 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2487,6 +2487,34 @@ static int is_command(enum todo_command command, const char **bol) (*bol = p)); } +static int check_label_or_ref_arg(enum todo_command command, const char *arg) +{ + switch (command) { + case TODO_LABEL: + /* + * '#' is not a valid label as the merge command uses it to + * separate merge parents from the commit subject. + */ + if (!strcmp(arg, "#") || + check_refname_format(arg, REFNAME_ALLOW_ONELEVEL)) + return error(_("'%s' is not a valid label"), arg); + break; + + case TODO_UPDATE_REF: + if (check_refname_format(arg, REFNAME_ALLOW_ONELEVEL)) + return error(_("'%s' is not a valid refname"), arg); + if (check_refname_format(arg, 0)) + return error(_("update-ref requires a fully qualified " + "refname e.g. refs/heads/%s"), arg); + break; + + default: + BUG("unexpected todo_command"); + } + + return 0; +} + static int parse_insn_line(struct repository *r, struct todo_item *item, const char *buf, const char *bol, char *eol) { @@ -2535,10 +2563,19 @@ static int parse_insn_line(struct repository *r, struct todo_item *item, if (item->command == TODO_EXEC || item->command == TODO_LABEL || item->command == TODO_RESET || item->command == TODO_UPDATE_REF) { + int ret = 0; + item->commit = NULL; item->arg_offset = bol - buf; item->arg_len = (int)(eol - bol); - return 0; + if (item->command == TODO_LABEL || + item->command == TODO_UPDATE_REF) { + saved = *eol; + *eol = '\0'; + ret = check_label_or_ref_arg(item->command, bol); + *eol = saved; + } + return ret; } if (item->command == TODO_FIXUP) { |