dotfiles/symlinks/bin/git-pr-review

41 lines
1002 B
Bash
Executable File

#!/bin/sh
set -e
if [ -z "$1" ]; then
echo "Missing origin branch. Pass in the branch to compare as the first parameter!"
exit 1
fi
ORIGIN_BRANCH="$1"
if [ "${1}" = "${1#origin/}" ]; then
read -p "Origin branch does not seem to be from the 'origin/' remote. Proceed? [y/n]" ANSWER
if [ ! "$ANSWER" = "y" ]; then
exit 2
fi
fi
TARGET_BRANCH="$2"
if [ -z "$2" ]; then
TARGET_BRANCH="origin/main"
echo "Missing target branch. Assuming $TARGET_BRANCH!"
fi
if [ "${TARGET_BRANCH}" = "${TARGET_BRANCH#origin/}" ]; then
read -p "Target branch does not seem to be from the 'origin/' remote. Proceed? [y/n]" ANSWER
if [ ! "$ANSWER" = "y" ]; then
exit 2
fi
fi
if [ ! "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
echo "Not inside a git repository."
exit 128
fi
echo "Updating origin..."
git fetch
git checkout $ORIGIN_BRANCH
echo "You are now checked out to the PR branch. Feel free to build the project and test it out."
git difftool $TARGET_BRANCH