Переглянути джерело

Improve mfadd helper script

- Use the original branch name if none is supplied
- Set the remote tracking to the source
- Accept User/Branch or User:Branch syntax
Scott Lahteine 4 роки тому
джерело
коміт
1af05797d7
1 змінених файлів з 12 додано та 8 видалено
  1. 12
    8
      buildroot/share/git/mfadd

+ 12
- 8
buildroot/share/git/mfadd Переглянути файл

@@ -1,20 +1,24 @@
1 1
 #!/usr/bin/env bash
2 2
 #
3
-# mfadd (user|ref) [copyname]
3
+# mfadd user[:branch] [copyname]
4 4
 #
5 5
 # Add a remote and fetch it. Optionally copy a branch.
6 6
 #
7
-# Example: mfadd myfork:patch-1 copy_of_patch-1
7
+# Examples:
8
+#  mfadd thefork
9
+#  mfadd thefork:patch-1
10
+#  mfadd thefork:patch-1 the_patch_12345
8 11
 #
9 12
 
10
-[[ $# > 0 && $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` (user|ref) [copyname]" 1>&2 ; exit 1; }
13
+[[ $# > 0 && $# < 3 && $1 != "-h" && $1 != "--help" ]] || { echo "usage: `basename $0` user[:branch] [copyname]" 1>&2 ; exit 1; }
11 14
 
12
-# If a colon is included, split the parts
13
-if [[ $1 =~ ":" ]]; then
14
-  IFS=':' read -a DATA <<< "$1"
15
+# If a colon or slash is included, split the parts
16
+if [[ $1 =~ ":" || $1 =~ "/" ]]; then
17
+  [[ $1 =~ ":" ]] && IFS=':' || IFS="/"
18
+  read -a DATA <<< "$1"
15 19
   USER=${DATA[0]}
16 20
   BRANCH=${DATA[1]}
17
-  NAME=$2
21
+  NAME=${2:-$BRANCH}
18 22
 else
19 23
   USER=$1
20 24
 fi
@@ -29,4 +33,4 @@ echo "Adding and fetching $USER..."
29 33
 git remote add "$USER" "git@github.com:$USER/$REPO.git" >/dev/null 2>&1 || echo "Remote exists."
30 34
 git fetch "$USER"
31 35
 
32
-[[ ! -z "$BRANCH" && ! -z "$NAME" ]] && git checkout $USER/$BRANCH -b $NAME
36
+[[ ! -z "$BRANCH" && ! -z "$NAME" ]] && git checkout -b "$NAME" --track "$USER/$BRANCH"

Завантаження…
Відмінити
Зберегти