summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander.sulfrian@fu-berlin.de>2012-07-16 18:07:09 +0200
committerAlexander Sulfrian <alexander.sulfrian@fu-berlin.de>2012-07-16 18:07:09 +0200
commitf56cbb49ea403b61662ae501c1e78cbf98969adf (patch)
tree0a204052d0b3062b380d50719d83b6c2dd480cf2
parent7cf492945368ecaf37815744f4cc756aac455c31 (diff)
downloaddotfiles-f56cbb49ea403b61662ae501c1e78cbf98969adf.tar.gz
dotfiles-f56cbb49ea403b61662ae501c1e78cbf98969adf.tar.xz
dotfiles-f56cbb49ea403b61662ae501c1e78cbf98969adf.zip
bashrc/main: use rebase to preserve local commits
-rw-r--r--bashrc/main.sh15
1 files 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