aboutsummaryrefslogtreecommitdiff
path: root/helpers/llvm-branch
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/llvm-branch')
-rwxr-xr-xhelpers/llvm-branch123
1 files changed, 84 insertions, 39 deletions
diff --git a/helpers/llvm-branch b/helpers/llvm-branch
index 98a9504..5343914 100755
--- a/helpers/llvm-branch
+++ b/helpers/llvm-branch
@@ -1,18 +1,24 @@
#!/usr/bin/env bash
# This script helps you check which branches are checked out on git and make
-# sure they're coherent with the feature you're developing. For instance,
-# if a feature spans across both LLVM and Clang, you could name the branch on
-# each repo the same and use this script to seamlessly move between them.
+# sure all repos linked in the current worktree are on the same branch (either
+# by checking it out, or by creating it if it doesn't exist). The branch must
+# exist in at least one of the repos. If it doesn't you can force its creation
+# with -b.
-# Syntax: llvm-branch [-d] [branch]
-# -d: delete chosen branch
-# branch: find on llvm and clang and check it out
-# Without arguments, the script lists all branches and highlight the current one
+# Syntax: llvm-branch [-d|-b] [branch]
+# -d: delete chosen branch
+# -b: create branch in all repos
+# branch: checkout or create branch on all repos linked in the current tree
+# Without arguments, the script lists all branches and highlights the current one
. llvm-common
+safe_run verify_env
+
function print_branches() {
+ # TODO: put a star or something next to branches that exist in other
+ # worktrees? (can be found by iterating through LLVM_ROOT)
local current=$1
shift
local space=0
@@ -29,22 +35,6 @@ function print_branches() {
done
}
-function has() {
- if [[ $1 = '' || $2 = '' ]]; then
- echo no
- return
- fi
- local item=$1
- shift
- for each in $*; do
- if [[ $item = $each ]]; then
- echo yes
- return
- fi
- done
- echo no
-}
-
function switch() {
SRC=$1
branch=$2
@@ -53,15 +43,17 @@ function switch() {
cd $SRC
pwd
if [[ $in = 'yes' ]]; then
- if [[ $DEL = '' ]]; then
+ if [[ $DELETE = '' ]]; then
+ echo " + Checking out $branch in $SRC"
safe_run git checkout $branch
else
- safe_run git checkout master
- safe_run git branch $DEL $branch
+ echo " + Deleting $branch in $SRC"
+ safe_run git branch $DELETE $branch
fi
else
- if [[ $DEL = '' ]]; then
- safe_run git checkout master
+ if [[ $DELETE = '' ]]; then
+ echo " + Creating $branch in $SRC"
+ safe_run git checkout -b $branch
fi
fi
fi
@@ -129,9 +121,21 @@ if [ -d $LLDB_SRC ]; then
fi
# Delete chosen branch
-DEL=''
+DELETE=''
if [[ $1 = '-d' || $1 = '-D' ]]; then
- DEL=$1
+ DELETE=$1
+ shift
+fi
+
+# Force creation
+CREATE=''
+if [[ $1 = '-b' ]]; then
+ if [[ $DELETE != '' ]]; then
+ echo "Can't create and delete branch at the same time"
+ exit 1
+ fi
+
+ CREATE=$1
shift
fi
@@ -186,12 +190,50 @@ fi
# Search for branch name
branch=$1
-if [[ $DEL = 1 && $branch = 'master' ]]; then
- echo "Cannot delete the master branch"
- exit 1
+if [[ $DELETE != '' ]]; then
+ if [[ $branch = 'master' ]]; then
+ echo "Cannot delete the master branch"
+ exit 1
+ fi
+ if [[ $branch = $llvm_branch ]]; then
+ echo "Cannot delete $branch - it is checked out in llvm"
+ exit 2
+ fi
+ if [[ $branch = $clang_branch ]]; then
+ echo "Cannot delete $branch - it is checked out in clang"
+ exit 2
+ fi
+ if [[ $branch = $clang_extra_branch ]]; then
+ echo "Cannot delete $branch - it is checked out in clang tools extra"
+ exit 2
+ fi
+ if [[ $branch = $rt_branch ]]; then
+ echo "Cannot delete $branch - it is checked out in compiler rt"
+ exit 2
+ fi
+ if [[ $branch = $cxx_branch ]]; then
+ echo "Cannot delete $branch - it is checked out in libcxx"
+ exit 2
+ fi
+ if [[ $branch = $cxxabi_branch ]]; then
+ echo "Cannot delete $branch - it is checked out in libcxxabi"
+ exit 2
+ fi
+ if [[ $branch = $unw_branch ]]; then
+ echo "Cannot delete $branch - it is checked out in libunwind"
+ exit 2
+ fi
+ if [[ $branch = $lld_branch ]]; then
+ echo "Cannot delete $branch - it is checked out in lld"
+ exit 2
+ fi
+ if [[ $branch = $lldb_branch ]]; then
+ echo "Cannot delete $branch - it is checked out in lldb"
+ exit 2
+ fi
fi
-# Check which projects the branch is
+# Check which projects have the branch
in_llvm=`has $branch $llvm_branches`
in_clang=`has $branch $clang_branches`
in_clang_extra=`has $branch $clang_extra_branches`
@@ -201,11 +243,14 @@ in_cxxabi=`has $branch $cxxabi_branches`
in_unw=`has $branch $unw_branches`
in_lld=`has $branch $lld_branches`
in_lldb=`has $branch $lldb_branches`
-if [[ $in_clang = 'no' && $in_clang_extra && $in_llvm = 'no' && \
- $in_rt = 'no' && $in_cxx = 'no' && $in_cxxabi = 'no' && \
- $in_unw = 'no' && $in_lld = 'no' && $in_lldb = 'no' ]]; then
- echo "Branch $branch doesn't exist on any repository"
- exit 1
+if [[ $CREATE = '' ]]; then
+ if [[ $in_clang = 'no' && $in_clang_extra && $in_llvm = 'no' && \
+ $in_rt = 'no' && $in_cxx = 'no' && $in_cxxabi = 'no' && \
+ $in_unw = 'no' && $in_lld = 'no' && $in_lldb = 'no' ]]; then
+ echo "Branch $branch doesn't exist on any repository"
+ echo "Force its creation with -b"
+ exit 1
+ fi
fi
# DO IT