+ local branch="$1"; shift
+
+ if [ -z "$branch" ]; then
+ echo "No branch was passed to check branch state."
+ return 1
+ fi
+
+ local to_return=120 # unknown issue.
+
+ local local_branch=$(git rev-parse @)
+ local remote_branch=$(git rev-parse "$branch")
+ local merge_base=$(git merge-base @ "$branch")
+
+ local to_echo=
+ if [ "$local_branch" == "$remote_branch" ]; then
+ to_echo="okay"
+ elif [ "$local_branch" == "$merge_base" ]; then
+ to_echo="needs_pull"
+ elif [ "$remote_branch" == "$merge_base" ]; then
+ to_echo="needs_push"
+ else
+ to_echo="diverged"
+ fi
+
+ echo -n "$to_echo"
+
+ return $to_return
+}
+
+# only shows the branch state if it's not okay.
+# note that this is not the same as a conditional branch (ha ha).
+function show_branch_conditionally()
+{
+ local this_branch="$1"; shift
+
+ local state=$(check_branch_state "$this_branch")
+ if [ "$state" != "okay" ]; then
+ echo "=> branch '$this_branch' state is not clean: $state"
+ fi