git-compose can now be cancelled with :q! in neovim
This commit is contained in:
@@ -6,6 +6,8 @@ pkgs.writeShellApplication {
|
||||
gawk
|
||||
];
|
||||
text = ''
|
||||
set -e
|
||||
|
||||
toplevel=$(git rev-parse --show-toplevel 2>/dev/null)
|
||||
|
||||
if [ -z "$toplevel" ]; then
|
||||
@@ -16,7 +18,6 @@ pkgs.writeShellApplication {
|
||||
(
|
||||
cd "$toplevel" || { echo "Failed to change to repo root"; exit 1; }
|
||||
|
||||
git reset > /dev/null 2>&1
|
||||
unstaged=$(git status --porcelain | awk '{print $2}') || { echo "Failed to get git status"; exit 1; }
|
||||
|
||||
if [ -z "$unstaged" ]; then
|
||||
@@ -24,11 +25,14 @@ pkgs.writeShellApplication {
|
||||
exit 0
|
||||
fi
|
||||
|
||||
git reset > /dev/null 2>&1
|
||||
|
||||
tmpfile=$(mktemp) || { echo "Failed to create a temporary file"; exit 1; }
|
||||
trap 'rm -f "$tmpfile"' EXIT
|
||||
|
||||
{
|
||||
filecontent=$(
|
||||
echo "# Compose your commits here"
|
||||
echo "# To cancel this operation, exit without saving (e.g., :q!)"
|
||||
echo "#"
|
||||
echo "# Format should be as follows:"
|
||||
echo "# <some_commit_message>"
|
||||
@@ -41,10 +45,16 @@ pkgs.writeShellApplication {
|
||||
echo "# using the given commit message at the top of the group"
|
||||
echo
|
||||
echo "$unstaged"
|
||||
} >> "$tmpfile"
|
||||
)
|
||||
echo "$filecontent" > "$tmpfile"
|
||||
|
||||
nvim -c 'setfiletype gitcommit' "$tmpfile"
|
||||
|
||||
if [ "$(cat "$tmpfile")" = "$filecontent" ]; then
|
||||
echo "No changes found; cancelling composition."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
collecting=false
|
||||
msg=""
|
||||
lines=()
|
||||
@@ -63,14 +73,14 @@ pkgs.writeShellApplication {
|
||||
collecting=true
|
||||
msg="$line"
|
||||
else
|
||||
lines+=("$line")
|
||||
lines+=("./$line")
|
||||
fi
|
||||
done < "$tmpfile"
|
||||
|
||||
# Final cleanup
|
||||
if [ -n "$msg" ] && [ ''${#lines[@]} -gt 0 ]; then
|
||||
git add "''${lines[@]}"
|
||||
git commit -m "$msg"
|
||||
git add "''${lines[@]}"
|
||||
git commit -m "$msg"
|
||||
fi
|
||||
)
|
||||
'';
|
||||
|
||||
Reference in New Issue
Block a user