From 995813d15d1cb04015c5d93aefe6bf7bb9c3e75f Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 16 Feb 2017 13:47:19 -0700 Subject: factor out fns in git-pull-safe --- bin/git-pull-safe | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'bin/git-pull-safe') diff --git a/bin/git-pull-safe b/bin/git-pull-safe index 9cb0b65b..22be76dd 100755 --- a/bin/git-pull-safe +++ b/bin/git-pull-safe @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Update all remote-tracking branches, and as many local branches that # we can fast-forward. Additionally, if the current branch looks like @@ -7,11 +7,21 @@ set -e +function branch_prefix() { + local branch="$1" + echo $branch | cut -s -d/ -f1 +} + +function branch_remote() { + local branch="$1" + git config branch.$branch.remote +} + current_branch="$(git rev-parse --abbrev-ref HEAD)" branches="$(git for-each-ref --format='%(refname:short)' refs/heads/)" -if [ "$(echo $current_branch | cut -s -d/ -f1)" = "dgit" ]; then - echo "I: current branch is dgit/foo; doing \`dgit pull\`" +if [ "$(branch_prefix $current_branch)" = "dgit" ]; then + echo "I: current branch is $current_branch; doing \`dgit pull\`" dgit pull fi for suite in $(git show-ref | grep refs/remotes/dgit/dgit | cut -d/ -f5 ); do @@ -24,10 +34,9 @@ done git remote update for branch in $branches; do - prefix="$(echo $branch | cut -s -d/ -f1)" - remote="$(git config branch.$branch.remote 2>/dev/null || true)" + remote="$(branch_remote $branch 2>/dev/null || true)" # echo "I: branch $branch has prefix $prefix and remote $remote" - if [ "$prefix" != "dgit" ] && [ "$remote" != "" ]; then + if [ "$(branch_prefix $branch)" != "dgit" ] && [ "$remote" != "" ]; then # if the branch cannot be fast-forwarded, git-merge-ff will # exit non-zero, so myrepos will report that the update # failed, so user intervention is required -- cgit v1.2.3