X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=scripts%2Frev_control%2Fversion_control.sh;h=53855ec010931b929402975167bb74fb7695fba3;hb=9e076ff4d414f8c92424c5c091c9b70592e7c8ed;hp=8c714ece4974d0269ef4b8b13b715dd7e386a4d9;hpb=154c324a33c8566c9f10dae55f6cadaf30862338;p=feisty_meow.git diff --git a/scripts/rev_control/version_control.sh b/scripts/rev_control/version_control.sh index 8c714ece..53855ec0 100644 --- a/scripts/rev_control/version_control.sh +++ b/scripts/rev_control/version_control.sh @@ -251,6 +251,38 @@ function parent_branch_name() echo "$(git branch -vv | grep \* | cut -d ' ' -f2)" } +# this exits with 0 for success (normal bash behavior). 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. @@ -260,34 +292,23 @@ 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 - -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 +#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 origin + git pull --no-ff --all test_or_die "git fetch origin" +echo The rest of pull is not being done yet. +return 1 + + # below has older shards of partial knowledge.