even more careful push and pull
[feisty_meow.git] / scripts / rev_control / version_control.sh
index b19f9a420626eb7f21ae890a9c05644e2218b230..ccb14c25d577784d480f4dfa77b375c45b7c7ca8 100644 (file)
@@ -81,9 +81,19 @@ function do_checkin()
       # catch if the diff-index failed somehow.
       retval+=$?
 
+      local myself="$(my_branch_name)"
+      local parent="$(parent_branch_name)"
+
       # upload any changes to the upstream repo so others can see them.
-      git push 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
-      retval+=${PIPESTATUS[0]}
+      if [ "$myself" != "$parent" ]; then
+        git push origin "$(myself)" 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
+        retval+=${PIPESTATUS[0]}
+      else
+        # this branch is the same as the parent, so just push.
+        git push 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
+        retval+=${PIPESTATUS[0]}
+      fi
+
     fi
   else
     # nothing there.  it's not an error though.
@@ -209,6 +219,19 @@ function squash_first_few_crs()
   fi
 }
 
+# a helpful method that reports the git branch for the current directory's
+# git repository.
+function my_branch_name()
+{
+  echo "$(git branch | grep \* | cut -d ' ' -f2)"
+}
+
+# this reports the upstream branch for the current repo.
+function parent_branch_name()
+{
+  echo "$(git branch -vv | grep \* | cut -d ' ' -f2)"
+}
+
 # gets the latest versions of the assets from the upstream repository.
 function do_update()
 {
@@ -240,10 +263,17 @@ function do_update()
   elif [ -d ".git" ]; then
     if test_writeable ".git"; then
       $blatt
-      git pull origin master 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
-      retval=${PIPESTATUS[0]}
-      git pull 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
-      retval+=${PIPESTATUS[0]}
+      retval=0
+      local myself="$(my_branch_name)"
+      local parent="$(parent_branch_name)"
+
+      if [ "$myself" != "$parent" ]; then
+        git pull origin "$parent" 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
+        retval+=${PIPESTATUS[0]}
+      else
+        git pull 2>&1 | grep -v "X11 forwarding request failed" | squash_first_few_crs
+        retval+=${PIPESTATUS[0]}
+      fi
     fi
   else
     # this is not an error necessarily; we'll just pretend they planned this.