Skip to content

Commit

Permalink
Add cmd-all-commits.sh
Browse files Browse the repository at this point in the history
A script to rebase onto a commit, and run a command on each commit until reaching the tip.

Any files that get created as a result of the command will be added as fixup! commits.
  • Loading branch information
Jon-edge committed Nov 17, 2023
1 parent 0ea6c7e commit bff6669
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions scripts/cmd-all-commits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Check if enough arguments are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 \"<command-to-run>\" <commit-hash>"
exit 1
fi

COMMAND_TO_RUN="$1"
TARGET_COMMIT="$2"

# Start the interactive rebase with an inline function definition
GIT_SEQUENCE_EDITOR=: git rebase -i --exec "bash -c ' \
COMMAND_TO_RUN=\"$COMMAND_TO_RUN\"; \
run_command_and_check() { \
eval \"\$COMMAND_TO_RUN\"; \
COMMAND_EXIT_STATUS=\$?; \
if [ \$COMMAND_EXIT_STATUS -ne 0 ]; then \
echo \"Command failed with exit status \$COMMAND_EXIT_STATUS\"; \
exit \$COMMAND_EXIT_STATUS; \
fi; \
if [ -n \"\$(git status --porcelain)\" ]; then \
git add .; \
git commit --fixup HEAD; \
fi; \
}; \
run_command_and_check' \
" $TARGET_COMMIT

if [ $? -ne 0 ]; then
echo "Rebase encountered an error. Resolve conflicts/errors and continue with 'git rebase --continue'."
exit 1
fi

echo "Rebase completed successfully."

0 comments on commit bff6669

Please sign in to comment.