Skip to content

Commit

Permalink
Prevent git-cleave from destroying empty commits -- keep 'em!
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Jul 19, 2023
1 parent 1fcd2f8 commit 0c25bc4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions git-cleave
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ main () {

LAST_COMMIT_MSG="$(git log --pretty='%s' -1)"
git reset HEAD~1
BASE_SHA="$(git sha HEAD)"

for expr in "$@"; do
locally_changed_files | grep -Ee "$expr" | while read f; do
Expand Down Expand Up @@ -72,9 +73,11 @@ main () {
git add "$f"
done

if git is-dirty -i; then
git commit --no-verify -C "$ORIG_SHA"
git commit --amend --no-verify -m "$LAST_COMMIT_MSG"
# If there are leftover changes (or cleave didn't commit anything yet, in the
# case of an empty original commit), commit it now
if git is-dirty -i || [ "$BASE_SHA" = "$(git sha HEAD)" ]; then
git commit --allow-empty --no-verify -C "$ORIG_SHA"
git commit --allow-empty --amend --no-verify -m "$LAST_COMMIT_MSG"
fi

# Sanity check. No files may get lost during this process!
Expand Down

0 comments on commit 0c25bc4

Please sign in to comment.