Browse Source

Git helper shell scripts for MarlinFirmware

Scott Lahteine 8 years ago
parent
commit
9a12054e0e
7 changed files with 202 additions and 0 deletions
  1. 3
    0
      Marlin/scripts/firstpush
  2. 40
    0
      Marlin/scripts/mfinfo
  3. 23
    0
      Marlin/scripts/mfnew
  4. 40
    0
      Marlin/scripts/mfpr
  5. 22
    0
      Marlin/scripts/mfprune
  6. 21
    0
      Marlin/scripts/mfrb
  7. 53
    0
      Marlin/scripts/mfup

+ 3
- 0
Marlin/scripts/firstpush View File

@@ -0,0 +1,3 @@
1
+#!/usr/bin/env bash
2
+
3
+git push --set-upstream origin `git branch | grep \* | sed 's/\* //g'`

+ 40
- 0
Marlin/scripts/mfinfo View File

@@ -0,0 +1,40 @@
1
+#!/usr/bin/env bash
2
+#
3
+# mfinfo
4
+#
5
+# Get the following helpful git info about the working directory:
6
+#
7
+#   - Remote (upstream) Org name (MarlinFirmware)
8
+#   - Remote (origin) Org name (your Github username)
9
+#   - Repo Name (Marlin or MarlinDev)
10
+#   - Marlin Target branch (RCBugFix or dev)
11
+#   - Branch Name (the current branch or the one that was passed)
12
+#
13
+
14
+REPO=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*\/(.*)\.git/\1/')
15
+
16
+if [[ -z $REPO ]]; then
17
+  echo "`basename $0`: No 'upstream' remote found." 1>&2 ; exit 1
18
+fi
19
+
20
+ORG=$(git remote get-url upstream 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
21
+
22
+if [[ $ORG != MarlinFirmware ]]; then
23
+  echo "`basename $0`: Not a Marlin repository."
24
+  exit 1
25
+fi
26
+
27
+case "$REPO" in
28
+  Marlin    ) TARG=RCBugFix ;;
29
+  MarlinDev ) TARG=dev ;;
30
+esac
31
+
32
+FORK=$(git remote get-url origin 2>/dev/null | sed -E 's/.*[\/:](.*)\/.*$/\1/')
33
+
34
+case "$#" in
35
+  0 ) BRANCH=$(git branch 2>/dev/null | grep ^* | sed 's/\* //g') ;;
36
+  1 ) BRANCH=$1 ;;
37
+  * ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
38
+esac
39
+
40
+echo "$ORG $FORK $REPO $TARG $BRANCH"

+ 23
- 0
Marlin/scripts/mfnew View File

@@ -0,0 +1,23 @@
1
+#!/usr/bin/env bash
2
+#
3
+# mfnew
4
+#
5
+# Create a new branch based on RCBugFix or dev a given branch name
6
+#
7
+
8
+MFINFO=$(mfinfo) || exit
9
+IFS=' ' read -a INFO <<< "$MFINFO"
10
+TARG=${INFO[3]}
11
+
12
+if [[ ${INFO[4]} == "(no" ]]; then
13
+  echo "Branch is unavailable!"
14
+  exit 1
15
+fi
16
+
17
+case "$#" in
18
+  0 ) BRANCH=pr_for_$TARG-$(date +"%G-%d-%m|%H:%M:%S") ;;
19
+  1 ) BRANCH=$1 ;;
20
+  * ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
21
+esac
22
+
23
+git checkout $TARG -b $BRANCH

+ 40
- 0
Marlin/scripts/mfpr View File

@@ -0,0 +1,40 @@
1
+#!/usr/bin/env bash
2
+#
3
+# mfpr
4
+#
5
+# Make a PR of the current branch against RCBugFix or dev
6
+#
7
+
8
+MFINFO=$(mfinfo "$@") || exit
9
+
10
+IFS=' ' read -a INFO <<< "$MFINFO"
11
+
12
+ORG=${INFO[0]}
13
+FORK=${INFO[1]}
14
+REPO=${INFO[2]}
15
+TARG=${INFO[3]}
16
+BRANCH=${INFO[4]}
17
+
18
+if [[ $BRANCH == "(no" ]]; then
19
+  echo "Git is busy with merge, rebase, etc."
20
+  exit 1
21
+fi
22
+
23
+if [[ ! -z "$1" ]]; then { BRANCH=$1 ; git checkout $1 || exit 1; } fi
24
+
25
+if [[ $BRANCH == $TARG ]]; then
26
+  echo "Can't make a PR from $BRANCH" ; exit
27
+fi
28
+
29
+if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then firstpush; fi
30
+
31
+TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
32
+URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
33
+
34
+if [ -z "$TOOL" ]; then
35
+  echo "Can't find a tool to open the URL:"
36
+  echo $URL
37
+else
38
+  echo "Opening a New PR Form..."
39
+  "$TOOL" "$URL"
40
+fi

