Created
March 14, 2024 08:33
-
-
Save seungjin/b347f88006e3ce1398af5dba43b1389f to your computer and use it in GitHub Desktop.
git autosave
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
autosave = "!f () { \ | |
origin=$(git remote) ; \ | |
project_name=$(git remote get-url $origin | xargs basename -s .git) ; \ | |
current_branch=$(git rev-parse --abbrev-ref HEAD) ; \ | |
gsm=$(git status) ; \ | |
ntc=$(echo $gsm | grep \"nothing to commit, working tree clean\" | wc -l) ; \ | |
ybi=$(echo $gsm | grep \"Your branch is ahead of '$origin/$current_branch' by\" | wc -l) ; \ | |
ybi2=$(echo $gsm | grep \"Your branch is ahead of '$origin/main' by\" | wc -l) ; \ | |
if [ $ntc -ne 1 ] || ([ $ybi -ne 1 ] && [ $ybi2 -ne 0 ]); then\ | |
echo \"πΎ Autosaving...\" ; \ | |
new_branch_name=\"$USER/autosave/`hostname`@`date +'%Y-%m-%dT%H.%M.%S%z'`\" ; \ | |
commit_msg=$(git diff | OPENAI_TEMPERATURE=0.4 OPENAI_PROMPT_TEXT=\"Generate a Git commit message based on the following diff\" OPENAI_MODEL_NAME=gpt-3.5-turbo ask_openai); \ | |
echo -e \"\\n\\e[1;32mMachine generated commit message:\"; \ | |
echo $commit_msg; \ | |
echo -e \"\\033[m\"; \ | |
git add -A; git commit -m \"(Autocommit) `whoami`@`hostname` \n$commit_msg \" ; \ | |
git push \ | |
-o merge_request.create \ | |
-o merge_request.remove_source_branch \ | |
-o merge_request.title=\"$project_name π Please merge for $new_branch_name π\" \ | |
-o merge_request.description=\"Automated MR by [git.aliases](https://codeberg.org/seungjin/_home.d/src/branch/main/.gitconfig)\" \ | |
-o merge_request.labe=\"autosave\" \ | |
$origin $current_branch:$new_branch_name; \ | |
if [ $? -eq 0 ]; then\ | |
echo \"β΅ Autosaving done.\"; \ | |
else \ | |
echo \"π₯ Autosaving failed. \"; \ | |
fi \ | |
else \ | |
echo \"π₯£ Nothing to autosave.\" ; \ | |
fi;\ | |
git fetch --all; \ | |
}; \ | |
f; \ | |
unset -f f" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment