summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bashrc/main.sh29
1 files changed, 28 insertions, 1 deletions
diff --git a/bashrc/main.sh b/bashrc/main.sh
index 47c8d65..8ba2e72 100644
--- a/bashrc/main.sh
+++ b/bashrc/main.sh
@@ -32,7 +32,34 @@ _self_update() {
echo -ne "\033[31m*\033[0m dotfile updates found, merge now? (Y/n) "
read _merge;
if [[ $_merge != 'n' ]]; then
- git merge origin/master
+ _local_commits="$(git rev-list old-origin..HEAD | xargs echo)"
+ _local_changes="$(git status | grep Change)"
+
+ if [[ -n "$_local_commits" ]]; then
+ echo -e "\033[31m*\033[0m You have some local commits. I will now try to use the new origin/master"
+ echo " and apply the extra commits afterwards."
+ fi
+
+ if [[ -n "$_local_changes" ]]; then
+ echo -e "\033[31m*\033[0m You have some uncommited local changes."
+ echo " I will try to preserve it using the git stash."
+ git stash || return
+ fi
+
+ git reset --hard origin/master
+
+ if [[ -n "$_local_commits" ]]; then
+ echo -e "\033[33m*\033[0m cherry-pick: $_local_commits"
+ git cherry-pick $_local_commits || return
+ fi
+
+ if [[ -n "$_local_changes" ]]; then
+ git stash pop || return
+ fi
+
+ # all done, update old-origin
+ git branch -D old-origin
+ git branch old-origin origin/master
if [[ -e management/symlinks.md5 ]]; then
if hash md5sum 2> /dev/null ; then