Skip to content

Instantly share code, notes, and snippets.

@leonhfr
Created November 16, 2020 22:42
Show Gist options
  • Save leonhfr/6ada4b71d15346d0a771d009ef580c27 to your computer and use it in GitHub Desktop.
Save leonhfr/6ada4b71d15346d0a771d009ef580c27 to your computer and use it in GitHub Desktop.
Foam commit
#!/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
@leonhfr
Copy link
Author

leonhfr commented Nov 17, 2020

With cfoam in your $PATH, this script:

  • commits all change with the date of the day (2020-11-16) as a commit message
  • push the commit to master, or amend the daily one if already created

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