fixed diagnostic message
[feisty_meow.git] / scripts / rev_control / version_control.sh
index 291789f13d7bd852e28723721d478df5ae30ee19..c87eee51b5442e46057271f4f1d7a97aa7f4594e 100644 (file)
@@ -91,6 +91,7 @@ function do_checkin()
         git commit .
         test_or_die "git commit"
       fi
+
 #      # upload the files to the server so others can see them.
 #      git push 2>&1 | grep -v "X11 forwarding request failed"
 #      if [ ${PIPESTATUS[0]} -ne 0 ]; then false; fi
@@ -250,6 +251,38 @@ function parent_branch_name()
   echo "$(git branch -vv | grep \* | cut -d ' ' -f2)"
 }
 
+# this exits with 0 for success (normal bash behavior) when up to date.  if the branch is not up to date,
+# then these values are returned:
+#DOCUMENT THE VALUES
+# reference: https://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git
+function check_branch_state()
+{
+  local branch="$1"; shift
+
+  local to_return=120  # unknown issue.
+
+  LOCAL=$(git rev-parse @)
+  REMOTE=$(git rev-parse "$branch")
+  BASE=$(git merge-base @ "$branch")
+var branch LOCAL REMOTE BASE
+
+  if [ "$LOCAL" == "$REMOTE" ]; then
+    echo "Up-to-date"
+    to_return=0
+  elif [ "$LOCAL" == "$BASE" ]; then
+    echo "Need to pull"
+    to_return=1
+  elif [ "$REMOTE" == "$BASE" ]; then
+    echo "Need to push"
+    to_return=2
+  else
+    echo "Diverged"
+    to_return=3
+  fi
+
+  return $to_return
+}
+
 # the git update process just gets more and more complex when you bring in
 # branches, so we've moved this here to avoid having a ton of code in the
 # do_checkin method.
@@ -259,33 +292,22 @@ function careful_git_update()
   git remote update
   test_or_die "git remote update"
 
-#hmmm: this should be a function:
-# from: https://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git
-UPSTREAM=$(parent_branch_name)
-#argh: original UPSTREAM='${1:-'\''@{u}'\''}'
-LOCAL=$(git rev-parse @)
-REMOTE=$(git rev-parse "$UPSTREAM")
-BASE=$(git merge-base @ "$UPSTREAM")
-var UPSTREAM LOCAL REMOTE BASE
+#is parent branch the right thing to tell it?
+#or we want mybranch for real, don't we?
+#  check_branch_state $(parent_branch_name)
+  state=$(check_branch_state $(my_branch_name) )
+test_or_continue "branch state check"
+#need to instead do something here if fails.
+
+  # now pull down any changes in our own origin in the repo, to stay in synch
+  # with any changes from others.
+  git pull --no-ff --all
+  test_or_die "git pulling all upstream"
 
-if [ "$LOCAL" == "$REMOTE" ]; then
-    echo "Up-to-date"
-elif [ "$LOCAL" == "$BASE" ]; then
-    echo "Need to pull"
-elif [ "$REMOTE" == "$BASE" ]; then
-    echo "Need to push"
-else
-    echo "Diverged"
-fi
 
 echo The rest of pull is not being done yet.
 return 1
 
-  # now pull down any changes in our own origin in the repo, to stay in synch
-  # with any changes from others.
-  git pull --no-ff origin
-  test_or_die "git fetch origin"
-
 
 
 # below has older shards of partial knowledge.