don't change branches unnecessarily
This commit is contained in:
parent
1bdd34d97e
commit
f9e512cb56
1 changed files with 14 additions and 4 deletions
14
git-update
14
git-update
|
|
@ -2,7 +2,11 @@
|
||||||
|
|
||||||
set -e # bail on errors
|
set -e # bail on errors
|
||||||
|
|
||||||
ORIG_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
function current_branch() {
|
||||||
|
git rev-parse --abbrev-ref HEAD
|
||||||
|
}
|
||||||
|
|
||||||
|
ORIG_BRANCH=$(current_branch)
|
||||||
REMOTE="${1:-$(git config --get branch.${ORIG_BRANCH}.remote)}"
|
REMOTE="${1:-$(git config --get branch.${ORIG_BRANCH}.remote)}"
|
||||||
if [[ "$ORIG_BRANCH" = "HEAD" ]]; then
|
if [[ "$ORIG_BRANCH" = "HEAD" ]]; then
|
||||||
echo "Cannot update in a detached HEAD state"
|
echo "Cannot update in a detached HEAD state"
|
||||||
|
|
@ -11,7 +15,9 @@ fi
|
||||||
if [[ -z "$2" ]]; then
|
if [[ -z "$2" ]]; then
|
||||||
BRANCHES="$ORIG_BRANCH"
|
BRANCHES="$ORIG_BRANCH"
|
||||||
else
|
else
|
||||||
|
if [[ "$1" = "$REMOTE" ]]; then
|
||||||
shift
|
shift
|
||||||
|
fi
|
||||||
BRANCHES="$@"
|
BRANCHES="$@"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -26,11 +32,15 @@ git fetch --prune --tags "$REMOTE"
|
||||||
|
|
||||||
for BRANCH in $BRANCHES; do
|
for BRANCH in $BRANCHES; do
|
||||||
echo "* Updating $BRANCH from $REMOTE/$BRANCH"
|
echo "* Updating $BRANCH from $REMOTE/$BRANCH"
|
||||||
|
if [[ "$BRANCH" != "$(current_branch)" ]]; then
|
||||||
git checkout "$BRANCH"
|
git checkout "$BRANCH"
|
||||||
|
fi
|
||||||
git rebase "$REMOTE/$BRANCH"
|
git rebase "$REMOTE/$BRANCH"
|
||||||
done
|
done
|
||||||
|
|
||||||
git checkout "$ORIG_BRANCH"
|
if [[ "$ORIG_BRANCH" != "$(current_branch)" ]]; then
|
||||||
|
git checkout "$ORIG_BRANCH"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $POP_STASH -eq 1 ]]; then
|
if [[ $POP_STASH -eq 1 ]]; then
|
||||||
git stash pop
|
git stash pop
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue