瀏覽代碼

Add 'ghpc' helper script

Scott Lahteine 5 年之前
父節點
當前提交
6d92a0a33b
共有 2 個文件被更改,包括 73 次插入4 次删除
  1. 5
    4
      buildroot/share/git/README.md
  2. 68
    0
      buildroot/share/git/ghpc

+ 5
- 4
buildroot/share/git/README.md 查看文件

@@ -18,7 +18,7 @@ The following scripts can be used on any system with a GNU environment to speed
18 18
 
19 19
 File|Description
20 20
 ----|-----------
21
-mfadd [user]|Add and Fetch Remote - Add another Github user's fork of Marlin as a remote, then fetch it. Optionally, check out one of their branches.
21
+mfadd [user]|Add and Fetch Remote - Add and fetch another user's Marlin fork. Optionally, check out one of their branches.
22 22
 mfinit|Init Working Copy - Create a remote named '`upstream`' (for use by the other scripts) pointing to the '`MarlinFirmware`' fork. This only needs to be used once. Newer versions of Github Desktop may create `upstream` on your behalf.
23 23
 
24 24
 #### Branches
@@ -41,14 +41,15 @@ mfqp|Quick Patch - Commit all current changes as "patch", then do `mfrb`, follow
41 41
 
42 42
 File|Description
43 43
 ----|-----------
44
-mfdoc|Build the documentation and preview it locally.
45
-mfpub|Build the documentation and publish it to marlinfw.org via Github.
44
+mfdoc|Build the documentation with Jekyll and preview it locally.
45
+mfpub|Build and publish the documentation to marlinfw.org.
46 46
 
47 47
 #### Utilities
48 48
 
49 49
 File|Description
50 50
 ----|-----------
51 51
 ghtp -[h/s]|Set the protocol to use for all remotes. -h for HTTPS, -s for SSL.
52
+ghpc [-f]|Push current branch to 'origin' or to the remote indicated by the error.
52 53
 mfinfo|This utility script is used by the other scripts to get:<br/>- The upstream project ('`MarlinFirmware`')<br/>- the '`origin`' project (i.e., your Github username),<br/>- the repository name ('`Marlin`'),<br/>- the PR target branch ('`bugfix-1.1.x`'), and<br/>- the current branch (or the first command-line argument).<br/><br/>By itself, `mfinfo` simply prints these values to the console.
53 54
 mfclean&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Prune your merged and remotely-deleted branches.
54 55
 
@@ -56,4 +57,4 @@ mfclean&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Prune your merged and remotely-deleted bra
56 57
 
57 58
 ### Examples
58 59
 
59
-Coming Soon!
60
+For a demonstration of these scripts see the video [Marlin Live - May 9 2019](https://youtu.be/rwT4G0uVTIY). There is also an old write-up at [#3193](https://github.com/MarlinFirmware/Marlin/issues/3193).

+ 68
- 0
buildroot/share/git/ghpc 查看文件

@@ -0,0 +1,68 @@
1
+#!/usr/bin/env bash
2
+#
3
+# ghpc (GitHub Push Current)
4
+#
5
+# - Push current branch to its remote. Try the following until it works:
6
+#   - Plain 'git push'
7
+#   - 'git push -f'
8
+#   - Try the 'git push' command from the 'git push' error message
9
+#   - Try adding '-f' to that command
10
+#
11
+
12
+yay() { echo "SUCCESS" ; }
13
+boo() { echo "FAIL" ; }
14
+
15
+FORCE=$([[ "$1" == "--force" || "$1" == "-f" ]] && echo 1)
16
+
17
+if [[ ! $FORCE ]]; then
18
+  echo -n "trying 'git push' ...... "
19
+  git push >/dev/null 2>&1 && { yay ; exit ; }
20
+  boo
21
+fi
22
+
23
+echo -n "trying 'git push -f' ... "
24
+
25
+# Get the error output from the failed push
26
+# and get the recommended 'git push' line
27
+git push -f 2>&1 | {
28
+  CMD=""
29
+
30
+  ltrim() {
31
+    [[ "$1" =~ [^[:space:]].* ]]
32
+    printf "%s" "$BASH_REMATCH"
33
+  }
34
+
35
+  while IFS= read -r line
36
+  do
37
+    #echo "$line"
38
+    if [[ -z "$CMD" && $line =~ "git push" ]]; then
39
+      CMD=$(ltrim "$line")
40
+    fi
41
+  done
42
+
43
+  # if a command was found try it
44
+  if [[ -n "$CMD" ]]; then
45
+
46
+    boo
47
+
48
+    if [[ ! $FORCE ]]; then
49
+      echo -n "trying '$CMD' ...... "
50
+      $CMD >/dev/null 2>&1 && { yay ; exit ; }
51
+      boo
52
+    fi
53
+
54
+    fCMD=${CMD/ push / push -f }
55
+    echo -n "trying '$fCMD' ... "
56
+    $fCMD >/dev/null 2>&1 && { yay ; exit ; }
57
+    boo
58
+
59
+    exit 1
60
+
61
+  else
62
+
63
+    yay
64
+
65
+  fi
66
+}
67
+
68
+[[ ${PIPESTATUS[1]} == 1 ]] && echo "Sorry! Failed to push current branch."

Loading…
取消
儲存