Created
November 16, 2020 22:42
-
-
Save leonhfr/6ada4b71d15346d0a771d009ef580c27 to your computer and use it in GitHub Desktop.
Foam commit
This file contains hidden or 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 | |
INSIDE_GIT_REPO="$(git rev-parse --is-inside-work-tree 2>/dev/null)" | |
TODAY="$(date +'%Y-%m-%d')" | |
if [ ! "$INSIDE_GIT_REPO" ]; then | |
echo "Not in a git repository." | |
exit 1 | |
fi | |
GIT_STATUS="$(git status --porcelain)" | |
GIT_LAST_COMMIT="$(git log -1 --pretty=%B)" | |
if [ -z "$GIT_STATUS" ]; then | |
# Working directory clean | |
echo "Nothing to commit." | |
exit 0 | |
fi | |
if [ "$GIT_LAST_COMMIT" == "$TODAY" ]; then | |
# We already have a commit for today | |
git add . | |
GIT_COMMIT="$(git commit --amend --no-edit)" | |
echo "$GIT_COMMIT" | |
git push origin master -f | |
else | |
# There is no commit for today | |
git add . | |
GIT_COMMIT="$(git commit -m $TODAY)" | |
echo "$GIT_COMMIT" | |
git push origin master | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With
cfoam
in your$PATH
, this script:2020-11-16
) as a commit message