From 5281befac3e3d484e024a94436155fe1a718ea2c Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 4 May 2012 21:32:20 +0200 Subject: bashrc/main: update could now handle force pushes to the server --- bashrc/main.sh | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'bashrc') 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 -- cgit v1.2.3