Last active
October 5, 2022 05:35
-
-
Save tcard/b35eb6759dd3253aab94f62728234873 to your computer and use it in GitHub Desktop.
Daily Git commit cronjob
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
#!/usr/bin/env bash | |
set -euo pipefail | |
function dirty { | |
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working tree clean" ]] && echo " (dirty)" | |
} | |
current_branch="$(git rev-parse --abbrev-ref HEAD)" | |
git add . # TODO: Save and then restore stage state | |
description="$(date +'%F %T') $current_branch$(dirty): $(git show -s --format='%h %s')" | |
git commit --allow-empty -m "$description" | |
git checkout -b daily || ( | |
git checkout daily | |
( | |
(git diff daily "$current_branch" | git apply) && | |
(git add . && git commit -m "$description") | |
) || true | |
) | |
git checkout "$current_branch" | |
git reset --soft HEAD~1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment