git revert --continue --no-verify

9 messages, 3 authors, 2021-08-05 · open the first message on its own page

git revert --continue --no-verify

From: Cameron Steffen <hidden>
Date: 2021-08-03 19:17:20

Today I tried to run this command and I just got a help screen. I am
using 2.32.0.

git revert --continue --no-verify

Re: git revert --continue --no-verify

From: Taylor Blau <hidden>
Date: 2021-08-03 20:50:49

Hi Cameron,

On Tue, Aug 03, 2021 at 02:17:07PM -0500, Cameron Steffen wrote:
Today I tried to run this command and I just got a help screen. I am
using 2.32.0.

git revert --continue --no-verify
I can't think of any sequencer commands that support a `--[no-]verify`
argument. Did you mistake `--no-verify` for something else, like
`--no-edit` or `--no-commit`?

Thanks,
Taylor

Re: git revert --continue --no-verify

From: Cameron Steffen <hidden>
Date: 2021-08-03 20:57:03

`--no-verify` is an argument typically used with `git commit` in order
to skip the pre-commit hook. Since the pre-commit hook also runs on
`git revert --continue`, I expected to be able to use `--no-verify`.

On Tue, Aug 3, 2021 at 3:50 PM Taylor Blau [off-list ref] wrote:
Hi Cameron,

On Tue, Aug 03, 2021 at 02:17:07PM -0500, Cameron Steffen wrote:
quoted
Today I tried to run this command and I just got a help screen. I am
using 2.32.0.

git revert --continue --no-verify
I can't think of any sequencer commands that support a `--[no-]verify`
argument. Did you mistake `--no-verify` for something else, like
`--no-edit` or `--no-commit`?

Thanks,
Taylor

Re: git revert --continue --no-verify

From: Taylor Blau <hidden>
Date: 2021-08-03 21:00:03

On Tue, Aug 03, 2021 at 03:56:49PM -0500, Cameron Steffen wrote:
`--no-verify` is an argument typically used with `git commit` in order
to skip the pre-commit hook. Since the pre-commit hook also runs on
`git revert --continue`, I expected to be able to use `--no-verify`.
No, `git revert` doesn't pass unknown options down to `git commit`.

Thanks,
Taylor

Re: git revert --continue --no-verify

From: Cameron Steffen <hidden>
Date: 2021-08-03 21:33:24

Perhaps the issue then is that the pre-commit hook should not run for
`git revert --continue`? It does not run for `git revert`.

On Tue, Aug 3, 2021 at 4:00 PM Taylor Blau [off-list ref] wrote:
On Tue, Aug 03, 2021 at 03:56:49PM -0500, Cameron Steffen wrote:
quoted
`--no-verify` is an argument typically used with `git commit` in order
to skip the pre-commit hook. Since the pre-commit hook also runs on
`git revert --continue`, I expected to be able to use `--no-verify`.
No, `git revert` doesn't pass unknown options down to `git commit`.

Thanks,
Taylor

Re: git revert --continue --no-verify

From: Taylor Blau <hidden>
Date: 2021-08-03 22:08:00

On Tue, Aug 03, 2021 at 04:33:09PM -0500, Cameron Steffen wrote:
Perhaps the issue then is that the pre-commit hook should not run for
`git revert --continue`? It does not run for `git revert`.
This does look like an oversight to me, but you'll have to bear with me
since I am relatively unfamiliar with the sequencer code.

Ultimately `git revert` calls do_pick_commit() which either calls
do_commit() or run_git_commit(). A couple of curiosities there:

  - do_commit() does fall back to run_git_commit() if it has the
    VERIFY_MSG bit set in `flags`.
  - run_git_commit() passes `-n` only when VERIFY_MSG *isn't* set, so
    the VERIFY_MSG bit does imply that the pre-commit hook would be run
    there.
  - when do_pick_commit() does have to fall back to run_git_commit(), it
    sets the VERIFY_MSG bit in flags.

But we never end up calling run_git_commit() (except in the case of
errors) because do_pick_commit() special-cases `command == TODO_REVERT`
(which is the case for `git revert`) and calls `do_commit()`.

But it gets weirder: do_commit() calls run_git_commit() itself, but
before the caller in do_pick_commit() has had a chance to add VERIFY_MSG
to the flags.

So I suspect that this is an oversight, but perhaps somebody more
familiar with this code could confirm my thinking.

Thanks,
Taylor

Re: git revert --continue --no-verify

From: Phillip Wood <hidden>
Date: 2021-08-04 18:14:40

Hi Cameron and Taylor

On 03/08/2021 23:07, Taylor Blau wrote:
On Tue, Aug 03, 2021 at 04:33:09PM -0500, Cameron Steffen wrote:
quoted
Perhaps the issue then is that the pre-commit hook should not run for
`git revert --continue`? It does not run for `git revert`.
The general rule for cherry-pick, revert and rebase is that if the 
commit message is edited then the commit is made with --verify and if 
the commit message is not being edited then the commit is made with 
--no-verify. I think the reasoning for this is that if the user has 
altered the commit message or contents and they have a pre-commit hook 
set then it is reasonable to check the new commit is acceptable to the 
hook. There are some exceptions to this which are oversights (for 
example I think we always pass --no-verify when committing a conflict 
resolution with 'git rebase --continue' even though the editor opens 
when committing in that case - I should try and fix that)

