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}')
}
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 {
if [[ $(is_git ".") -ne 0 ]]; then
@@ -35,27 +49,35 @@ function git_auto_save {
fi
# stash changes
git stash
echo "Stashing changes..."
git stash > /dev/null 2>&1
# create new branch
git checkout -b $new_branch_name
git push origin $new_branch_name
echo "Creating new branch $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
git stash apply
echo "Applying stash to new branch..."
git stash apply > /dev/null 2>&1
# add changed files
git add -u
echo "Adding new/changed files..."
git add -u > /dev/null 2>&1
# 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
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
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 {
@@ -64,6 +86,8 @@ function remove_auto_save {
echo "Current dir is not a git repository."
return 1
fi
echo "Looking for auto-save branches..."
if [[ $1 ]]; then
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}'`
fi
if [[ ! $auto_save_branch ]]; then
echo "No auto-save branch found."
return 1
fi
auto_save_branch=${auto_save_branch:2}
echo "Auto-save branch found: $auto_save_branch"
current_branch=$(get_current_branch)
# if on autosave branch, move to master
@@ -86,10 +113,12 @@ function remove_auto_save {
fi
# 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
git push origin --delete $auto_save_branch
echo "Deleting remote branch..."
git push origin --delete $auto_save_branch > /dev/null 2>&1
return 0
@@ -120,5 +149,6 @@ function remove_all_auto_saves {
}
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
gap = 10
topbar = 0
border = 2
topbar = 5
border = 5
prompt = 5
status = 5