summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2012-05-04 21:32:20 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2012-05-04 21:32:20 +0200
commit5281befac3e3d484e024a94436155fe1a718ea2c (patch)
treefc298174d912abe99c3b5bd0c6eb3b8b595f91c8
parent0897d4baab634674348e5be3b2b7d9c4395e0548 (diff)
downloaddotfiles-5281befac3e3d484e024a94436155fe1a718ea2c.tar.gz
dotfiles-5281befac3e3d484e024a94436155fe1a718ea2c.tar.xz
dotfiles-5281befac3e3d484e024a94436155fe1a718ea2c.zip
bashrc/main: update could now handle force pushes to the server
-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