Browse Source

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 years ago
parent
commit
1af05797d7
1 changed files with 12 additions and 8 deletions
  1. 12
    8
      buildroot/share/git/mfadd

+ 12
- 8
buildroot/share/git/mfadd View File

1
 #!/usr/bin/env bash
1
 #!/usr/bin/env bash
2
 #
2
 #
3
-# mfadd (user|ref) [copyname]
3
+# mfadd user[:branch] [copyname]
4
 #
4
 #
5
 # Add a remote and fetch it. Optionally copy a branch.
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
   USER=${DATA[0]}
19
   USER=${DATA[0]}
16
   BRANCH=${DATA[1]}
20
   BRANCH=${DATA[1]}
17
-  NAME=$2
21
+  NAME=${2:-$BRANCH}
18
 else
22
 else
19
   USER=$1
23
   USER=$1
20
 fi
24
 fi
29
 git remote add "$USER" "git@github.com:$USER/$REPO.git" >/dev/null 2>&1 || echo "Remote exists."
33
 git remote add "$USER" "git@github.com:$USER/$REPO.git" >/dev/null 2>&1 || echo "Remote exists."
30
 git fetch "$USER"
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"

Loading…
Cancel
Save