Skip to content

refresh: Support --diff with --edit #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion stgit/commands/refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
action='store_true',
short='Invoke an editor for the patch description',
),
opt(
'-d',
'--diff',
action='store_true',
short='Edit the patch diff if -e was set',
),
opt(
'-a',
'--annotate',
Expand Down Expand Up @@ -380,6 +386,7 @@ def __refresh(
include_submodules=False,
no_verify=False,
invoke_editor=False,
edit_diff=False,
):
stack = directory.repository.current_stack

Expand Down Expand Up @@ -455,7 +462,7 @@ def edit_fun(cd):
)
if invoke_editor:
cd, failed_diff = interactive_edit_patch(
stack.repository, cd, edit_diff=False, diff_flags=[]
stack.repository, cd, edit_diff=edit_diff, diff_flags=[]
)
assert not failed_diff
if not no_verify and (invoke_editor or cd.message != orig_msg):
Expand Down Expand Up @@ -522,4 +529,5 @@ def func(parser, options, args):
include_submodules=options.submodules,
no_verify=options.no_verify,
invoke_editor=options.edit,
edit_diff=options.diff,
)
18 changes: 18 additions & 0 deletions t/t7504-commit-msg-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,22 @@ test_expect_success "squash hook doesn't edit commit message (editor)" '
commit_msg_is "more plus"
'

write_script diffedit <<EOF
sed \
-e 's/old content/new content/' \
-e 's/old message/new message/' "\$1" > "\$1".tmp && mv "\$1".tmp "\$1"
exit 0
EOF
test_expect_success "refresh hook edits message and diff (editor)" '
stg new -m "old message" p1 &&
echo "old content" > file &&
stg add file &&
stg refresh -i &&
GIT_EDITOR=./diffedit stg refresh -d -e &&
git log --pretty=format:%s%b -1 &&
commit_msg_is "new message" &&
test "$(grep "new content" file)" = "new content"
'
rm -f diffedit

test_done