Skip to content

Instantly share code, notes, and snippets.

@jonfazzaro
Created September 10, 2024 13:37
Show Gist options
  • Save jonfazzaro/a86ab5bd08285c3fde0b0bb52f6075cf to your computer and use it in GitHub Desktop.
Save jonfazzaro/a86ab5bd08285c3fde0b0bb52f6075cf to your computer and use it in GitHub Desktop.
A git script for quick continuous integration in an ensemble.
#!/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
@jonfazzaro
Copy link
Author

Hat tip to @KodyFintak for the git_next part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment