From f56cbb49ea403b61662ae501c1e78cbf98969adf Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 16 Jul 2012 18:07:09 +0200 Subject: bashrc/main: use rebase to preserve local commits --- bashrc/main.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bashrc/main.sh b/bashrc/main.sh index 01ca309..9883ca9 100644 --- a/bashrc/main.sh +++ b/bashrc/main.sh @@ -44,12 +44,13 @@ _self_update() { echo -ne "\033[31m*\033[0m dotfile updates found, merge now? (Y/n) " read _merge; if [[ $_merge != 'n' ]]; then - _local_commits="$(git rev-list old-origin..HEAD | xargs echo)" _local_changes="$(git status | grep '^# Change')" + _old_origin="$(git rev-list old-origin | head -n1)" + _old_head="$(git rev-list HEAD | head -n1)" - 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." + if [[ "$_old_origin" != "$_old_head" ]]; then + echo -e "\033[31m*\033[0m You have some local commits. I will now try to rebase them" + echo " onto the new origin/master." fi if [[ -n "$_local_changes" ]]; then @@ -64,9 +65,9 @@ _self_update() { git tag -d old-origin >/dev/null 2>&1 git tag old-origin origin-master >/dev/null 2>&1 - if [[ -n "$_local_commits" ]]; then - echo -e "\033[33m*\033[0m cherry-pick: $_local_commits" - git cherry-pick $_local_commits >/dev/null || return + if [[ "$_old_origin" != "$_old_head" ]]; then + echo -e "\033[33m*\033[0m git rebase --onto HEAD $_old_origin $_old_head" + git rebase --onto origin/master $_old_origin $_old_head || return fi if [[ -n "$_local_changes" ]]; then -- cgit v1.2.3