tj.git-extras/bin/git-pr
J.C. Yamokoski 6eb04bcca8 Remove slashes from git-config command
These slashes were causing the branch to be saved in `.git/config` with headings
such as `[branch "\"pr/123\""]` as opposed to `[branch "pr/123"]`. This in turn
prevented these entries from being removed when running `git pr clean`.
2017-03-28 09:44:40 -04:00

23 lines
746 B
Bash
Executable file

#!/usr/bin/env bash
# Based on https://gist.github.com/gnarf/5406589 and https://gist.github.com/jhnns/d654d9d6da6d3b749986
if test "$1" = "clean"; then
git for-each-ref refs/heads/pr/* --format='%(refname)' | while read ref; do
git branch -D ${ref#refs/heads/}
done
exit 0
elif [[ $1 =~ ^(https?://[^/]+/(.+))/pull/([0-9]+).*$ ]]; then
remote=${BASH_REMATCH[1]}.git
id=${BASH_REMATCH[3]}
branch=pr/$id
else
test -z $1 && echo "pr number required." 1>&2 && exit 1
remote=${2:-origin}
id=$1
branch=pr/$id
fi
git fetch -fu $remote refs/pull/$id/head:$branch && \
git checkout $branch && \
git config --local --replace branch.$branch.merge refs/pull/$id/head && \
git config --local --replace branch.$branch.remote $remote;