summaryrefslogtreecommitdiffhomepage
path: root/scripts/checkoutpr.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/checkoutpr.sh')
-rwxr-xr-xscripts/checkoutpr.sh30
1 files changed, 23 insertions, 7 deletions
diff --git a/scripts/checkoutpr.sh b/scripts/checkoutpr.sh
index 3d07227ff6..204fb0ed9f 100755
--- a/scripts/checkoutpr.sh
+++ b/scripts/checkoutpr.sh
@@ -3,7 +3,7 @@ if [ -z "$1" ]; then
echo "$0 <prID>"
exit 1;
fi
-repo=$(git remote get-url origin | sed -E 's/github.com(:|\/)//g')
+repo=$(git remote get-url origin | sed -E 's/(.*@)?github.com(:|\/)//g' | sed 's/.git$//g')
data=$(curl -q https://api.github.com/repos/$repo/pulls/$1 2>/dev/null)
url=$(echo -e "$data" | grep --color=none ssh_url | head -n 1 |awk '{print $2}' | sed 's/"//g' | sed 's/,//g')
ref=$(echo -e "$data" | grep --color=none '"head":' -A 3 | grep ref | head -n 1 |awk '{print $2}' | sed 's/"//g' | sed 's/,//g')
@@ -16,23 +16,39 @@ git branch -D $branch 2>/dev/null 1>&2
git checkout -b $branch $up/$ref 2>/dev/null|| true
echo "Merging $prevbranch into $branch"
git fetch origin
-git merge origin/$prevbranch
-
+read -p "Press 'm' to merge, 'r' to rebase, or 'n' for nothing" -n 1 -r >&2
+echo
+if [[ "$REPLY" =~ ^[Mm]$ ]]; then
+ git merge origin/$prevbranch
+elif [[ "$REPLY" =~ ^[Rr]$ ]]; then
+ git rebase master
+fi
echo "Dropping to new shell, exit to delete the refs"
-bash -i
+"${SHELL:-bash}" -i
read -p "Press 'p' to push. " -n 1 -r >&2
echo
-if [[ "d$REPLY" =~ ^d[Pp]$ ]]; then
+pushed=0
+if [[ "$REPLY" =~ ^[Pp]$ ]]; then
git push $up $branch:$ref -f
-
+ pushed=1
echo "Pushed" >&2
fi
echo "Deleting branch/upstream"
git checkout $prevbranch
+if [[ "$pushed" == "1" ]]; then
+ read -p "Press 'm' to merge or 'r' to rebase merge " -n 1 -r >&2
+ if [[ "$REPLY" =~ ^[Mm]$ ]]; then
+ git merge $branch
+ fi
+ if [[ "$REPLY" =~ ^[Rr]$ ]]; then
+ git merge --ff-only $branch
+ fi
+fi
+
git branch -D $branch
git remote remove $up
git gc
#git branch -u $up/$ref $branch
-#git checkout $branch \ No newline at end of file
+#git checkout $branch