chore: improvements
This commit is contained in:
parent
dace008122
commit
593901894e
|
@ -1,19 +1,46 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Set the commit hash to the latest commit if no argument is provided
|
||||
if [ -z "$1" ]
|
||||
# Function to handle Ctrl+C
|
||||
handle_sigint()
|
||||
{
|
||||
echo "Interrupt received. Exiting script..."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Trap SIGINT (Ctrl+C) and call handle_sigint()
|
||||
trap 'handle_sigint' INT
|
||||
|
||||
# Check if commit_hash.txt exists
|
||||
if [ -f commit_hash.txt ]
|
||||
then
|
||||
commit_hash=$(git rev-parse HEAD)
|
||||
else
|
||||
commit_hash=$1
|
||||
read -p "commit_hash.txt found. Do you want to use it (y/n)? " answer
|
||||
if [ "$answer" != "${answer#[Yy]}" ]
|
||||
then
|
||||
commit_hash=$(cat commit_hash.txt)
|
||||
fi
|
||||
fi
|
||||
|
||||
# If commit_hash is empty, ask the user for a commit hash
|
||||
if [ -z "$commit_hash" ]
|
||||
then
|
||||
read -p "Please enter a commit hash: " commit_hash
|
||||
fi
|
||||
|
||||
# If the commit hash is still empty (no input given), exit the script
|
||||
if [ -z "$commit_hash" ]
|
||||
then
|
||||
echo "No commit hash given. Exiting script..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
latest_commit_hash=$(git rev-parse HEAD)
|
||||
|
||||
# Get the diff and write it to diffs.txt
|
||||
git diff ${commit_hash}~1..${commit_hash} > diffs.txt
|
||||
git diff ${commit_hash}~1..${latest_commit_hash} > diffs.txt
|
||||
|
||||
# Always grab the latest commit hash and write to commit_hash.txt
|
||||
latest_commit_hash=$(git rev-parse HEAD)
|
||||
|
||||
echo ${latest_commit_hash} > commit_hash.txt
|
||||
|
||||
echo "Diffs and latest commit hash have been written to diffs.txt and commit_hash.txt, respectively."
|
||||
echo "git apply diffs.txt"
|
||||
echo "To apply the diffs, run: git apply diffs.txt"
|
||||
|
|
Loading…
Reference in New Issue