Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git rpr #1109

Merged
merged 3 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/cpr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
#
# git config --global alias.cpr '!sh .github/cpr.sh'

set -e # stop on error

usage="$(basename "$0") pr -- Checkout a Pull Request locally"

if [ "$#" -ne 1 ]; then
echo "Illegal number of parameters"
echo "$usage" >&2
exit 1
fi

command -v jq >/dev/null 2>&1 || { echo "I require jq but it's not installed. Aborting." >&2; exit 1; }

set -x # echo on

initial=$(git rev-parse --abbrev-ref HEAD)
pr=$1
remote=$(curl -s https://api.github.com/repos/containous/traefik/pulls/$pr | jq -r .head.repo.owner.login)
branch=$(curl -s https://api.github.com/repos/containous/traefik/pulls/$pr | jq -r .head.ref)

git remote add $remote git@github.com:$remote/traefik.git
git fetch $remote $branch
git checkout -t $remote/$branch
27 changes: 27 additions & 0 deletions .github/rmpr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh
#
# git config --global alias.rmpr '!sh .github/rmpr.sh'

set -e # stop on error

usage="$(basename "$0") pr -- remove a Pull Request local branch & remote"

if [ "$#" -ne 1 ]; then
echo "Illegal number of parameters"
echo "$usage" >&2
exit 1
fi

command -v jq >/dev/null 2>&1 || { echo "I require jq but it's not installed. Aborting." >&2; exit 1; }

set -x # echo on

initial=$(git rev-parse --abbrev-ref HEAD)
pr=$1
remote=$(curl -s https://api.github.com/repos/containous/traefik/pulls/$pr | jq -r .head.repo.owner.login)
branch=$(curl -s https://api.github.com/repos/containous/traefik/pulls/$pr | jq -r .head.ref)

# clean
git checkout $initial
git branch -D $branch
git remote remove $remote
26 changes: 13 additions & 13 deletions .github/rpr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

set -e # stop on error

usage="$(basename "$0") pr -- rebase a Pull Request against current branch"
usage="$(basename "$0") pr remote/branch -- rebase a Pull Request against a remote branch"

if [ "$#" -ne 1 ]; then
if [ "$#" -ne 2 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a default value for the most common case ? (if $2 is not present, use upstream/master for ex 👼 )

echo "Illegal number of parameters"
echo "$usage" >&2
exit 1
Expand All @@ -16,20 +16,20 @@ command -v jq >/dev/null 2>&1 || { echo "I require jq but it's not installed. A

set -x # echo on

base=$(git rev-parse --abbrev-ref HEAD)
initial=$(git rev-parse --abbrev-ref HEAD)
pr=$1
base=$2
remote=$(curl -s https://api.github.com/repos/containous/traefik/pulls/$pr | jq -r .head.repo.owner.login)
branch=$(curl -s https://api.github.com/repos/containous/traefik/pulls/$pr | jq -r .head.ref)

git checkout $base
clean ()
{
.github/rmpr.sh $pr
}

git remote add $remote git@github.com:$remote/traefik.git
git fetch $remote $branch
git checkout -t $remote/$branch
git rebase origin/$base
git push -f $remote $branch
trap clean EXIT

.github/cpr.sh $pr

# clean
git checkout $base
git branch -D $branch
git remote remove $remote
git rebase $base
git push -f $remote $branch