Skip to content

Commit

Permalink
add script from rich to create a local branch
Browse files Browse the repository at this point in the history
  • Loading branch information
white238 committed Aug 15, 2022
1 parent 7f286c6 commit 488aff3
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions scripts/make_local_branch_from_fork_pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash

###############################################################################
# Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and
# other BLT Project Developers. See the top-level LICENSE file for details
#
# SPDX-License-Identifier: (BSD-3-Clause)
###############################################################################

###############################################################################
# Help
###############################################################################
Help()
{
# Display Help
echo
echo "This script will make a branch in a local git repo for a PR from a "
echo "branch in a forked repo. The script must be run inside the local repo."
echo
echo "Syntax: make_local_branch_from_fork_pr [-h | -c num | num]"
echo "options:"
echo "-h Print this help usage message."
echo "-c <#> Check whether there is a PR with given number."
echo "-b <#> Make local branch from branch associated with given PR number."
echo
}

###############################################################################
# Process the input args.
###############################################################################
if [ "$1" == "" ]; then
echo
echo "You must pass an arg to script. Pass -h to see correct usage."
exit
fi

while [ "$1" != "" ]; do
case $1 in
-h) # display help message
Help
exit;;
-c) # check PR exists
shift
num=$1
echo
echo "Running git ls-remote on origin to see if PR ${num} exists..."
echo "If you don't see it in the output, it does not exist."
echo
git ls-remote --refs origin | grep "pull/${num}"
exit;;
-b) # make local branch for given PR number
shift
num=$1
echo
echo "Attempting to make local branch from branch on fork for PR ${num}"
echo
echo "If successful, you will be on local branch pr-from-fork/${num}"
echo "when script exits."
echo
echo "Run 'git branch' to be sure the new branch exists."
echo
echo "You can then push the new branch to the main repo; e.g.,"
echo " git push <remote> <branch>"
echo
echo "If you make a PR for the new branch, it is a good idea to "
echo "reference the original PR from the forked repo to track the "
echo "original PR discussion."
echo
git fetch origin pull/${num}/head:pr-from-fork/${num} && git checkout pr-from-fork/${num}
echo

exit;;
\?) # incorrect option
echo
echo "Error: $1 is an invalid option"
exit;;
esac
done

0 comments on commit 488aff3

Please sign in to comment.