chiark / gitweb /
tg update: Support updating from remote branches
authorPetr Baudis <pasky@suse.cz>
Tue, 9 Sep 2008 19:33:55 +0000 (21:33 +0200)
committerPetr Baudis <pasky@suse.cz>
Tue, 9 Sep 2008 19:33:55 +0000 (21:33 +0200)
Currently, we only ever check against the base remote.

README
tg-update.sh

diff --git a/README b/README
index 0c0002c7dd416c51bc22f05cc46cfca0306b1a75..cc200cae41b7695b91e1cc768bf905c2b9ef764f 100644 (file)
--- a/README
+++ b/README
@@ -352,10 +352,11 @@ tg export
 tg update
 ~~~~~~~~~
        Update the current topic branch wrt. changes in the branches
-       it depends on. This is made in two phases - first,
+       it depends on and remote branches.
+       This is performed in two phases - first,
        changes within the dependencies are merged to the base,
-       then the base is merged into the topic branch. The output
-       will guide you in case of conflicts.
+       then the base is merged into the topic branch.
+       The output will guide you in case of conflicts.
 
        In case your dependencies are not up-to-date, tg update
        will first recurse into them and update these.
index 5caf6910a17f7c39906fe6456bd550faf4b537c2..912c968dbdce2b3ce35f08f2adfcbf82164fbff0 100644 (file)
@@ -43,9 +43,10 @@ if [ -s "$depcheck" ]; then
                        dep="$(echo "$depline" | cut -c 2-)"
 
                        # We do not distinguish between dependencies out-of-date
-                       # and base out-of-date cases for $dep here,
-                       # but thanks to needs_update returning : for the latter,
-                       # we do correctly recurse here in both cases.
+                       # and base/remote out-of-date cases for $dep here,
+                       # but thanks to needs_update returning : or %
+                       # for the latter, we do correctly recurse here
+                       # in both cases.
 
                        if [ x"$action" = x+ ]; then
                                info "Recursing to $dep..."
@@ -67,10 +68,8 @@ if [ -s "$depcheck" ]; then
                                switch_to_base "$name"
                        fi
 
-                       # This will always be a proper topic branch
-                       # (not a base or remote), since for deep updates
-                       # we recurse and immediate dependencies
-                       # are always proper. (branch_needs_update() is called
+                       # This will be either a proper topic branch
+                       # or a remote base.  (branch_needs_update() is called
                        # only on the _dependencies_, not our branch itself!)
 
                        info "Updating base with $dep changes..."
@@ -96,15 +95,41 @@ else
 fi
 rm "$depcheck"
 
+merge_with="refs/top-bases/$name"
+
+
+## Second, update our head with the remote branch
+
+rname="refs/remotes/$base_remote/$name"
+if [ -n "$base_remote" ] && ref_exists "$rname"; then
+       if branch_contains "$name" "$rname"; then
+               info "The $name head is up-to-date wrt. its remote branch."
+       else
+               info "Reconciling remote branch updates with $name base..."
+               # *DETACH* our HEAD now!
+               git checkout -q "refs/top-bases/$name"
+               if ! git merge "$rname"; then
+                       info "Oops, you will need to help me out here a bit."
+                       info "Please commit merge resolution and call:"
+                       info "git checkout $name && git merge <commitid>"
+                       info "It is also safe to abort this operation using: git reset --hard $name"
+                       exit 3
+               fi
+               # Go back but remember we want to merge with this, not base
+               merge_with="$(git rev-parse HEAD)"
+               git checkout -q "$name"
+       fi
+fi
+
 
-## Second, update our head with the base
+## Third, update our head with the base
 
-if branch_contains "$name" "refs/top-bases/$name"; then
+if branch_contains "$name" "$merge_with"; then
        info "The $name head is up-to-date wrt. the base."
        exit 0
 fi
 info "Updating $name against new base..."
-if ! git merge "refs/top-bases/$name"; then
+if ! git merge "$merge_with"; then
        if [ -z "$TG_RECURSIVE" ]; then
                info "Please commit merge resolution. No need to do anything else"
                info "You can abort this operation using \`git reset --hard\` now"