summaryrefslogtreecommitdiff
path: root/bin/git-pull-safe
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2017-02-16 13:47:19 -0700
committerSean Whitton <spwhitton@spwhitton.name>2017-02-16 13:47:19 -0700
commit995813d15d1cb04015c5d93aefe6bf7bb9c3e75f (patch)
tree5c0807106f4ba609eb6a89ad67671414382f101d /bin/git-pull-safe
parentfac92fecbe14f01db2d7b5f23ae87ad6c7cb5a09 (diff)
downloaddotfiles-995813d15d1cb04015c5d93aefe6bf7bb9c3e75f.tar.gz
factor out fns in git-pull-safe
Diffstat (limited to 'bin/git-pull-safe')
-rwxr-xr-xbin/git-pull-safe21
1 files changed, 15 insertions, 6 deletions
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