Skip to content

Commit c258dd5

Browse files
committed
lib/rebase.sh: add word-level merging for fine-grained conflict resolution
Signed-off-by: Tim Janik <timj@gnu.org>
1 parent 117eb0b commit c258dd5

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/rebase.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ echo 'CH=' >> $JJFZF_TEMPD/rebase.env
2727
echo 'TO=--destination' >> $JJFZF_TEMPD/rebase.env
2828
echo 'SP=false' >> $JJFZF_TEMPD/rebase.env
2929
echo 'II=' >> $JJFZF_TEMPD/rebase.env
30+
echo 'WORDS=' >> $JJFZF_TEMPD/rebase.env
3031
if [[ $JJFZF_CREVS =~ \| ]] ; then
3132
echo 'FR=--revisions' >> $JJFZF_TEMPD/rebase.env # multi revs
3233
else
@@ -61,15 +62,18 @@ B+=( --bind "alt-p:execute-silent( sed 's/^SP=false/SP=x/; s/^SP=true/SP=false/;
6162
H+=( 'Alt-I: Ignore-Immutable permits rebasing immutable commits' )
6263
B+=( --bind "alt-i:execute-silent( sed 's/^II=-.*/II=x/; s/^II=$/II=--ignore-immutable/; s/^II=x.*/II=/' -i $JJFZF_TEMPD/rebase.env )+refresh-preview" )
6364

64-
H+=( "Ctrl-D: Destination — pick the target to rebase onto" )
65-
B+=( --bind "ctrl-d:execute-silent( sed 's/^TO=.*/TO=--destination/' -i $JJFZF_TEMPD/rebase.env )+refresh-preview" )
66-
6765
H+=( "Ctrl-A: After — pick the target to insert after" )
6866
B+=( --bind "ctrl-a:execute-silent( sed 's/^TO=.*/TO=--insert-after/' -i $JJFZF_TEMPD/rebase.env )+refresh-preview" )
6967

7068
H+=( "Ctrl-B: Before — pick the target to insert before" )
7169
B+=( --bind "ctrl-b:execute-silent( sed 's/^TO=.*/TO=--insert-before/' -i $JJFZF_TEMPD/rebase.env )+refresh-preview" )
7270

71+
H+=( "Ctrl-D: Destination — pick the target to rebase onto" )
72+
B+=( --bind "ctrl-d:execute-silent( sed 's/^TO=.*/TO=--destination/' -i $JJFZF_TEMPD/rebase.env )+refresh-preview" )
73+
74+
H+=( "Ctrl-W: Word-level merging — merge words not lines" )
75+
B+=( --bind "ctrl-w:execute-silent( sed 's/^WORDS=-.*/WORDS=x/; s/^WORDS=$/WORDS=--config=merge.hunk-level=word/; s/^WORDS=x.*/WORDS=/' -i $JJFZF_TEMPD/rebase.env )+refresh-preview" )
76+
7377
# == Header Help ==
7478
HEADER_HELP=$(printf "%s\n" "${H[@]}" | jjfzf_bold_keys)
7579
B+=( --header "$HEADER_HELP" )
@@ -83,9 +87,9 @@ jjfzf_rebase_enter()
8387
source $JJFZF_TEMPD/rebase.env
8488
# duplicate revisions
8589
if test -n "$DP" ; then
86-
jjfzf_run +n jj duplicate $II $TO "$TARGET" -r "$JJFZF_CREVS$CH"
90+
jjfzf_run +n jj duplicate $II $TO "$TARGET" -r "$JJFZF_CREVS$CH" $WORDS
8791
else # rebase revisions
88-
jjfzf_run +n jj rebase $II $TO "$TARGET" $FR "$JJFZF_CREVS"
92+
jjfzf_run +n jj rebase $II $TO "$TARGET" $FR "$JJFZF_CREVS" $WORDS
8993
fi
9094
# simplify-parents
9195
if $SP; then
@@ -105,9 +109,9 @@ jjfzf_rebase_plan()
105109
source $JJFZF_TEMPD/rebase.env
106110
echo
107111
test -z "$DP" ||
108-
echo "jj duplicate $II $TO $TARGET -r '$JJFZF_CREVS'$CH"
112+
echo "jj duplicate $II $TO $TARGET -r '$JJFZF_CREVS'$CH" $WORDS
109113
test -n "$DP" ||
110-
echo "jj rebase $II $TO $TARGET $FR '$JJFZF_CREVS'"
114+
echo "jj rebase $II $TO $TARGET $FR '$JJFZF_CREVS'" $WORDS
111115
echo
112116
test $SP == true &&
113117
echo "jj simplify-parents -r '$JJFZF_CREVS'"

0 commit comments

Comments
 (0)