Skip to content

Commit

Permalink
reintegrate: learn --allow-empty
Browse files Browse the repository at this point in the history
I was initially torn about adding this flag, since it's just a
convoluted way to spell `git reset --hard master`. But in practice, time
and again I found myself annoyed at going "okay, time to reintegrate..."
then hitting a wall where I have to go "oh yeah, no actual branches,
guess I'll have to reset by hand". It's conceptually simpler to keep it
all in the same subcommand, and also not difficult to add, so may as
well toss it in there.

Fun side note: looking back at my code let me discover the dead
`in_progress()` function.
  • Loading branch information
ajvondrak committed Nov 29, 2018
1 parent 2912806 commit 99f9f36
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion completions/bash/git-topics
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ __git_topics_reintegrate() {
return
fi
case "$cur" in
--*) __gitcomp "--onto" ;;
--*) __gitcomp "--onto --allow-empty" ;;
*) __git_complete_refs ;;
esac
}
Expand Down
1 change: 1 addition & 0 deletions completions/zsh/_git-topics
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ __git_topics_list() {
__git_topics_reintegrate() {
_arguments -C -S -s \
"--onto=[merge topics onto this branch]:branches:__git_branches" \
"--allow-empty[do not abort due to empty todo list]" \
"--continue[continue after resolving a merge conflict]" \
"--skip[skip the current merge and continue]" \
"--abort[abort and reset the original branch]" \
Expand Down
26 changes: 14 additions & 12 deletions libexec/lib/reintegrate
Original file line number Diff line number Diff line change
Expand Up @@ -173,29 +173,26 @@ if test -d "$state"; then
OPTIONS="(--continue | --skip | --abort | --quit | --edit-todo)"
else
in_progress=
OPTIONS="[--onto <branch>]"
OPTIONS="[--onto <branch>] [--allow-empty]"
fi

OPTIONS_SPEC="\
$dashless $command [--onto <branch>]
$dashless $command [--onto <branch>] [--allow-empty]
$dashless $command (--continue | --skip | --abort | --quit | --edit-todo)
--
Options
onto=! merge topics onto this branch (default: $DEVELOP)
onto=! merge topics onto this branch (default: $DEVELOP)
allow-empty! do not abort due to empty todo list
Actions
continue! continue after resolving a merge conflict
skip! skip the current merge and continue
abort! abort and reset the original branch
quit! abort but keep the branch where it is
edit-todo! edit the todo list
continue! continue after resolving a merge conflict
skip! skip the current merge and continue
abort! abort and reset the original branch
quit! abort but keep the branch where it is
edit-todo! edit the todo list
"

eval "$(parsed_options "$@")"

in_progress() {
test -n "$in_progress"
}

assert_in_progress() {
test -n "$in_progress" || {
echo >&2 "There doesn't appear to be a reintegration in progress. Try"
Expand Down Expand Up @@ -242,6 +239,11 @@ while test -n "$1"; do
branch="${1##--onto=}"
shift
;;
--allow-empty)
refute_in_progress
allow_empty="true"
shift
;;
--)
shift
;;
Expand Down
13 changes: 11 additions & 2 deletions libexec/lib/reintegrate--onto
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@ echo "$(
sed "s/^- /drop /"
)" >"$todo"

EXTRA_INSTRUCTIONS="
if test -z "$allow_empty"; then
EXTRA_INSTRUCTIONS="
If you drop every line, the reintegration will be aborted without any effect on
the $branch branch.
"
else
EXTRA_INSTRUCTIONS="
If you drop every line, the reintegration will still rewind the $branch branch,
making it even with the $MASTER branch.
"
fi

edit_todo

test -s "$todo" || finished "Reintegration aborted due to empty todo list"
if test -z "$allow_empty"; then
test -s "$todo" || finished "Reintegration aborted due to empty todo list"
fi

git checkout --quiet "$branch" || exit "$?"
ensure_correct_branch
Expand Down
15 changes: 12 additions & 3 deletions ronn/git-topics-reintegrate.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## SYNOPSIS

`git topics reintegrate` [--onto <branch>]
`git topics reintegrate` [--onto <branch>] [--allow-empty]

`git topics reintegrate` (--continue | --skip | --abort | --quit | --edit-todo)

Expand Down Expand Up @@ -50,15 +50,24 @@ created and based off of _master_.

Merge conflicts and other errors might interrupt the execution of the todo
list. When this happens, it's your responsibility to resolve the issue and
resume the reintegration using the "action" flags of this command (i.e., any
option other than `--onto`).
resume the reintegration using the flags listed in the [ACTIONS][] section
below.

## OPTIONS

* --onto <branch>:
Reintegrate topics onto the specified branch. If not supplied, the target
branch will default to _develop_.

* --allow-empty:
Normally, you can abort a reintegration by saving an empty todo list (whether
literally empty or containing nothing but `drop` instructions). However, if
you give this option, the reintegration will still run without re-merging any
topics. Effectively, this is equivalent to just doing `git reset --hard
<master>` by hand.

## ACTIONS

* --continue:
Resumes executing the todo list after you've resolved a merge conflict.

Expand Down

0 comments on commit 99f9f36

Please sign in to comment.