#!/usr/bin/env bash # Update all remote-tracking branches, and as many local branches that # we can fast-forward. Additionally, if the current branch looks like # a dgit suite-tracking branch, merge into it the current state of the # package in the Debian archive # This script is based on the value of git_update set by the myrepos # dgit plugin. That library uses an unconditional `git pull` to match # global myrepos conventions. The main reason for having this script # is to override that unconditional `git pull` 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/)" # (1) normal git branches # note that `git remote update` may not fetch all tags git fetch --all --tags --prune for branch in $branches; do remote="$(branch_remote $branch 2>/dev/null || true)" if [ "$(branch_prefix $branch)" != "dgit" ] && [ "$remote" != "" ]; then # echo "I: attempting to fast-forward local branch $branch" if ! git branch --contains "$branch@{upstream}" \ | grep -qE " $branch$"; 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 git merge-ff "$branch" fi fi done # (2) dgit branches 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 # skip if we just called `dgit pull` on this suite if ! [ "$current_branch" = "dgit/$suite" ]; then # echo "I: fetching dgit suite $suite" [ -z "$source" ] \ && source=$(git cat-file blob dgit/dgit/$suite:debian/control \ | awk -F': ' '$1 ~ /Source/ { print $2 }') dgit -p$source fetch $suite fi done