further work on git auto save

This commit is contained in:
2021-05-03 20:42:08 +02:00
parent 3996045f93
commit c636635998
3 changed files with 43 additions and 14 deletions
+41 -11
View File
@@ -15,6 +15,20 @@ function get_current_branch {
echo $(git branch | grep "*" | awk '{print $NF}') echo $(git branch | grep "*" | awk '{print $NF}')
} }
function get_auto_save_branches {
auto_save_branches_raw=`git branch | grep "git_auto_save" | tail -1 | awk '{print $FN}'`
auto_save_branches=()
for i in "${$auto_save_branches_raw[@]}"
do
echo ${git_auto_save_branches_raw[i]}
#auto_save_branches+=${git_auto_save[i]}
done
echo $auto_save_branches
}
function git_auto_save { function git_auto_save {
if [[ $(is_git ".") -ne 0 ]]; then if [[ $(is_git ".") -ne 0 ]]; then
@@ -35,27 +49,35 @@ function git_auto_save {
fi fi
# stash changes # stash changes
git stash echo "Stashing changes..."
git stash > /dev/null 2>&1
# create new branch # create new branch
git checkout -b $new_branch_name echo "Creating new branch $new_branch_name..."
git push origin $new_branch_name git checkout -b $new_branch_name > /dev/null 2>&1
git push origin $new_branch_name > /dev/null 2>&1
# apply stashed changes # apply stashed changes
git stash apply echo "Applying stash to new branch..."
git stash apply > /dev/null 2>&1
# add changed files # add changed files
git add -u echo "Adding new/changed files..."
git add -u > /dev/null 2>&1
# commit changes # commit changes
git commit -m "git autosave from $timestamp" echo "Commiting changes..."
git commit -m "git autosave from $timestamp" > /dev/null 2>&1
# push changes # push changes
git push --set-upstream origin $new_branch_name echo "Pushing changes..."
git push --set-upstream origin $new_branch_name > /dev/null 2>&1
# move back to initial branch # move back to initial branch
git checkout $current_branch_name echo "Moving back to previous branch..."
git checkout $current_branch_name > /dev/null 2>&1
echo "Done."
} }
function remove_auto_save { function remove_auto_save {
@@ -64,6 +86,8 @@ function remove_auto_save {
echo "Current dir is not a git repository." echo "Current dir is not a git repository."
return 1 return 1
fi fi
echo "Looking for auto-save branches..."
if [[ $1 ]]; then if [[ $1 ]]; then
auto_save_branch=$1 auto_save_branch=$1
@@ -71,12 +95,15 @@ function remove_auto_save {
auto_save_branch=`git branch | grep "git_auto_save" | head -1 | awk '{print $FN}'` auto_save_branch=`git branch | grep "git_auto_save" | head -1 | awk '{print $FN}'`
fi fi
if [[ ! $auto_save_branch ]]; then if [[ ! $auto_save_branch ]]; then
echo "No auto-save branch found." echo "No auto-save branch found."
return 1 return 1
fi fi
auto_save_branch=${auto_save_branch:2} auto_save_branch=${auto_save_branch:2}
echo "Auto-save branch found: $auto_save_branch"
current_branch=$(get_current_branch) current_branch=$(get_current_branch)
# if on autosave branch, move to master # if on autosave branch, move to master
@@ -86,10 +113,12 @@ function remove_auto_save {
fi fi
# remove local branch # remove local branch
git branch -d $auto_save_branch echo "Deleting local branch..."
git branch -d $auto_save_branch > /dev/null 2>&1
# remove remote branch # remove remote branch
git push origin --delete $auto_save_branch echo "Deleting remote branch..."
git push origin --delete $auto_save_branch > /dev/null 2>&1
return 0 return 0
@@ -120,5 +149,6 @@ function remove_all_auto_saves {
} }
function load_last_auto_save { function load_last_auto_save {
echo "" auto_save_branches=$(get_auto_save_branches)
echo $auto_save_branches
} }
-1
View File
@@ -1 +0,0 @@
config.ini##class.arch_desktop
+2 -2
View File
@@ -94,8 +94,8 @@ green = "#859900"
-- sizes -- sizes
gap = 10 gap = 10
topbar = 0 topbar = 5
border = 2 border = 5
prompt = 5 prompt = 5
status = 5 status = 5