Created
September 10, 2024 13:37
-
-
Save jonfazzaro/a86ab5bd08285c3fde0b0bb52f6075cf to your computer and use it in GitHub Desktop.
A git script for quick continuous integration in an ensemble.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MESSAGE=$1 | |
pushd () { | |
command pushd "$@" > /dev/null | |
} | |
popd () { | |
command popd "$@" > /dev/null | |
} | |
git_root () { | |
echo "$(git rev-parse --show-toplevel)" | |
} | |
has_changes () { | |
$(git diff-index --quiet HEAD) && return 1 || return 0 | |
} | |
commit_message () { | |
local message | |
if [ -z "$MESSAGE" ]; then | |
read -rp "Commit message? " message | |
else | |
message="$MESSAGE" | |
fi | |
echo "$message" | |
} | |
git_commit() { | |
git add -A && git commit -m "$(commit_message)" | |
} | |
git_push() { | |
git push && git_next | |
} | |
git_next() { | |
git log --since='1 day ago' --format='%at %an' | sort -n -r | awk '!seen[$2]++ {print $2}' | |
} | |
pushd $(git_root) || exit | |
if $(has_changes); then | |
git_commit | |
fi | |
git_push | |
popd || exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hat tip to @KodyFintak for the
git_next
part.