From: Andrei Rybak <hidden> Date: 2019-11-14 16:35:55
I've wanted this feature for a long time, and now with rebase working without
forking rebase--interactive (thanks to Phillip Wood for working on that), I
finally got around to implementing it.
It still needs validation for arguments. Right now, I have two ideas:
1. iterate over original argv and make sure its just '--exec's with its
arguments.
2. check all other vars in options[].
Andrei Rybak (3):
rebase: prepare cmd before choosing action
rebase: extract add_exec()
rebase -i: allow --edit-todo with --exec
Documentation/git-rebase.txt | 3 +-
builtin/rebase.c | 63 ++++++++++++++++++++++-------------
t/t3404-rebase-interactive.sh | 32 ++++++++++++++++++
3 files changed, 74 insertions(+), 24 deletions(-)
--
2.24.0.windows.2
From: Andrei Rybak <hidden> Date: 2019-11-14 16:35:57
When git rebase is started with option --exec, its arguments are parsed
into string_list exec and then converted into options.cmd.
In following commits, action --edit-todo will be taught to use arguments
passed with --exec option. Prepare options.cmd before switch (action)
to make it available for the ACTION_EDIT_TODO branch of the switch.
Signed-off-by: Andrei Rybak <redacted>
---
builtin/rebase.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
From: Andrei Rybak <hidden> Date: 2019-11-14 16:35:58
In following commit addition of commands to the todo file will be
implemented for the --edit-todo action. So extract a function to avoid
duplicating the code for splitting of opts->cmd into list of commands.
Signed-off-by: Andrei Rybak <redacted>
---
builtin/rebase.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
From: Andrei Rybak <hidden> Date: 2019-11-14 16:36:01
When using rebase, option --exec can be used, for example, to run tests
after every commit created by rebase. When using interactive rebase, I
don't always know, if I would want to run something against each commit
before I start rebasing. Sometimes, I realize this only after doing
some editing in the middle of the rebase. To do that, I have to
manually edit the todo file. Additing exec command by hand or
semi-automatically is cumbersome and error prone. Especially if the
file is big or complex, e.g. when option --rebase-merges is used.
Allow using the --edit-todo action of git rebase with option --exec.
New test is based on test 'rebase --edit-todo can be used to modify
todo'. Contents of todo file are checked using set_cat_todo_editor
similarly to what test 'respects rebase.abbreviateCommands with fixup,
squash and exec' does.
Remove unnecessary braces around call to usage_with_options, while we're
here.
TODO: Still need better validation of options. With current
implementation, the following is not rejected:
git rebase --edit-todo -x 'git show HEAD' --autostash
Signed-off-by: Andrei Rybak <redacted>
---
Documentation/git-rebase.txt | 3 ++-
builtin/rebase.c | 16 +++++++++++++---
t/t3404-rebase-interactive.sh | 32 ++++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+), 4 deletions(-)
@@ -1082,6 +1082,38 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' 'testL=$(gitcat-filecommitHEAD|sed-ne\$p)'+test_expect_success'rebase --edit-todo can be used with -x''+test_when_finished"reset_rebase"&&+gitreset--hard&&+gitcheckoutno-conflict-branch^0&&+cat>expected<<-EOF&&+pick$(gitrev-list--abbrev-commit-1HEAD^)L+execgitshowHEAD+pick$(gitrev-list--abbrev-commit-1HEAD)M+execgitshowHEAD+EOF+set_fake_editor&&+FAKE_LINES="1 edit 2 3 4"gitrebase-iHEAD~4&&+set_cat_todo_editor&&+test_must_failgitrebase--edit-todo-x"git show HEAD">actual&&+test_cmpexpectedactual+'++test_expect_failure'rebase --edit-todo -x does not allow other arguments''+test_when_finished"reset_rebase"&&+gitreset--hard&&+gitcheckoutno-conflict-branch^0&&+cat>expected<<-EOF&&+pick$(gitrev-list--abbrev-commit-1HEAD^)L+execgitshowHEAD+pick$(gitrev-list--abbrev-commit-1HEAD)M+execgitshowHEAD+EOF+set_fake_editor&&+FAKE_LINES="1 edit 2 3 4"gitrebase-iHEAD~4&&+test_must_failgitrebase--edit-todo-x"git show HEAD"--autostash+'+ test_expect_success'rebase -i produces readable reflog''gitreset--hard&&gitbranch-fbranch-reflog-testH&&
From: Andrei Rybak <hidden> Date: 2019-11-20 09:52:46
Variable "int i" is already defined at the top of the function
cmd_rebase, so reuse it instead of declaring other variables, which mask
the outer "i".
Signed-off-by: Andrei Rybak <redacted>
---
builtin/rebase.c | 4 ----
1 file changed, 4 deletions(-)
From: Andrei Rybak <hidden> Date: 2019-11-20 09:52:47
When git rebase is started with option --exec, its arguments are parsed
into string_list exec and then converted into options.cmd.
In following commits, action --edit-todo will be taught to use arguments
passed with --exec option. Prepare options.cmd before switch (action)
to make it available for the ACTION_EDIT_TODO branch of the switch.
Signed-off-by: Andrei Rybak <redacted>
---
builtin/rebase.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
From: Andrei Rybak <hidden> Date: 2019-11-20 09:52:47
Differences from v1:
- Added missing RFC marker.
- Fixed CC list.
- Addressed Junio's comment about masked variable in a for loop: another
preparatory patch is added.
- Cleaned up copy-pasted unused code in the new test.
----
Original cover letter:
I've wanted this feature for a long time, and now with rebase working without
forking rebase--interactive (thanks to Phillip Wood for working on that), I
finally got around to implementing it.
It still needs validation for arguments. Right now, I have two ideas:
1. iterate over original argv and make sure its just '--exec's with its
arguments.
2. check all other vars in options[].
Andrei Rybak (4):
builtin/rebase.c: reuse loop variable
rebase: prepare cmd before choosing action
rebase: extract add_exec()
rebase -i: allow --edit-todo with --exec
Documentation/git-rebase.txt | 3 +-
builtin/rebase.c | 63 +++++++++++++++++++++--------------
t/t3404-rebase-interactive.sh | 32 ++++++++++++++++++
3 files changed, 72 insertions(+), 26 deletions(-)
--
2.24.0.windows.2
From: Andrei Rybak <hidden> Date: 2019-11-20 09:52:50
In following commit addition of commands to the todo file will be
implemented for the --edit-todo action. So extract a function to avoid
duplicating the code for splitting of opts->cmd into list of commands.
Signed-off-by: Andrei Rybak <redacted>
---
builtin/rebase.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
From: Andrei Rybak <hidden> Date: 2019-11-20 09:52:51
When using rebase, option --exec can be used, for example, to run tests
after every commit created by rebase. When using interactive rebase, I
don't always know, if I would want to run something against each commit
before I start rebasing. Sometimes, I realize this only after doing
some editing in the middle of the rebase. To do that, I have to
manually edit the todo file. Additing exec command by hand or
semi-automatically is cumbersome and error prone. Especially if the
file is big or complex, e.g. when option --rebase-merges is used.
Allow using the --edit-todo action of git rebase with option --exec.
New test is based on test 'rebase --edit-todo can be used to modify
todo'. Contents of todo file are checked using set_cat_todo_editor
similarly to what test 'respects rebase.abbreviateCommands with fixup,
squash and exec' does.
Remove unnecessary braces around call to usage_with_options, while we're
here.
TODO: Still need better validation of options. With current
implementation, the following is not rejected:
git rebase --edit-todo -x 'git show HEAD' --autostash
Signed-off-by: Andrei Rybak <redacted>
---
Documentation/git-rebase.txt | 3 ++-
builtin/rebase.c | 16 +++++++++++++---
t/t3404-rebase-interactive.sh | 26 ++++++++++++++++++++++++++
3 files changed, 41 insertions(+), 4 deletions(-)
@@ -1082,6 +1082,32 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' 'testL=$(gitcat-filecommitHEAD|sed-ne\$p)'+test_expect_success'rebase --edit-todo can be used with -x''+test_when_finished"reset_rebase"&&+gitreset--hard&&+gitcheckoutno-conflict-branch^0&&+cat>expected<<-EOF&&+pick$(gitrev-list--abbrev-commit-1HEAD^)L+execgitshowHEAD+pick$(gitrev-list--abbrev-commit-1HEAD)M+execgitshowHEAD+EOF+set_fake_editor&&+FAKE_LINES="1 edit 2 3 4"gitrebase-iHEAD~4&&+set_cat_todo_editor&&+test_must_failgitrebase--edit-todo-x"git show HEAD">actual&&+test_cmpexpectedactual+'++test_expect_failure'rebase --edit-todo -x does not allow other arguments''+test_when_finished"reset_rebase"&&+gitreset--hard&&+gitcheckoutno-conflict-branch^0&&+set_fake_editor&&+FAKE_LINES="1 edit 2 3 4"gitrebase-iHEAD~4&&+test_must_failgitrebase--edit-todo-x"git show HEAD"--autostash+'+ test_expect_success'rebase -i produces readable reflog''gitreset--hard&&gitbranch-fbranch-reflog-testH&&