mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 07:26:17 -04:00
git-pr: added <[remote]:pr number> option.
This commit is contained in:
parent
088ea058d9
commit
87b7c959b4
30
bin/git-pr
30
bin/git-pr
|
|
@ -1,22 +1,38 @@
|
|||
#!/usr/bin/env bash
|
||||
# Based on https://gist.github.com/gnarf/5406589 and https://gist.github.com/jhnns/d654d9d6da6d3b749986
|
||||
|
||||
pull() {
|
||||
local remote="$1"
|
||||
local id="$2"
|
||||
local branch="$3"
|
||||
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;
|
||||
}
|
||||
|
||||
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]}
|
||||
|
||||
elif [[ $1 =~ ^(.*):([0-9]+)|(https?://[^/]+/.+)/pull/([0-9]+).*$ ]]; then
|
||||
if [[ -n ${BASH_REMATCH[2]} ]]; then
|
||||
remote="${BASH_REMATCH[1]:-origin}"
|
||||
id="${BASH_REMATCH[2]}"
|
||||
else
|
||||
remote="${BASH_REMATCH[3]}.git"
|
||||
id="${BASH_REMATCH[4]}"
|
||||
fi
|
||||
|
||||
branch=pr/$id
|
||||
pull "$remote" "$id" "$branch"
|
||||
|
||||
else
|
||||
test -z $1 && echo "pr number required." 1>&2 && exit 1
|
||||
remote=${2:-origin}
|
||||
id=$1
|
||||
branch=pr/$id
|
||||
pull "$remote" "$id" "$branch"
|
||||
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;
|
||||
|
|
|
|||
18
man/git-pr.1
18
man/git-pr.1
|
|
@ -1,7 +1,7 @@
|
|||
.\" generated with Ronn/v0.7.3
|
||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||
.
|
||||
.TH "GIT\-PR" "1" "October 2017" "" "Git Extras"
|
||||
.TH "GIT\-PR" "1" "February 2019" "" "Git Extras"
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBgit\-pr\fR \- Checks out a pull request locally
|
||||
|
|
@ -10,6 +10,9 @@
|
|||
\fBgit\-pr\fR <number> [<remote>]
|
||||
.
|
||||
.br
|
||||
\fBgit\-pr\fR <[remote]:number>
|
||||
.
|
||||
.br
|
||||
\fBgit\-pr\fR <url>
|
||||
.
|
||||
.br
|
||||
|
|
@ -66,6 +69,19 @@ $ git pr 226 upstream
|
|||
.IP "" 0
|
||||
.
|
||||
.P
|
||||
This does the same thing as the command above:
|
||||
.
|
||||
.IP "" 4
|
||||
.
|
||||
.nf
|
||||
|
||||
$ git pr upstream:226
|
||||
.
|
||||
.fi
|
||||
.
|
||||
.IP "" 0
|
||||
.
|
||||
.P
|
||||
You can also checkout a pull request based on a GitHub URL:
|
||||
.
|
||||
.IP "" 4
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@
|
|||
<h2 id="SYNOPSIS">SYNOPSIS</h2>
|
||||
|
||||
<p><code>git-pr</code> <number> [<remote>]<br />
|
||||
<code>git-pr</code> <[remote]:number><br />
|
||||
<code>git-pr</code> <url><br />
|
||||
<code>git-pr clean</code></p>
|
||||
|
||||
|
|
@ -116,6 +117,11 @@ Switched to branch 'pr/226'
|
|||
<pre><code>$ git pr 226 upstream
|
||||
</code></pre>
|
||||
|
||||
<p>This does the same thing as the command above:</p>
|
||||
|
||||
<pre><code>$ git pr upstream:226
|
||||
</code></pre>
|
||||
|
||||
<p>You can also checkout a pull request based on a GitHub URL:</p>
|
||||
|
||||
<pre><code>$ git pr https://github.com/tj/git-extras/pull/453
|
||||
|
|
@ -148,7 +154,7 @@ Deleted branch pr/220 (was d34dc0f).
|
|||
|
||||
<ol class='man-decor man-foot man foot'>
|
||||
<li class='tl'></li>
|
||||
<li class='tc'>October 2017</li>
|
||||
<li class='tc'>February 2019</li>
|
||||
<li class='tr'>git-pr(1)</li>
|
||||
</ol>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ git-pr(1) -- Checks out a pull request locally
|
|||
## SYNOPSIS
|
||||
|
||||
`git-pr` <number> [<remote>]<br>
|
||||
`git-pr` <[remote]:number><br>
|
||||
`git-pr` <url><br>
|
||||
`git-pr clean`
|
||||
|
||||
|
|
@ -41,6 +42,10 @@ This pulls from a different remote:
|
|||
|
||||
$ git pr 226 upstream
|
||||
|
||||
This does the same thing as the command above:
|
||||
|
||||
$ git pr upstream:226
|
||||
|
||||
You can also checkout a pull request based on a GitHub URL:
|
||||
|
||||
$ git pr https://github.com/tj/git-extras/pull/453
|
||||
|
|
|
|||
Loading…
Reference in a new issue