Skip to content

Commit

Permalink
Merge branch 'describe-with-content-diff'
Browse files Browse the repository at this point in the history
* Branch commit log:
  jj-fzf: commit: --message fixup
  jj-fzf: echo_commit_msg: skip signoff if no files changed
  jj-fzf: add ui.default-description to commit messages
  jj-fzf: use JJ_EDITOR to really override th JJ editor settings
  jj-fzf: honor the JJ_EDITOR precedence
	The JJ docs describe the precedence:
	$JJ_EDITOR > ui.editor > $VISUAL > $EDITOR > pico
	https://jj-vcs.github.io/jj/latest/config/#editor
  jj-fzf: show content diff when editing commit message
	Show the first few thausand lines of the content diff during
	commit message creation, inspired by git commit --verbose

Signed-off-by: Tim Janik <[email protected]>
  • Loading branch information
tim-janik committed Dec 22, 2024
2 parents 392453e + eb77b16 commit 4e996bd
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions jj-fzf
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ echo_commit_msg()
gsed '/^\([A-Z][a-z0-9-]*-by\|Cc\):/d' | # strip Signed-off-by:
gsed '/^$/d ; s/^/\t/ ; s/^\t\f$/ (no description)/ ; s/^\t\f/ /'
done
echo_signoff
else # Commit message based on files
# start with file name prefixes
cd "$JJROOT" # create root relative file names
Expand All @@ -379,25 +380,40 @@ echo_commit_msg()
test ${#FILES[@]} -gt 0 &&
printf "%s: \n" "${FILES[@]}" ||
echo ""
jj config --no-pager get 'ui.default-description' 2>/dev/null || :
test ${#FILES[@]} -le 0 ||
echo_signoff
fi
# ensure signoff
echo_signoff
)
# Run user editor: user_editor_on_var <FILE> <VARIABLE>
# Run user editor: user_editor_on_var <FILE> <VARIABLE> [COMMIT]
user_editor_on_var()
{
local FILE="$1" N=
local FILE="$1" COMMIT="${3:-}" N=
declare -n _ueovMSG="$2" # <VARIABLE> alias
# create msg file
temp_dir
local TEMPFILE="$TEMPD/$FILE"
cat >"$TEMPFILE" <<<"$_ueovMSG"
test -z "$COMMIT" || {
jj diff --ignore-working-copy --no-pager --color=never -r "$COMMIT" |
head -n 4000 > "$TEMPFILE.diff"
test -s "$TEMPFILE.diff" && {
echo
echo '# -------- >8 -------- >8 -------- 8< -------- 8< --------'
echo '# Everything below the snippet mark will be ignored'
echo '#'
echo '# Content diff of this revision:'
cat "$TEMPFILE.diff"
}
rm -f "$TEMPFILE.diff"
} >> "$TEMPFILE"
# edit commit msg
JJ_EDITOR="$(jj config get ui.editor 2>/dev/null || echo "${EDITOR:-pico}")"
test -n "${JJ_EDITOR:-}" || # https://jj-vcs.github.io/jj/latest/config/#editor
JJ_EDITOR="$(jj config get ui.editor 2>/dev/null || echo "${VISUAL:-${EDITOR:-pico}}")"
$JJ_EDITOR "$TEMPFILE" &&
N="$(cat "$TEMPFILE")" && {
test "$_ueovMSG" != "$N" &&
_ueovMSG="$(cat "$TEMPFILE")"
_ueovMSG="$(gsed -r '/^# -+ >8 -+ >8 -+ 8< -+ 8< -+/Q' < "$TEMPFILE")"
rm -f "$TEMPFILE"
return 0
}
Expand Down Expand Up @@ -547,20 +563,20 @@ commit()
MSG="$(echo_commit_msg "$R")"
O="$MSG"
if test "$R" == "$W" -a "$IMMU" != true ; then
user_editor_on_var "COMMIT-$R.txt" MSG &&
user_editor_on_var "COMMIT-$R.txt" MSG "$R" &&
test "$O" != "$MSG" ||
ERROR "Commit cancelled by user"
( set -x
jj commit -m "$MSG"
jj commit --message="$MSG"
) || sleep 1
else # R is @ and mutable
else # R is not @, may be immutable
[[ $IMMU =~ ^true ]] || {
user_editor_on_var "COMMIT-$R.txt" MSG &&
user_editor_on_var "COMMIT-$R.txt" MSG "$R" &&
test "$O" != "$MSG" ||
ERROR "Commit cancelled by user"
test "$O" != "$MSG" &&
( set -x
jj describe --no-edit -r "$R" -m "$MSG"
jj describe --no-edit -r "$R" --message="$MSG"
) || sleep 1
}
# open new empty working copy commit
Expand Down Expand Up @@ -638,7 +654,7 @@ describe()
R="$(xrev_or_commit "${1:-@}")"
MSG="$(echo_commit_msg "$R")"
O="$MSG"
user_editor_on_var "CHANGE-$R.txt" MSG ||
user_editor_on_var "CHANGE-$R.txt" MSG "$R" ||
ERROR "Describe cancelled by user"
test "$O" != "$MSG" ||
return
Expand Down Expand Up @@ -684,8 +700,7 @@ DOC['split-interactive']='Use `jj split` to interactively select content diff hu
split-interactive()
(
R="$(xrev "${1:-@}")"
# Override ui.editor to implement --split-with-no-description: truncate the first
# (original) description, then keep the other description for subsequent edits
# To avoid message editing, truncate all but the first (original) description
temp_dir
cat > $TEMPD/noeditor <<-\__EOF__
#!/usr/bin/env bash
Expand All @@ -695,8 +710,9 @@ split-interactive()
gsed 's/TRUNCATE=./TRUNCATE=y/' -i "$0"
__EOF__
chmod +x $TEMPD/noeditor
export JJ_EDITOR="$TEMPD/noeditor" # Override ui.editor to implement --split-with-no-description
( set -x
jj split --interactive -r "$R" --config-toml "ui.editor='$TEMPD/noeditor'"
jj split --interactive -r "$R"
) || ERROR
)
KEYBINDINGS["Alt-I"]="split-interactive"
Expand Down Expand Up @@ -1034,9 +1050,9 @@ split-files()
# create n-1 new commits from n files
while [[ ${#MAPFILE[@]} -gt 1 ]] ; do
unset 'MAPFILE[-1]' # unset 'MAPFILE[${#MAPFILE[@]}-1]'
# Override ui.editor to implement --split-with-no-description
export JJ_EDITOR='true' # Override ui.editor to implement --split-with-no-description
( set -x
jj split --config-toml 'ui.editor="true"' -r "$R" -- "${MAPFILE[@]}"
jj split -r "$R" -- "${MAPFILE[@]}"
) || ERROR
done
)
Expand Down Expand Up @@ -1346,10 +1362,10 @@ vivifydivergent()
test "$COMMIT" == "$WCOPY" && NOEDIT= || NOEDIT=--no-edit
echo "# $SELF vivifydivergent $COMMIT" >&2
jj --no-pager log --no-graph -T builtin_log_oneline -r "$COMMIT" # --ignore-working-copy
# Override ui.editor to implement --squash-with-no-description
export JJ_EDITOR='true' # Override ui.editor to implement --squash-with-no-description
( set -x
jj new --insert-after "$COMMIT" $NOEDIT
jj squash --from "$COMMIT" --into "$COMMIT+" --config-toml 'ui.editor="true"'
jj squash --from "$COMMIT" --into "$COMMIT+"
) || ERROR
)
KEYBINDINGS["Alt-V"]="vivifydivergent" NEXTS="$NEXTS vivifydivergent"
Expand Down

0 comments on commit 4e996bd

Please sign in to comment.