For 'git revert --continue' the commit is made when sequencer_continue() 
calls continue_single_pick() which looks like

static int continue_single_pick(struct repository *r, struct replay_opts 
*opts)
{
	struct strvec argv = STRVEC_INIT;
	int ret;

	if (!refs_ref_exists(get_main_ref_store(r), "CHERRY_PICK_HEAD") &&
	    !refs_ref_exists(get_main_ref_store(r), "REVERT_HEAD"))
		return error(_("no cherry-pick or revert in progress"));

	strvec_push(&argv, "commit");

	/*
	 * continue_single_pick() handles the case of recovering from a
	 * conflict.  should_edit() doesn't handle that case; for a conflict,
	 * we want to edit if the user asked for it, or if they didn't specify
	 * and stdin is a tty.
	 */
	if (!opts->edit || (opts->edit < 0 && !isatty(0)))
		/*
		 * Include --cleanup=strip as well because we don't want the
		 * "# Conflicts:" messages.
		 */
		strvec_pushl(&argv, "--no-edit", "--cleanup=strip", NULL);

	ret = run_command_v_opt(argv.v, RUN_GIT_CMD);
	strvec_clear(&argv);
	return ret;
}

It runs git commit directly and never passes --no-verify. I wouldn't be 
opposed to someone adding support for --no-verify (and --no-edit) to 
"cherry-pick/revert/rebase --continue" on the understanding that it only 
applied when committing the conflict resolution. There is a possible 
confusion for users though who might expect that the options passed with 
'--continue' applied to all the commits made by the command.
This does look like an oversight to me, but you'll have to bear with me
since I am relatively unfamiliar with the sequencer code.

Ultimately `git revert` calls do_pick_commit()
This is what happens when we are picking commits, the commit made with 
'--continue' uses a different code path
which either calls
do_commit() or run_git_commit(). A couple of curiosities there:

   - do_commit() does fall back to run_git_commit() if it has the
     VERIFY_MSG bit set in `flags`.
   - run_git_commit() passes `-n` only when VERIFY_MSG *isn't* set, so
     the VERIFY_MSG bit does imply that the pre-commit hook would be run
     there.
   - when do_pick_commit() does have to fall back to run_git_commit(), it
     sets the VERIFY_MSG bit in flags.
Calling run_git_commit() there is not a fallback it, that call is used 
to reword commits once they have been picked (see 450efe2d53 ("rebase 
-i: always update HEAD before rewording", 2019-08-19) for the reasoning 
behind this) . Because the message is being edited there is no point in 
going through do_commit().
But we never end up calling run_git_commit() (except in the case of
errors) because do_pick_commit() special-cases `command == TODO_REVERT`
(which is the case for `git revert`) and calls `do_commit()`.

But it gets weirder: do_commit() calls run_git_commit() itself, but
before the caller in do_pick_commit() has had a chance to add VERIFY_MSG
to the flags.
do_commit() does not change the flags that it is called with - callers 
that want VERIFY_MSG will set that before they call do_commit(). 
do_commit() is there to commit simple picks without forking 'git commit'
So I suspect that this is an oversight, but perhaps somebody more
familiar with this code could confirm my thinking.
I hope the above helps - basically the idea is "if the commit has been 
edited use VERIFY_MSG" and --continue unhelpfully uses a completely 
different code-path to the main commit picking/reverting loop.

Best Wishes

Phillip
Thanks,
Taylor

Re: git revert --continue --no-verify

From: Taylor Blau <hidden>
Date: 2021-08-05 01:40:17

On Wed, Aug 04, 2021 at 07:14:34PM +0100, Phillip Wood wrote:
[...] I wouldn't be opposed to someone adding support for --no-verify
(and --no-edit) to "cherry-pick/revert/rebase --continue" on the
understanding that it only applied when committing the conflict
resolution. There is a possible confusion for users though who might
expect that the options passed with '--continue' applied to all the
commits made by the command.
Yeah, that feels like we are just trying to confuse the user ;). So I
agree that I'd rather not go any further along that direction.
do_commit() does not change the flags that it is called with - callers that
want VERIFY_MSG will set that before they call do_commit(). do_commit() is
there to commit simple picks without forking 'git commit'
quoted
So I suspect that this is an oversight, but perhaps somebody more
familiar with this code could confirm my thinking.
I hope the above helps - basically the idea is "if the commit has been
edited use VERIFY_MSG" and --continue unhelpfully uses a completely
different code-path to the main commit picking/reverting loop.
Makes sense, thanks.

Taylor

Re: git revert --continue --no-verify

From: Cameron Steffen <hidden>
Date: 2021-08-05 01:57:13

I've updated my mental model to include "--continue is a shortcut for
`git commit && ..`". That is a big help and resolves the issue for me
since I know I can always fall back to running `git commit` manually.
Thanks for all the replies!

Cameron
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help