+ 22
- 0
Marlin/scripts/mfprune View File

@@ -0,0 +1,22 @@
1
+#!/usr/bin/env bash
2
+#
3
+# mfprune
4
+#
5
+# Prune all your merged branches and any branches whose remotes are gone
6
+# Great way to clean up your branches after messing around a lot
7
+#
8
+
9
+echo "Pruning Merged Branches..."
10
+git branch --merged | egrep -v "^\*|RC|RCBugFix|dev" | xargs -n 1 git branch -d
11
+echo
12
+
13
+echo "Pruning Remotely-deleted Branches..."
14
+git branch -vv | egrep -v "^\*|RC|RCBugFix|dev" | grep ': gone]' | gawk '{print $1}' | xargs -n 1 git branch -D
15
+echo
16
+
17
+echo "You may want to remove these remote tracking references..."
18
+comm -23 \
19
+  <(git branch --all | sed 's/^[\* ] //' | grep origin/ | grep -v "\->" | awk '{ print $1; }' | sed 's/remotes\/origin\///') \
20
+  <(git branch --all | sed 's/^[\* ] //' | grep -v remotes/ | awk '{ print $1; }') \
21
+  | awk '{ print "git branch -d -r origin/" $1; }'
22
+echo

+ 21
- 0
Marlin/scripts/mfrb View File

@@ -0,0 +1,21 @@
1
+#!/usr/bin/env bash
2
+#
3
+# mfrb
4
+#
5
+# Do "git rebase -i" against the "target" branch (RCBugFix or dev)
6
+#
7
+
8
+MFINFO=$(mfinfo) || exit
9
+IFS=' ' read -a INFO <<< "$MFINFO"
10
+
11
+if [[ ${INFO[4]} == "(no" ]]; then
12
+  echo "Branch is unavailable!"
13
+  exit 1
14
+fi
15
+
16
+case "$#" in
17
+  0 ) ;;
18
+  * ) echo "Usage: `basename $0`" 1>&2 ; exit 1 ;;
19
+esac
20
+
21
+git rebase -i ${INFO[3]}

+ 53
- 0
Marlin/scripts/mfup View File

@@ -0,0 +1,53 @@
1
+#!/usr/bin/env bash
2
+#
3
+# mfup
4
+#
5
+# Fetch and merge upstream changes, optionally with a branch
6
+#
7
+
8
+MFINFO=$(mfinfo) || exit
9
+
10
+IFS=' ' read -a INFO <<< "$MFINFO"
11
+
12
+ORG=${INFO[0]}
13
+FORK=${INFO[1]}
14
+REPO=${INFO[2]}
15
+TARG=${INFO[3]}
16
+OLDBRANCH=${INFO[4]}
17
+
18
+if [[ $OLDBRANCH == "(no" ]]; then
19
+  echo "Branch is unavailable!"
20
+  exit 1
21
+fi
22
+
23
+case "$#" in
24
+  0 ) BRANCH=$OLDBRANCH ;;
25
+  1 ) BRANCH=$1 ;;
26
+  * ) echo "Usage: `basename $0` [branch]" 1>&2 ; exit 1 ;;
27
+esac
28
+
29
+set -e
30
+
31
+echo "Fetching upstream ($ORG/$REPO)..."
32
+git fetch upstream
33
+
34
+echo ; echo "Bringing $TARG up to date..."
35
+git checkout -q $TARG || git branch checkout upstream/$TARG -b $TARG && git push --set-upstream origin $TARG
36
+git merge upstream/$TARG
37
+git push origin
38
+
39
+if [[ $BRANCH != $TARG ]]; then
40
+  echo ; echo "Rebasing $BRANCH on $TARG..."
41
+  if git checkout $BRANCH; then
42
+    echo
43
+    if git rebase $TARG; then
44
+      git push -f ; echo
45
+      [[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH
46
+    else
47
+      echo "Looks like merge conflicts. Stopping here."
48
+    fi
49
+  else
50
+    echo "No such branch!" ; echo
51
+    git checkout $OLDBRANCH
52
+  fi
53
+fi

Loading…
Cancel
Save