File tree 1 file changed +45
-0
lines changed
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # Creates new worktrees for all IntelliJ IDEA repositories pointing to a new release branch.
3
+ # Usage: ./cloneToWt.sh <target directory> <branch>
4
+ # Restrictions:
5
+ # None of the given Git repositories should have the branch with name <branch>.
6
+ # There should be a remote branch origin/<branch> from which a new local branch will be created by this script.
7
+ # You must use Git 2.5.0 or later.
8
+
9
+ set -e # Any command which returns non-zero exit code will cause this shell script to exit immediately
10
+
11
+ if [[ -z " $1 " || -z " $2 " ]] ; then
12
+ echo "
13
+ Usage: ./cloneToWt.sh <target directory> <branch>
14
+ Example: ./cloneToWt.sh ~/intellij-go-143 143"
15
+ exit 1
16
+ fi
17
+
18
+ NEW_REPO=" $1 "
19
+ BRANCH=" $2 "
20
+
21
+ if [[ " $BRANCH " == origin/* ]]; then
22
+ BRANCH=" ${BRANCH/ origin\/ / } "
23
+ fi
24
+
25
+ # Absolute path to directory containing existing IntelliJ IDEA repo (and this script as well)
26
+ OLD_REPO=" $( cd " ` dirname " $0 " ` " ; pwd) "
27
+ ROOTS=(" /" )
28
+
29
+ if [ -d " $NEW_REPO " ]; then
30
+ echo " Directory '$NEW_REPO ' already exists"
31
+ exit 2
32
+ fi
33
+
34
+ for ROOT in ${ROOTS[@]} ; do
35
+ if [[ ! -z ` git --git-dir=" ${OLD_REPO}${ROOT} /.git" --work-tree=" ${OLD_REPO}${ROOT} " branch --list $BRANCH ` ]]; then
36
+ echo " Branch '$BRANCH ' already exists in $ROOT "
37
+ exit 3
38
+ fi
39
+ done
40
+
41
+ for ROOT in ${ROOTS[@]} ; do
42
+ git --git-dir=" ${OLD_REPO}${ROOT} /.git" --work-tree=" ${OLD_REPO}${ROOT} " worktree add -b $BRANCH " ${NEW_REPO}${ROOT} " origin/${BRANCH}
43
+ done
44
+
45
+ cp -a " $OLD_REPO /.idea/workspace.xml" " $NEW_REPO /.idea/"
You can’t perform that action at this time.
0 commit comments