eac_launcher 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/lib/eac_launcher.rb +3 -0
  3. data/lib/eac_launcher/version.rb +1 -1
  4. data/vendor/git-subrepo/Changes +51 -0
  5. data/vendor/git-subrepo/Intro.pod +508 -0
  6. data/vendor/git-subrepo/License +21 -0
  7. data/vendor/git-subrepo/Makefile +80 -0
  8. data/vendor/git-subrepo/Meta +28 -0
  9. data/vendor/git-subrepo/ReadMe.pod +695 -0
  10. data/vendor/git-subrepo/doc/comparison.swim +35 -0
  11. data/vendor/git-subrepo/doc/git-subrepo.swim +611 -0
  12. data/vendor/git-subrepo/doc/intro-to-subrepo.swim +387 -0
  13. data/vendor/git-subrepo/ext/bashplus/Changes +15 -0
  14. data/vendor/git-subrepo/ext/bashplus/License +21 -0
  15. data/vendor/git-subrepo/ext/bashplus/Makefile +45 -0
  16. data/vendor/git-subrepo/ext/bashplus/Meta +28 -0
  17. data/vendor/git-subrepo/ext/bashplus/ReadMe.pod +77 -0
  18. data/vendor/git-subrepo/ext/bashplus/bin/bash+ +43 -0
  19. data/vendor/git-subrepo/ext/bashplus/doc/bash+.swim +61 -0
  20. data/vendor/git-subrepo/ext/bashplus/lib/bash+.bash +92 -0
  21. data/vendor/git-subrepo/ext/bashplus/man/man1/bash+.1 +134 -0
  22. data/vendor/git-subrepo/ext/bashplus/man/man3/bash+.3 +134 -0
  23. data/vendor/git-subrepo/ext/bashplus/test/base.t +12 -0
  24. data/vendor/git-subrepo/ext/bashplus/test/fcopy.t +22 -0
  25. data/vendor/git-subrepo/ext/bashplus/test/lib/foo/bar.bash +3 -0
  26. data/vendor/git-subrepo/ext/bashplus/test/lib/foo/foo.bash +3 -0
  27. data/vendor/git-subrepo/ext/bashplus/test/source-bash+-std.t +18 -0
  28. data/vendor/git-subrepo/ext/bashplus/test/source-bash+.t +23 -0
  29. data/vendor/git-subrepo/ext/bashplus/test/test.bash +70 -0
  30. data/vendor/git-subrepo/ext/bashplus/test/use.t +19 -0
  31. data/vendor/git-subrepo/ext/test-more-bash/Changes +15 -0
  32. data/vendor/git-subrepo/ext/test-more-bash/License +21 -0
  33. data/vendor/git-subrepo/ext/test-more-bash/Makefile +20 -0
  34. data/vendor/git-subrepo/ext/test-more-bash/Meta +30 -0
  35. data/vendor/git-subrepo/ext/test-more-bash/ReadMe.pod +115 -0
  36. data/vendor/git-subrepo/ext/test-more-bash/doc/test-more.swim +89 -0
  37. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/Changes +15 -0
  38. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/License +21 -0
  39. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/Makefile +45 -0
  40. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/Meta +28 -0
  41. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/ReadMe.pod +77 -0
  42. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/bin/bash+ +43 -0
  43. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/doc/bash+.swim +61 -0
  44. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/lib/bash+.bash +92 -0
  45. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/man/man1/bash+.1 +134 -0
  46. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/man/man3/bash+.3 +134 -0
  47. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/base.t +12 -0
  48. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/fcopy.t +22 -0
  49. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/lib/foo/bar.bash +3 -0
  50. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/lib/foo/foo.bash +3 -0
  51. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/source-bash+-std.t +18 -0
  52. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/source-bash+.t +23 -0
  53. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/test.bash +70 -0
  54. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/use.t +19 -0
  55. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/Changes +15 -0
  56. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/License +21 -0
  57. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/Makefile +37 -0
  58. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/Meta +28 -0
  59. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/ReadMe.pod +66 -0
  60. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/doc/test-tap.swim +48 -0
  61. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/lib/test/tap.bash +153 -0
  62. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/man/man3/test-tap.3 +119 -0
  63. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/bail_out.t +13 -0
  64. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/done.t +10 -0
  65. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/fail.t +20 -0
  66. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/fail_fast.t +15 -0
  67. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/helper.bash +9 -0
  68. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/pass.t +9 -0
  69. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/plan.t +10 -0
  70. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/skip_all.t +20 -0
  71. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/tap.t +13 -0
  72. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/test/bail.t +14 -0
  73. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/test/fail.t +7 -0
  74. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/test/fail_fast.t +12 -0
  75. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/test/skip-all-init.t +8 -0
  76. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/test/skip-all-plan.t +9 -0
  77. data/vendor/git-subrepo/ext/test-more-bash/lib/test/more.bash +95 -0
  78. data/vendor/git-subrepo/ext/test-more-bash/man/man3/test-more.3 +173 -0
  79. data/vendor/git-subrepo/ext/test-more-bash/test/fail.t +20 -0
  80. data/vendor/git-subrepo/ext/test-more-bash/test/more.t +20 -0
  81. data/vendor/git-subrepo/ext/test-more-bash/test/pass.t +9 -0
  82. data/vendor/git-subrepo/ext/test-more-bash/test/setup +8 -0
  83. data/vendor/git-subrepo/ext/test-more-bash/test/skip_all.t +11 -0
  84. data/vendor/git-subrepo/ext/test-more-bash/test/test/fail1.t +12 -0
  85. data/vendor/git-subrepo/ext/test-more-bash/test/test/skip_all.t +10 -0
  86. data/vendor/git-subrepo/lib/git-subrepo +1891 -0
  87. data/vendor/git-subrepo/lib/git-subrepo.d/bash+.bash +1 -0
  88. data/vendor/git-subrepo/lib/git-subrepo.d/help-functions.bash +343 -0
  89. data/vendor/git-subrepo/man/man1/git-subrepo.1 +746 -0
  90. data/vendor/git-subrepo/note/0.4.0 +12 -0
  91. data/vendor/git-subrepo/note/AllGitCmds +148 -0
  92. data/vendor/git-subrepo/note/Cases +32 -0
  93. data/vendor/git-subrepo/note/Commands +33 -0
  94. data/vendor/git-subrepo/note/Dags +199 -0
  95. data/vendor/git-subrepo/note/Gists +7 -0
  96. data/vendor/git-subrepo/note/Links +25 -0
  97. data/vendor/git-subrepo/note/Plugins +10 -0
  98. data/vendor/git-subrepo/note/Spec +39 -0
  99. data/vendor/git-subrepo/note/Story1 +57 -0
  100. data/vendor/git-subrepo/note/ToDo +55 -0
  101. data/vendor/git-subrepo/note/design.swim +137 -0
  102. data/vendor/git-subrepo/note/design2.swim +85 -0
  103. data/vendor/git-subrepo/note/init-test +38 -0
  104. data/vendor/git-subrepo/note/pull-dance.txt +18 -0
  105. data/vendor/git-subrepo/note/recreate-rebase-conflict.sh +56 -0
  106. data/vendor/git-subrepo/note/subtree-rebase-fail-example/test.bash +29 -0
  107. data/vendor/git-subrepo/note/test-subrepo-push.sh +69 -0
  108. data/vendor/git-subrepo/note/test.sh +58 -0
  109. data/vendor/git-subrepo/pkg/bin/generate-completion.pl +210 -0
  110. data/vendor/git-subrepo/pkg/bin/generate-help-functions.pl +89 -0
  111. data/vendor/git-subrepo/share/completion.bash +42 -0
  112. data/vendor/git-subrepo/share/enable-completion.sh +50 -0
  113. data/vendor/git-subrepo/share/git-completion.bash +2738 -0
  114. data/vendor/git-subrepo/share/zsh-completion/_git-subrepo +82 -0
  115. data/vendor/git-subrepo/test/branch-all.t +41 -0
  116. data/vendor/git-subrepo/test/branch-rev-list-one-path.t +43 -0
  117. data/vendor/git-subrepo/test/branch-rev-list.t +47 -0
  118. data/vendor/git-subrepo/test/branch.t +52 -0
  119. data/vendor/git-subrepo/test/clean.t +43 -0
  120. data/vendor/git-subrepo/test/clone-annotated-tag.t +45 -0
  121. data/vendor/git-subrepo/test/clone.t +107 -0
  122. data/vendor/git-subrepo/test/compile.t +19 -0
  123. data/vendor/git-subrepo/test/config.t +58 -0
  124. data/vendor/git-subrepo/test/encode.t +91 -0
  125. data/vendor/git-subrepo/test/error.t +171 -0
  126. data/vendor/git-subrepo/test/fetch.t +43 -0
  127. data/vendor/git-subrepo/test/gitignore.t +61 -0
  128. data/vendor/git-subrepo/test/init.t +64 -0
  129. data/vendor/git-subrepo/test/issue29.t +98 -0
  130. data/vendor/git-subrepo/test/issue95.t +98 -0
  131. data/vendor/git-subrepo/test/issue96.t +96 -0
  132. data/vendor/git-subrepo/test/pull-all.t +38 -0
  133. data/vendor/git-subrepo/test/pull-merge.t +113 -0
  134. data/vendor/git-subrepo/test/pull-message.t +88 -0
  135. data/vendor/git-subrepo/test/pull-new-branch.t +58 -0
  136. data/vendor/git-subrepo/test/pull-ours.t +90 -0
  137. data/vendor/git-subrepo/test/pull-theirs.t +82 -0
  138. data/vendor/git-subrepo/test/pull-twice.t +44 -0
  139. data/vendor/git-subrepo/test/pull.t +99 -0
  140. data/vendor/git-subrepo/test/push-after-init.t +51 -0
  141. data/vendor/git-subrepo/test/push-force.t +56 -0
  142. data/vendor/git-subrepo/test/push-new-branch.t +61 -0
  143. data/vendor/git-subrepo/test/push-no-changes.t +29 -0
  144. data/vendor/git-subrepo/test/push-squash.t +56 -0
  145. data/vendor/git-subrepo/test/push.t +176 -0
  146. data/vendor/git-subrepo/test/reclone.t +45 -0
  147. data/vendor/git-subrepo/test/repo/bar/HEAD +1 -0
  148. data/vendor/git-subrepo/test/repo/bar/config +4 -0
  149. data/vendor/git-subrepo/test/repo/bar/objects/1f/0c4b264caed0126814a0ede851a1e0b4e16ae6 +0 -0
  150. data/vendor/git-subrepo/test/repo/bar/objects/87/46903fdb1b9c2101377880125917c2e05b4d69 +0 -0
  151. data/vendor/git-subrepo/test/repo/bar/objects/94/c86ffc745232d89f78c6f895e11e71272518db +0 -0
  152. data/vendor/git-subrepo/test/repo/bar/objects/c6/76c57b6576743fa56278527aa60ebd2e202a7c +0 -0
  153. data/vendor/git-subrepo/test/repo/bar/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
  154. data/vendor/git-subrepo/test/repo/bar/objects/f6/2a8ff3feadf39b0a98f1a86ec6d1eb33858ee9 +0 -0
  155. data/vendor/git-subrepo/test/repo/bar/refs/heads/master +1 -0
  156. data/vendor/git-subrepo/test/repo/bar/refs/tags/A +1 -0
  157. data/vendor/git-subrepo/test/repo/foo/HEAD +1 -0
  158. data/vendor/git-subrepo/test/repo/foo/config +4 -0
  159. data/vendor/git-subrepo/test/repo/foo/objects/a0/f4cdaaf533a936296cdebbed8206c3b9ededa8 +0 -0
  160. data/vendor/git-subrepo/test/repo/foo/objects/e2/1291a1ad392a9d4c51dd9586804f1467b28afd +0 -0
  161. data/vendor/git-subrepo/test/repo/foo/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
  162. data/vendor/git-subrepo/test/repo/foo/refs/heads/master +1 -0
  163. data/vendor/git-subrepo/test/repo/init/HEAD +1 -0
  164. data/vendor/git-subrepo/test/repo/init/config +5 -0
  165. data/vendor/git-subrepo/test/repo/init/objects/11/523f5dcf03b4c89b592dc8a3d0308f68da2386 +0 -0
  166. data/vendor/git-subrepo/test/repo/init/objects/14/2addf8ec5f37334e837440122c62f2c68a29ad +0 -0
  167. data/vendor/git-subrepo/test/repo/init/objects/32/5180321750a21cd7a4e7ecda319e557a4f6a09 +2 -0
  168. data/vendor/git-subrepo/test/repo/init/objects/3d/918c6901c02f43af5d31779dd5e1f9166aeb36 +0 -0
  169. data/vendor/git-subrepo/test/repo/init/objects/3e/4cb596066dce63ba4d047abddb677389b65e19 +0 -0
  170. data/vendor/git-subrepo/test/repo/init/objects/4b/6e53022e7a04f07887697e4f3d7c377fd9822b +0 -0
  171. data/vendor/git-subrepo/test/repo/init/objects/58/931fc1bd559b59c41ea738fc7ad04f9ad01bd3 +0 -0
  172. data/vendor/git-subrepo/test/repo/init/objects/5e/c0c28e1b806f25efdca18fcf7a74b49c3755bd +0 -0
  173. data/vendor/git-subrepo/test/repo/init/objects/75/fa6584e748f57eff06eebdc55e9ac21d4fcbf2 +1 -0
  174. data/vendor/git-subrepo/test/repo/init/objects/80/2d5edbd5e1cb7fca82b5bd38e7c8a0a496fb20 +0 -0
  175. data/vendor/git-subrepo/test/repo/init/objects/94/7b3d714c38791e95ad6f928b48c98bb8708acd +0 -0
  176. data/vendor/git-subrepo/test/repo/init/objects/95/e1f2df3f4d5f3d7a60588c25a7ca8a913d3c2a +1 -0
  177. data/vendor/git-subrepo/test/repo/init/objects/b1/5f4a7666baf40d949548ead946a3370e273479 +0 -0
  178. data/vendor/git-subrepo/test/repo/init/objects/c3/ee8978c4c5d84c3b7d00ba8e5906933d027882 +0 -0
  179. data/vendor/git-subrepo/test/repo/init/objects/c8/b0bffbc405ef3fad7354ff833fbec36d67ddfa +3 -0
  180. data/vendor/git-subrepo/test/repo/init/objects/dd/8bdb934ec848137f011fe423b185505c343626 +2 -0
  181. data/vendor/git-subrepo/test/repo/init/objects/e2/9be58c767cfeb27235c995d293a7d71aac0135 +2 -0
  182. data/vendor/git-subrepo/test/repo/init/objects/ee/1224401fc6aac595145fa727dcf6706ac8aec1 +1 -0
  183. data/vendor/git-subrepo/test/repo/init/objects/f1/cc1a657b2e805c400f5dcaaa76bd29c6178b1b +0 -0
  184. data/vendor/git-subrepo/test/repo/init/refs/heads/master +1 -0
  185. data/vendor/git-subrepo/test/setup +205 -0
  186. data/vendor/git-subrepo/test/status.t +68 -0
  187. data/vendor/git-subrepo/test/submodule.t +45 -0
  188. metadata +186 -2
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source lib/test/tap.bash
4
+
5
+ Test::Tap:init tests 5
6
+
7
+ Test::Tap:pass 'test #1'
8
+ Test::Tap:pass 'test #2'
9
+ Test::Tap:pass 'test #3'
10
+
11
+ Test::Tap:BAIL_OUT 'Get me outta here'
12
+
13
+ Test::Tap:pass 'test #4'
14
+ Test::Tap:fail 'test #5'
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source lib/test/tap.bash
4
+
5
+ Test::Tap:init tests 1
6
+
7
+ Test::Tap:fail 'I am a failure'
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source lib/test/tap.bash
4
+
5
+ Test::Tap:init tests 5
6
+ Test::Tap:BAIL_ON_FAIL
7
+
8
+ Test::Tap:pass 'test #1'
9
+ Test::Tap:pass 'test #2'
10
+ Test::Tap:fail 'test #3'
11
+ Test::Tap:pass 'test #4'
12
+ Test::Tap:pass 'test #5'
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source lib/test/tap.bash
4
+
5
+ Test::Tap:init skip_all 'Test for skip_all from init'
6
+
7
+ Test::Tap:diag "This code should not be run"
8
+ Test::Tap:fail
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source lib/test/tap.bash
4
+
5
+ Test::Tap:init
6
+ Test::Tap:plan skip_all 'Test for skip_all from plan'
7
+
8
+ Test::Tap:diag "This code should not be run"
9
+ Test::Tap:fail
@@ -0,0 +1,95 @@
1
+ # test/more.bash - Complete TAP test framework for Bash
2
+ #
3
+ # Copyright (c) 2013-2016. Ingy döt Net.
4
+
5
+ set -e
6
+
7
+ Test__More_VERSION=0.0.3
8
+
9
+ source bash+ :std
10
+ use Test::Tap
11
+
12
+ Test::More:import() { Test::Tap:init "$@"; }
13
+
14
+ plan() { Test::Tap:plan "$@"; }
15
+ pass() { Test::Tap:pass "$@"; }
16
+ fail() { Test::Tap:fail "$@"; }
17
+ diag() { Test::Tap:diag "$@"; }
18
+ note() { Test::Tap:note "$@"; }
19
+ done_testing() { Test::Tap:done_testing "$@"; }
20
+ BAIL_OUT() { Test::Tap:BAIL_OUT "$@"; }
21
+ BAIL_ON_FAIL() { Test::Tap:BAIL_ON_FAIL "$@"; }
22
+
23
+ is() {
24
+ local got="$1" want="$2" label="$3"
25
+ if [[ $got == "$want" ]]; then
26
+ Test::Tap:pass "$label"
27
+ else
28
+ Test::Tap:fail "$label" Test::More:is-fail
29
+ fi
30
+ }
31
+
32
+ Test::More:is-fail() {
33
+ local Test__Tap_CALL_STACK_LEVEL=
34
+ Test__Tap_CALL_STACK_LEVEL=$(( Test__Tap_CALL_STACK_LEVEL + 1 ))
35
+ if [[ "$want" =~ \n ]]; then
36
+ echo "$got" > /tmp/got-$$
37
+ echo "$want" > /tmp/want-$$
38
+ diff -u /tmp/{want,got}-$$ >&2
39
+ wc /tmp/{want,got}-$$ >&2
40
+ rm -f /tmp/{got,want}-$$
41
+ else
42
+ Test::Tap:diag "\
43
+ got: '$got'
44
+ expected: '$want'"
45
+ fi
46
+ }
47
+
48
+ isnt() {
49
+ local Test__Tap_CALL_STACK_LEVEL=
50
+ Test__Tap_CALL_STACK_LEVEL=$(( Test__Tap_CALL_STACK_LEVEL + 1 ))
51
+ local got="$1" dontwant="$2" label="$3"
52
+ if [[ $got != "$dontwant" ]]; then
53
+ Test::Tap:pass "$label"
54
+ else
55
+ Test::Tap:fail "$label" Test::More:isnt-fail
56
+ fi
57
+ }
58
+
59
+ Test::More:isnt-fail() {
60
+ Test::Tap:diag "\
61
+ got: '$got'
62
+ expected: anything else"
63
+ }
64
+
65
+ ok() {
66
+ (exit ${1:-$?}) &&
67
+ Test::Tap:pass "$2" ||
68
+ Test::Tap:fail "$2"
69
+ }
70
+
71
+ like() {
72
+ local got=$1 regex=$2 label=$3
73
+ if [[ $got =~ "$regex" ]]; then
74
+ Test::Tap:pass "$label"
75
+ else
76
+ Test::Tap:fail "$label" Test::More:like-fail
77
+ fi
78
+ }
79
+
80
+ Test::More:like-fail() {
81
+ Test::Tap:diag "Got: '$got'"
82
+ }
83
+
84
+ unlike() {
85
+ local got=$1 regex=$2 label=$3
86
+ if [[ ! $got =~ "$regex" ]]; then
87
+ Test::Tap:pass "$label"
88
+ else
89
+ Test::Tap:fail "$label" Test::More:unlike-fail
90
+ fi
91
+ }
92
+
93
+ Test::More:unlike-fail() {
94
+ Test::Tap:diag "Got: '$got'"
95
+ }
@@ -0,0 +1,173 @@
1
+ .\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28)
2
+ .\"
3
+ .\" Standard preamble:
4
+ .\" ========================================================================
5
+ .de Sp \" Vertical space (when we can't use .PP)
6
+ .if t .sp .5v
7
+ .if n .sp
8
+ ..
9
+ .de Vb \" Begin verbatim text
10
+ .ft CW
11
+ .nf
12
+ .ne \\$1
13
+ ..
14
+ .de Ve \" End verbatim text
15
+ .ft R
16
+ .fi
17
+ ..
18
+ .\" Set up some character translations and predefined strings. \*(-- will
19
+ .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20
+ .\" double quote, and \*(R" will give a right double quote. \*(C+ will
21
+ .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
22
+ .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
23
+ .\" nothing in troff, for use with C<>.
24
+ .tr \(*W-
25
+ .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
26
+ .ie n \{\
27
+ . ds -- \(*W-
28
+ . ds PI pi
29
+ . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30
+ . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
31
+ . ds L" ""
32
+ . ds R" ""
33
+ . ds C` ""
34
+ . ds C' ""
35
+ 'br\}
36
+ .el\{\
37
+ . ds -- \|\(em\|
38
+ . ds PI \(*p
39
+ . ds L" ``
40
+ . ds R" ''
41
+ . ds C`
42
+ . ds C'
43
+ 'br\}
44
+ .\"
45
+ .\" Escape single quotes in literal strings from groff's Unicode transform.
46
+ .ie \n(.g .ds Aq \(aq
47
+ .el .ds Aq '
48
+ .\"
49
+ .\" If the F register is turned on, we'll generate index entries on stderr for
50
+ .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
51
+ .\" entries marked with X<> in POD. Of course, you'll have to process the
52
+ .\" output yourself in some meaningful fashion.
53
+ .\"
54
+ .\" Avoid warning from groff about undefined register 'F'.
55
+ .de IX
56
+ ..
57
+ .nr rF 0
58
+ .if \n(.g .if rF .nr rF 1
59
+ .if (\n(rF:(\n(.g==0)) \{
60
+ . if \nF \{
61
+ . de IX
62
+ . tm Index:\\$1\t\\n%\t"\\$2"
63
+ ..
64
+ . if !\nF==2 \{
65
+ . nr % 0
66
+ . nr F 2
67
+ . \}
68
+ . \}
69
+ .\}
70
+ .rr rF
71
+ .\" ========================================================================
72
+ .\"
73
+ .IX Title "Test::More 1"
74
+ .TH Test::More 1 "January 2016" "Generated by Swim v0.1.41" "\s-1TAP\s0 Testing for Bash"
75
+ .\" For nroff, turn off justification. Always turn off hyphenation; it makes
76
+ .\" way too many mistakes in technical documents.
77
+ .if n .ad l
78
+ .nh
79
+ .SH "Name"
80
+ .IX Header "Name"
81
+ Test::More \- \s-1TAP\s0 Testing for Bash
82
+ .SH "Synopsis"
83
+ .IX Header "Synopsis"
84
+ Write a test file like this. Maybe call it \f(CW\*(C`test/test.t\*(C'\fR:
85
+ .PP
86
+ .Vb 1
87
+ \& #!/usr/bin/env bash
88
+ \&
89
+ \& TEST_MORE_PATH="/path/to/test\-more\-bash"
90
+ \& BASHLIB="\`
91
+ \& find $TEST_MORE_PATH \-type d |
92
+ \& grep \-E \*(Aq/(bin|lib)$\*(Aq |
93
+ \& xargs \-n1 printf "%s:"\`"
94
+ \& PATH="$BASHLIB$PATH"
95
+ \&
96
+ \& source bash+ :std
97
+ \&
98
+ \& use Test::More
99
+ \&
100
+ \& plan tests 8
101
+ \&
102
+ \& some\-command
103
+ \& ok $? \*(Aqsome\-command is ok\*(Aq
104
+ \&
105
+ \& # or:
106
+ \& ok "\`some\-command\`" \*(Aqsome\-command is ok\*(Aq
107
+ \&
108
+ \& pass \*(AqThis will always pass\*(Aq
109
+ \&
110
+ \& fail \*(AqThis will always fail\*(Aq
111
+ \&
112
+ \& is \`echo foo\` \*(Aqfoo\*(Aq \*(Aqfoo is foo\*(Aq
113
+ \&
114
+ \& isnt foo bar "foo isn\*(Aqt bar"
115
+ \&
116
+ \& like food foo \*(Aqfood is like foo\*(Aq
117
+ \&
118
+ \& unlike team I "There\*(Aqs no \*(AqI\*(Aq in \*(Aqteam\*(Aq"
119
+ \&
120
+ \& diag "A message for stderr"
121
+ \&
122
+ \& note "A message for stdout"
123
+ .Ve
124
+ .PP
125
+ Run the test with \f(CW\*(C`prove\*(C'\fR like this:
126
+ .PP
127
+ .Vb 1
128
+ \& prove test/test.t
129
+ .Ve
130
+ .PP
131
+ Prove knows it's Bash from the first line (the hashbang), and it just works.
132
+ .SH "Description"
133
+ .IX Header "Description"
134
+ Test::More is the tried and true testing library for Perl. It uses \s-1TAP \s0(the Test Anything Protocol). This is the same thing for Bash. For the most part it should work exactly the same.
135
+ .SH "Methods"
136
+ .IX Header "Methods"
137
+ This is the basic usage:
138
+ .IP "\(bu" 4
139
+ \&\f(CW\*(C`plan tests $count\*(C'\fR
140
+ .IP "\(bu" 4
141
+ \&\f(CW\*(C`ok $status_code "$label"\*(C'\fR
142
+ .IP "\(bu" 4
143
+ \&\f(CW\*(C`pass "$label"\*(C'\fR
144
+ .IP "\(bu" 4
145
+ \&\f(CW\*(C`fail "$label"\*(C'\fR
146
+ .IP "\(bu" 4
147
+ \&\f(CW\*(C`is "$got" "$want" "label"\*(C'\fR
148
+ .IP "\(bu" 4
149
+ \&\f(CW\*(C`isnt "$got" "$unwanted" "$label"\*(C'\fR
150
+ .IP "\(bu" 4
151
+ \&\f(CW\*(C`like "$got" "$regex" "$label"\*(C'\fR
152
+ .IP "\(bu" 4
153
+ \&\f(CW\*(C`unlike "$got" "$regex" "$label"\*(C'\fR
154
+ .IP "\(bu" 4
155
+ \&\f(CW\*(C`diag "$message"\*(C'\fR
156
+ .IP "\(bu" 4
157
+ \&\f(CW\*(C`note "$message"\*(C'\fR
158
+ .IP "\(bu" 4
159
+ \&\f(CW\*(C`done_testing $count\*(C'\fR
160
+ .IP "\(bu" 4
161
+ \&\f(CW\*(C`plan skip_all "$reason"\*(C'\fR
162
+ .IP "\(bu" 4
163
+ \&\f(CW\*(C`BAIL_OUT "$reason"\*(C'\fR
164
+ .PP
165
+ More detailed info coming soon.
166
+ .SH "Author"
167
+ .IX Header "Author"
168
+ Ingy döt Net <ingy@bpan.org>
169
+ .SH "Copyright & License"
170
+ .IX Header "Copyright & License"
171
+ Copyright 2013\-2016. Ingy döt Net.
172
+ .PP
173
+ The \s-1MIT\s0 License (\s-1MIT\s0)
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source test/setup
4
+
5
+ use Test::More
6
+
7
+ output=$(prove -v test/test/fail1.t 2>&1) || true
8
+
9
+ like "$output" 'not ok 1 - fail with label' \
10
+ 'fail with label'
11
+ like "$output" 'not ok 2' \
12
+ 'fail with no label'
13
+ like "$output" 'not ok 3 - is foo bar' \
14
+ 'fail output is correct'
15
+ like "$output" "# got: 'foo'" \
16
+ 'difference reporting - got'
17
+ like "$output" "# expected: 'bar'" \
18
+ 'difference reporting - want'
19
+
20
+ done_testing 5
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source test/setup
4
+ use Test::More
5
+
6
+ plan tests 5
7
+
8
+ pass 'This test always passes'
9
+
10
+ is 'foo' "foo" 'foo is foo'
11
+
12
+ ok "`true`" 'true is true'
13
+
14
+ ok "`[ 123 -eq $((61+62)) ]`" 'Math works'
15
+
16
+ ok "`[[ ! team =~ I ]]`" "There's no I in team"
17
+
18
+ # diag "A msg for stderr"
19
+
20
+ note "A msg for stdout"
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source test/setup
4
+
5
+ use Test::More tests 3
6
+
7
+ pass 'pass 1 - with label'
8
+ pass
9
+ pass 'pass 3 - 2 has no label'
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ BASHLIB="`find $PWD -type d | grep -E '/(bin|lib)$' | xargs -n1 printf "%s:"`"
6
+ PATH="$BASHLIB:$PATH"
7
+
8
+ source bash+ :std
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source test/setup
4
+ use Test::More
5
+
6
+ output=$(prove -v test/test/skip_all.t 2>&1) || true
7
+
8
+ like "$output" 'skipped: Skipping this test to demo skip_all' \
9
+ 'skip_all works'
10
+
11
+ done_testing 1
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source test/setup
4
+ use Test::More
5
+
6
+ fail 'fail with label'
7
+
8
+ fail
9
+
10
+ is foo bar 'is foo bar'
11
+
12
+ done_testing 3
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+
3
+ source test/setup
4
+ use Test::More
5
+
6
+ plan skip_all 'Skipping this test to demo skip_all'
7
+
8
+ fail "Don't run this code"
9
+
10
+ done_testing
@@ -0,0 +1,1891 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ #
4
+ # Copyright 2013-2017 - Ingy döt Net <ingy@ingy.net>
5
+ #
6
+
7
+
8
+ # Exit on any errors:
9
+ set -e
10
+
11
+ # Import Bash+ helper functions:
12
+ SOURCE="$BASH_SOURCE"
13
+ while [[ -h $SOURCE ]]; do
14
+ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
15
+ SOURCE="$(readlink "$SOURCE")"
16
+ [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
17
+ done
18
+ SOURCE_DIR="$(dirname "$SOURCE")"
19
+
20
+ if [[ -z "$GIT_SUBREPO_ROOT" ]]; then
21
+ # If `make install` installation used:
22
+ source "${SOURCE_DIR}/git-subrepo.d/bash+.bash"
23
+ else
24
+ # If `source .rc` method used:
25
+ source "${SOURCE_DIR}/../ext/bashplus/lib/bash+.bash"
26
+ fi
27
+ bash+:import :std can
28
+
29
+ VERSION=0.4.0
30
+ REQUIRED_GIT_VERSION=2.7.0
31
+ GIT_TMP=.git/tmp
32
+
33
+ # `git rev-parse` turns this into a getopt parser and a command usage message:
34
+ GETOPT_SPEC="\
35
+ git subrepo <command> <arguments> <options>
36
+
37
+ Commands:
38
+ clone Clone a remote repository into a local subdirectory
39
+ init Turn a current subdirectory into a subrepo
40
+ pull Pull upstream changes to the subrepo
41
+ push Push local subrepo changes upstream
42
+
43
+ fetch Fetch a subrepo's remote branch (and create a ref for it)
44
+ branch Create a branch containing the local subrepo commits
45
+ commit Commit a merged subrepo branch into the mainline
46
+
47
+ status Get status of a subrepo (or all of them)
48
+ clean Remove branches, remotes and refs for a subrepo
49
+ config Set subrepo configuration properties
50
+
51
+ help Documentation for git-subrepo (or specific command)
52
+ version Display git-subrepo version info
53
+ upgrade Upgrade the git-subrepo software itself
54
+
55
+ See 'git help subrepo' for complete documentation and usage of each command.
56
+
57
+ Options:
58
+ --
59
+ h Show the command summary
60
+ help Help overview
61
+ version Print the git-subrepo version number
62
+
63
+ a,all Perform command on all current subrepos
64
+ A,ALL Perform command on all subrepos and subsubrepos
65
+ b,branch= Specify the upstream branch to push/pull/fetch
66
+ e,edit Edit commit message
67
+ f,force Force certain operations
68
+ F,fetch Fetch the upstream content first
69
+ M,method= Method when you join, valid options are 'merge' or 'rebase'
70
+ Default is 'merge'
71
+ m,message= Specify a commit message
72
+ r,remote= Specify the upstream remote to push/pull/fetch
73
+ s,squash Squash commits on push
74
+ u,update Add the --branch and/or --remote overrides to .gitrepo
75
+
76
+ q,quiet Show minimal output
77
+ v,verbose Show verbose output
78
+ d,debug Show the actual commands used
79
+ x,DEBUG Turn on -x Bash debugging
80
+ "
81
+
82
+ #------------------------------------------------------------------------------
83
+ # Top level function:
84
+ #------------------------------------------------------------------------------
85
+ main() {
86
+ # Define global variables:
87
+ local command= # Subrepo subcommand to run
88
+ local command_arguments=() # Command args after getopt parsing
89
+ local commit_msg_args=() # Arguments to show in the commit msg
90
+ local subrepos=() # List of multiple subrepos
91
+
92
+ local all_wanted=false # Apply command to all subrepos
93
+ local ALL_wanted=false # Apply command to all subrepos and subsubrepos
94
+ local force_wanted=false # Force certain operations
95
+ local fetch_wanted=false # Fetch requested before a command
96
+ local squash_wanted=false # Squash commits on push
97
+ local update_wanted=false # Update .gitrepo with --branch and/or --remote
98
+
99
+ local quiet_wanted=false # Output should be quiet
100
+ local verbose_wanted=false # Output should be verbose
101
+ local debug_wanted=false # Show debug messages
102
+
103
+ local subdir= # Subdirectory of the subrepo being used
104
+ local subref= # Valid git ref format of subdir
105
+ local gitrepo= # Path to .gitrepo file
106
+ local worktree= # Worktree created by 'git worktree'
107
+ local start_pwd=$(pwd) # Store the original directory
108
+
109
+ local original_head_commit= # HEAD commit id at start of command
110
+ local original_head_branch= # HEAD ref at start of command
111
+ local upstream_head_commit= # HEAD commit id from a subrepo fetch
112
+
113
+ local subrepo_remote= # Remote url for subrepo's upstream repo
114
+ local subrepo_branch= # Upstream branch to clone/push/pull
115
+ local subrepo_commit= # Upstream HEAD from previous clone/pull
116
+ local subrepo_parent= # Local commit from before previous clone/pull
117
+ local subrepo_former= # A retired gitrepo key that might still exist
118
+
119
+ local refs_subrepo_branch= # A subrepo ref -> commit of branch/pull command
120
+ local refs_subrepo_commit= # A subrepo ref -> commit last merged
121
+ local refs_subrepo_fetch= # A subrepo ref -> FETCH_HEAD after fetch
122
+ local refs_subrepo_push= # A subrepo ref -> branch after push
123
+
124
+ local override_remote= # Remote specified with -r
125
+ local override_branch= # Remote specified with -b
126
+
127
+ local edit_wanted=false # Edit commit message using -e
128
+ local wanted_commit_message= # Custom commit message using -m
129
+
130
+ local join_method= # Current join method (rebase/merge)
131
+
132
+ local FAIL=true # Flag for RUN: fail on error
133
+ local OUT=false # Flag for RUN: put output in $output
134
+ local TTY=false # Flag for RUN: print output directly
135
+ local SAY=true # Flag for RUN: print command for verbose
136
+ local EXEC=false # Flag for RUN: run subprocess
137
+ local OK=true # Flag that commands have succeeded
138
+ local CODE=0 # Failure reason code
139
+ local INDENT= # Verbose indentation
140
+
141
+ local git_version= # Git version in use
142
+
143
+ # Check environment and parse CLI options:
144
+ assert-environment-ok
145
+
146
+ # Parse and validate command options:
147
+ get-command-options "$@"
148
+
149
+ # Make sure repo is in the proper state:
150
+ assert-repo-is-ready
151
+
152
+ command-init
153
+
154
+ if $all_wanted && [[ ! $command =~ ^(help|status)$ ]]; then
155
+ # Run the command on all subrepos
156
+ local args=( "${command_arguments[@]}" )
157
+ get-all-subrepos
158
+ for subdir in ${subrepos[*]}; do
159
+ command-prepare
160
+ subrepo_remote=
161
+ subrepo_branch=
162
+ command_arguments=( "$subdir" "${args[@]}" )
163
+ "command:$command"
164
+ done
165
+ else
166
+ # Run the command on a specific subrepo
167
+ command-prepare
168
+ "command:$command"
169
+ fi
170
+ }
171
+
172
+ #------------------------------------------------------------------------------
173
+ # API command functions.
174
+ #
175
+ # Most of these commands call a subrepo:$command function to do the actual
176
+ # work. The user facing output (via `say`) is done up here. The
177
+ # subrepo:* worker functions are meant to be called internally and don't print
178
+ # info to the user.
179
+ #------------------------------------------------------------------------------
180
+
181
+ # `git subrepo clone <url> [<subdir>]` command:
182
+ command:clone() {
183
+ command-setup +subrepo_remote subdir:guess-subdir
184
+
185
+ # Clone (or reclone) the subrepo into the subdir:
186
+ local reclone_up_to_date=false
187
+ subrepo:clone
188
+ if "$reclone_up_to_date"; then
189
+ say "Subrepo '$subdir' is up to date."
190
+ return
191
+ fi
192
+
193
+ # Successful command output:
194
+ local re=
195
+ $force_wanted && re=re
196
+ local remote="$subrepo_remote"
197
+ say "Subrepo '$remote' ($subrepo_branch) ${re}cloned into '$subdir'."
198
+ }
199
+
200
+ # `git subrepo init <subdir>` command:
201
+ command:init() {
202
+ command-setup +subdir
203
+ local remote="${subrepo_remote:=none}"
204
+ local branch="${subrepo_branch:=master}"
205
+
206
+ # Init new subrepo from the subdir:
207
+ subrepo:init
208
+ if OK; then
209
+ if [[ $remote == none ]]; then
210
+ say "Subrepo created from '$subdir' (with no remote)."
211
+ else
212
+ say "Subrepo created from '$subdir' with remote '$remote' ($branch)."
213
+ fi
214
+ else
215
+ die "Unknown init error code: '$CODE'"
216
+ fi
217
+ return 0
218
+ }
219
+
220
+ # `git subrepo pull <subdir>` command:
221
+ command:pull() {
222
+ command-setup +subdir
223
+
224
+ subrepo:pull
225
+ if OK; then
226
+ say "Subrepo '$subdir' pulled from '$subrepo_remote' ($subrepo_branch)."
227
+ elif [[ $CODE -eq -1 ]]; then
228
+ say "Subrepo '$subdir' is up to date."
229
+ elif [[ $CODE -eq 1 ]]; then
230
+ error-join
231
+ return "$CODE"
232
+ else
233
+ die "Unknown pull error code: '$CODE'"
234
+ fi
235
+ return 0
236
+ }
237
+
238
+ # `git subrepo push <subdir>` command:
239
+ command:push() {
240
+ local branch=
241
+ command-setup +subdir branch
242
+
243
+ subrepo:push
244
+ if OK; then
245
+ say "Subrepo '$subdir' pushed to '$subrepo_remote' ($subrepo_branch)."
246
+ elif [[ $CODE -eq -2 ]]; then
247
+ say "Subrepo '$subdir' has no new commits to push."
248
+ elif [[ $CODE -eq 1 ]]; then
249
+ error-join
250
+ return "$CODE"
251
+ else
252
+ die "Unknown push error code: '$CODE'"
253
+ fi
254
+ return 0
255
+ }
256
+
257
+ # `git subrepo fetch <subdir>` command
258
+ command:fetch() {
259
+ command-setup +subdir
260
+ if [[ $subrepo_remote == "none" ]]; then
261
+ say "Ignored '$subdir', no remote."
262
+ else
263
+ subrepo:fetch
264
+ say "Fetched '$subdir' from '$subrepo_remote' ($subrepo_branch)."
265
+ fi
266
+ }
267
+
268
+ # `git subrepo branch <subdir>` command:
269
+ command:branch() {
270
+ command-setup +subdir
271
+ if $fetch_wanted; then
272
+ CALL subrepo:fetch
273
+ fi
274
+
275
+ local branch="subrepo/$subref"
276
+ if $force_wanted; then
277
+ # We must make sure that the worktree is removed as well
278
+ worktree="$GIT_TMP/$branch"
279
+ git:delete-branch "$branch"
280
+ fi
281
+
282
+ if git:branch-exists "$branch"; then
283
+ error "Branch '$branch' already exists. Use '--force' to override."
284
+ fi
285
+
286
+ # Create the subrepo branch:
287
+ subrepo:branch
288
+
289
+ say "Created branch '$branch' and worktree '$worktree'."
290
+ }
291
+
292
+ # `git subrepo commit <subdir>` command
293
+ command:commit() {
294
+ command-setup +subdir subrepo_commit_ref
295
+
296
+ if "$fetch_wanted"; then
297
+ CALL subrepo:fetch
298
+ fi
299
+ git:rev-exists "$refs_subrepo_fetch" ||
300
+ error "Can't find ref '$refs_subrepo_fetch'. Try using -F."
301
+ upstream_head_commit="$(git rev-parse "$refs_subrepo_fetch")"
302
+
303
+ [[ -n $subrepo_commit_ref ]] ||
304
+ subrepo_commit_ref="subrepo/$subref"
305
+ subrepo:commit
306
+
307
+ say "Subrepo commit '$subrepo_commit_ref' committed as"
308
+ say "subdir '$subdir/' to branch '$original_head_branch'."
309
+ }
310
+
311
+ # `git subrepo status [<subdir>]` command:
312
+ command:status() {
313
+ subrepo:status | ${GIT_SUBREPO_PAGER}
314
+ }
315
+
316
+ status-refs() {
317
+ local output=
318
+ while read line; do
319
+ [[ $line =~ ^([0-9a-f]+)\ refs/subrepo/$subref/([a-z]+) ]] || continue
320
+ local sha1=; sha1="$(git rev-parse --short "${BASH_REMATCH[1]}")"
321
+ local type="${BASH_REMATCH[2]}"
322
+ local ref="refs/subrepo/$subref/$type"
323
+ if [[ $type == branch ]]; then
324
+ output+=" Branch Ref: $sha1 ($ref)"$'\n'
325
+ elif [[ $type == commit ]]; then
326
+ output+=" Commit Ref: $sha1 ($ref)"$'\n'
327
+ elif [[ $type == fetch ]]; then
328
+ output+=" Fetch Ref: $sha1 ($ref)"$'\n'
329
+ elif [[ $type == pull ]]; then
330
+ output+=" Pull Ref: $sha1 ($ref)"$'\n'
331
+ elif [[ $type == push ]]; then
332
+ output+=" Push Ref: $sha1 ($ref)"$'\n'
333
+ fi
334
+ done < <(git show-ref)
335
+ if [[ -n $output ]]; then
336
+ printf " Refs:\n$output"
337
+ fi
338
+ }
339
+
340
+ # `git subrepo clean <subdir>` command
341
+ command:clean() {
342
+ command-setup +subdir
343
+ local clean_list=()
344
+ subrepo:clean
345
+ for item in "${clean_list[@]}"; do
346
+ say "Removed $item."
347
+ done
348
+ }
349
+
350
+ # Wrap git config $gitrepo
351
+ command:config() {
352
+ command-setup +subdir +config_option config_value
353
+ o "Update '$subdir' configuration with $config_option=$config_value"
354
+
355
+ if [[ ! $config_option =~ ^(branch|cmdver|commit|method|remote|version)$ ]]; then
356
+ error "Option $config_option not recognized"
357
+ fi
358
+
359
+ if [[ -z $config_value ]]; then
360
+ OUT=true RUN git config --file="$gitrepo" "subrepo.$config_option"
361
+ say "Subrepo '$subdir' option '$config_option' has value '$output'."
362
+ return
363
+ fi
364
+
365
+ if ! $force_wanted; then
366
+ # Only allow changing method without force
367
+ if [[ ! $config_option == "method" ]]; then
368
+ error "This option is autogenerated, use '--force' to override."
369
+ fi
370
+ fi
371
+
372
+ if [[ $config_option == "method" ]]; then
373
+ if [[ ! $config_value =~ ^(merge|rebase)$ ]]; then
374
+ error "Not a valid method. Valid options are 'merge' or 'rebase'."
375
+ fi
376
+ fi
377
+
378
+ RUN git config --file="$gitrepo" "subrepo.$config_option" "$config_value"
379
+ say "Subrepo '$subdir' option '$config_option' set to '$config_value'."
380
+ }
381
+
382
+
383
+ # Launch the manpage viewer:
384
+ command:help() {
385
+ source "${SOURCE_DIR}/git-subrepo.d/help-functions.bash"
386
+ local cmd="${command_arguments[0]}"
387
+ if [[ -n $cmd ]]; then
388
+ if can "help:$cmd"; then
389
+ "help:$cmd"
390
+ echo
391
+ else
392
+ err "No help found for '$cmd'"
393
+ fi
394
+ elif $all_wanted; then
395
+ help:all
396
+ else
397
+ exec git help subrepo
398
+ fi
399
+ msg_ok=0
400
+ }
401
+
402
+ # Print version info.
403
+ # TODO: Add short commit id after version.
404
+ # Will need to get it from repo or make install can put it somewhere.
405
+ command:version() {
406
+ cat <<...
407
+ git-subrepo Version: $VERSION
408
+ Copyright 2013-2017 Ingy döt Net
409
+ https://github.com/git-commands/git-subrepo
410
+ $BASH_SOURCE
411
+ Git Version: $git_version
412
+
413
+ ...
414
+ :
415
+ }
416
+
417
+ command:upgrade() {
418
+ local path="$0"
419
+ if [[ $path =~ ^/ && $path =~ ^(.*/git-subrepo)/lib/git-subrepo$ ]]; then
420
+ local subrepo_root="${BASH_REMATCH[1]}"
421
+ (
422
+ o "Change directory to '$subrepo_root'."
423
+ cd "${BASH_REMATCH[1]}"
424
+
425
+ local branch="$(git rev-parse --abbrev-ref HEAD)"
426
+ if [[ $branch != master ]]; then
427
+ error "git-subrepo repo is not on the 'master' branch"
428
+ fi
429
+
430
+ o "'git pull' latest version."
431
+ RUN git pull --ff-only
432
+
433
+ say "git-subrepo is up to date."
434
+ )
435
+ else
436
+ die "\
437
+
438
+ Sorry. Your installation can't use the 'git subrepo upgrade' command. The
439
+ command only works if you installed git subrepo by adding
440
+ '/path/to/git-subrepo' to your PATH.
441
+
442
+ If you used 'make install' to install git-subrepo, then just do this:
443
+
444
+ cd /path/to/git-subrepo
445
+ git pull
446
+ make install
447
+
448
+ "
449
+ fi
450
+ }
451
+
452
+ #------------------------------------------------------------------------------
453
+ # Subrepo command worker functions.
454
+ #------------------------------------------------------------------------------
455
+
456
+ # Clone by fetching remote content into our subdir:
457
+ subrepo:clone() {
458
+ re="$1"
459
+
460
+ FAIL=false RUN git rev-parse HEAD
461
+ if ! OK; then
462
+ error "You can't clone into an empty repository"
463
+ fi
464
+
465
+ # Turn off force unless really a reclone:
466
+ if $force_wanted && [[ ! -f $gitrepo ]]; then
467
+ force_wanted=false
468
+ fi
469
+
470
+ if $force_wanted; then
471
+ o "--force indicates a reclone."
472
+ CALL subrepo:fetch
473
+ read-gitrepo-file
474
+ o "Check if we already are up to date."
475
+ if [[ $upstream_head_commit == $subrepo_commit ]]; then
476
+ reclone_up_to_date=true
477
+ return
478
+ fi
479
+ o "Remove the old subdir."
480
+ RUN git rm -r -- "$subdir"
481
+ else
482
+ assert-subdir-empty
483
+ if [[ -z $subrepo_branch ]]; then
484
+ o "Determine the upstream head branch."
485
+ get-upstream-head-branch
486
+ subrepo_branch="$output"
487
+ fi
488
+
489
+ CALL subrepo:fetch
490
+ fi
491
+
492
+ o "Make the directory '$subdir/' for the clone."
493
+ RUN mkdir -p -- "$subdir"
494
+
495
+ o "Commit the new '$subdir/' content."
496
+ subrepo_commit_ref="$upstream_head_commit"
497
+ CALL subrepo:commit
498
+ }
499
+
500
+ # Init a new subrepo from current repo:
501
+ subrepo:init() {
502
+ local branch_name="subrepo/${subref:??}"
503
+ # Check if subdir is proper candidate for this init:
504
+ assert-subdir-ready-for-init
505
+
506
+ o "Put info into '$subdir/.gitrepo' file."
507
+ update-gitrepo-file
508
+
509
+ o "Add the new '$subdir/.gitrepo' file."
510
+ # -f from pull request #219. TODO needs test.
511
+ RUN git add -f -- "$gitrepo"
512
+
513
+ o "Commit new subrepo to the '$original_head_branch' branch."
514
+ subrepo_commit_ref="$original_head_commit"
515
+ RUN git commit -m "$(get-commit-message)"
516
+
517
+ o "Create ref '$refs_subrepo_commit'."
518
+ git:make-ref "$refs_subrepo_commit" "$subrepo_commit_ref"
519
+ }
520
+
521
+ # Properly merge a local subrepo branch with upstream and commit to mainline:
522
+ subrepo:pull() {
523
+ CALL subrepo:fetch
524
+
525
+ # Check if we already are up to date
526
+ # If the -u flag is present, always perform the operation
527
+ if [[ $upstream_head_commit == $subrepo_commit ]] && ! $update_wanted; then
528
+ OK=false; CODE=-1; return
529
+ fi
530
+
531
+ local branch_name="subrepo/$subref"
532
+ git:delete-branch "$branch_name"
533
+
534
+ subrepo_commit_ref="$branch_name"
535
+
536
+ o "Create subrepo branch '$branch_name'."
537
+ CALL subrepo:branch
538
+ cd "$worktree";
539
+
540
+ if [[ "$join_method" == "rebase" ]]; then
541
+ o "Rebase changes to $refs_subrepo_fetch"
542
+ FAIL=false OUT=true RUN git rebase "$refs_subrepo_fetch" "$branch_name"
543
+ if ! OK; then
544
+ say "The \"git rebase\" command failed:"
545
+ say
546
+ say " ${output//$'\n'/$'\n' }"
547
+ CODE=1
548
+ return
549
+ fi
550
+ else
551
+ o "Merge in changes from $refs_subrepo_fetch"
552
+ FAIL=false OUT=true RUN git merge "$refs_subrepo_fetch"
553
+ if ! OK; then
554
+ say "The \"git merge\" command failed:"
555
+ say
556
+ say " ${output//$'\n'/$'\n' }"
557
+ CODE=1
558
+ return
559
+ fi
560
+ fi
561
+
562
+ o "Back to $start_pwd"
563
+ cd "$start_pwd";
564
+
565
+ o "Create ref '$refs_subrepo_branch' for branch '$branch_name'."
566
+ git:make-ref "$refs_subrepo_branch" "$branch_name"
567
+
568
+ o "Commit the new '$subrepo_commit_ref' content."
569
+ CALL subrepo:commit
570
+ }
571
+
572
+ # Push a properly merged subrepo branch upstream:
573
+ subrepo:push() {
574
+ local branch_name="$branch"
575
+ local new_upstream=false
576
+ local branch_created=false
577
+
578
+ if [[ -z $branch_name ]]; then
579
+ FAIL=false OUT=false CALL subrepo:fetch
580
+
581
+ if ! OK; then
582
+ # Check if we are pushing to a new upstream repo (or branch) and just
583
+ # push the commit directly. This is common after a `git subrepo init`:
584
+ local re="(^|"$'\n'")fatal: Couldn't find remote ref "
585
+ if [[ $output =~ $re ]]; then
586
+ o "Pushing to new upstream: $subrepo_remote ($subrepo_branch)."
587
+ new_upstream=true
588
+ else
589
+ error "Fetch for push failed: $output"
590
+ fi
591
+ else
592
+ # Check that we are up to date:
593
+ o "Check upstream head against .gitrepo commit."
594
+ if ! $force_wanted; then
595
+ if [[ $upstream_head_commit != $subrepo_commit ]]; then
596
+ error "There are new changes upstream, you need to pull first."
597
+ fi
598
+ fi
599
+ fi
600
+
601
+ branch_name="subrepo/$subref"
602
+ git:delete-branch "$branch_name"
603
+
604
+ if $squash_wanted; then
605
+ o "Squash commits"
606
+ subrepo_parent="HEAD^"
607
+ fi
608
+
609
+ o "Create subrepo branch '$branch_name'."
610
+ CALL subrepo:branch "$branch_name"
611
+ cd "$worktree";
612
+
613
+ if [[ "$join_method" == "rebase" ]]; then
614
+ o "Rebase changes to $refs_subrepo_fetch"
615
+ FAIL=false OUT=true RUN git rebase "$refs_subrepo_fetch" "$branch_name"
616
+ if ! OK; then
617
+ say "The \"git rebase\" command failed:"
618
+ say
619
+ say " ${output//$'\n'/$'\n' }"
620
+ CODE=1
621
+ return
622
+ fi
623
+ fi
624
+ branch_created=true
625
+ cd "$start_pwd"
626
+ else
627
+ if $squash_wanted; then
628
+ error "Squash option (-s) can't be used with branch parameter"
629
+ fi
630
+ fi
631
+
632
+ o "Make sure that '$branch_name' exists."
633
+ git:branch-exists "$branch_name" ||
634
+ error "No subrepo branch '$branch_name' to push."
635
+
636
+ o "Check if we have something to push"
637
+ new_upstream_head_commit="$(git rev-parse "$branch_name")"
638
+ if ! $new_upstream; then
639
+ if [[ $upstream_head_commit == $new_upstream_head_commit ]]; then
640
+ OK=false
641
+ CODE=-2
642
+ return
643
+ fi
644
+ fi
645
+
646
+ if ! $force_wanted; then
647
+ o "Make sure '$branch_name' contains the '$refs_subrepo_fetch' HEAD."
648
+ if ! git:commit-in-rev-list "$upstream_head_commit" "$branch_name"; then
649
+ error "Can't commit: '$branch_name' doesn't contain upstream HEAD: " \
650
+ "$upstream_head_commit"
651
+ fi
652
+ fi
653
+
654
+ local force=''
655
+ "$force_wanted" && force=' --force'
656
+
657
+ o "Push$force branch '$branch_name' to '$subrepo_remote' ($subrepo_branch)."
658
+ RUN git push$force "$subrepo_remote" "$branch_name":"$subrepo_branch"
659
+
660
+ o "Create ref '$refs_subrepo_push' for branch '$branch_name'."
661
+ git:make-ref "$refs_subrepo_push" "$branch_name"
662
+
663
+ if $branch_created; then
664
+ o "Remove branch '$branch_name'."
665
+ git:delete-branch "$branch_name"
666
+ fi
667
+
668
+ o "Put updates into '$subdir/.gitrepo' file."
669
+ upstream_head_commit="$new_upstream_head_commit"
670
+ subrepo_commit_ref="$upstream_head_commit"
671
+ update-gitrepo-file
672
+ RUN git commit -m "$(get-commit-message)"
673
+ }
674
+
675
+ # Fetch the subrepo's remote branch content:
676
+ subrepo:fetch() {
677
+ if [[ $subrepo_remote == none ]]; then
678
+ error "Can't fetch subrepo. Remote is 'none' in '$subdir/.gitrepo'."
679
+ fi
680
+
681
+ o "Fetch the upstream: $subrepo_remote ($subrepo_branch)."
682
+ RUN git fetch --no-tags --quiet "$subrepo_remote" "$subrepo_branch"
683
+ OK || return
684
+
685
+ o "Get the upstream subrepo HEAD commit."
686
+ OUT=true RUN git rev-parse FETCH_HEAD^0
687
+ upstream_head_commit="$output"
688
+
689
+ o "Create ref '$refs_subrepo_fetch'."
690
+ git:make-ref "$refs_subrepo_fetch" FETCH_HEAD^0
691
+ }
692
+
693
+ # Create a subrepo branch containing all changes
694
+ subrepo:branch() {
695
+ local branch="${1:-"subrepo/$subref"}"
696
+ o "Check if the '$branch' branch already exists."
697
+ git:branch-exists "$branch" && return
698
+
699
+ local last_gitrepo_commit=
700
+ local first_gitrepo_commit=
701
+
702
+ o "Subrepo parent: $subrepo_parent"
703
+ if [[ -n "$subrepo_parent" ]]; then
704
+ local prev_commit=
705
+ local ancestor=
706
+ o "Create new commits with parents into the subrepo fetch"
707
+ OUT=true RUN git rev-list --reverse --ancestry-path "$subrepo_parent..HEAD"
708
+ local commit_list="$output"
709
+ for commit in $commit_list; do
710
+ o "Working on $commit"
711
+
712
+ FAIL=false OUT=true RUN git config --blob \
713
+ "$commit":"$subdir/.gitrepo" "subrepo.commit"
714
+ if [[ -z "$output" ]]; then
715
+ o "Ignore commit, no .gitrepo file"
716
+ continue
717
+ fi
718
+
719
+ local gitrepo_commit="$output"
720
+ o ".gitrepo reference commit: $gitrepo_commit"
721
+
722
+
723
+ # Only include the commit if it's a child of the previous commit
724
+ # This way we create a single path between $subrepo_parent..HEAD
725
+ if [[ -n "$ancestor" ]]; then
726
+ local is_direct_child=$(git show -s --pretty=format:"%P" $commit | grep "$ancestor")
727
+ o "is child: $is_direct_child"
728
+ if [[ -z "$is_direct_child" ]]; then
729
+ o "Ignore $commit, it's not in the selected path"
730
+ continue
731
+ fi
732
+ fi
733
+
734
+ # Remember the previous commit from the parent repo path
735
+ ancestor="$commit"
736
+
737
+ o "Check for rebase"
738
+ if git:rev-exists "$refs_subrepo_fetch"; then
739
+ if ! git:commit-in-rev-list "$gitrepo_commit" "$refs_subrepo_fetch"; then
740
+ error "Local repository does not contain $gitrepo_commit. Try to 'git subrepo fetch $subref' of add the '-F' flag to always fetch the latest content."
741
+ fi
742
+ fi
743
+
744
+ o "Find parents"
745
+ local first_parent=
746
+ [[ -n $prev_commit ]] && first_parent="-p $prev_commit"
747
+ local second_parent=
748
+ if [[ -z "$first_gitrepo_commit" ]]; then
749
+ first_gitrepo_commit="$gitrepo_commit"
750
+ second_parent="-p $gitrepo_commit"
751
+ fi
752
+
753
+ if [[ "$join_method" != "rebase" ]]; then
754
+ # In the rebase case we don't create merge commits
755
+ if [[ "$gitrepo_commit" != "$last_gitrepo_commit" ]]; then
756
+ second_parent="-p $gitrepo_commit"
757
+ last_gitrepo_commit="$gitrepo_commit"
758
+ fi
759
+ fi
760
+
761
+ o "Create a new commit $first_parent $second_parent"
762
+ FAIL=false RUN git cat-file -e "$commit":"$subdir"
763
+ if OK; then
764
+ o "Create with content"
765
+ local PREVIOUS_IFS=$IFS
766
+ IFS=$'\n'
767
+ local author_info=( $(git log -1 --format=%ad%n%ae%n%an "$commit") )
768
+ local commiter_info=( $(git log -1 --format=%cd%n%ce%n%cn "$commit") )
769
+ IFS=$PREVIOUS_IFS
770
+
771
+ # When we create new commits we leave the author information unchanged
772
+ # the committer will though be updated to the current user
773
+ # This should be analog how cherrypicking is handled allowing git
774
+ # to store both the original author but also the responsible committer
775
+ # that created the local version of the commit and pushed it.
776
+ prev_commit=$(git log -n 1 --format=%B "$commit" |
777
+ GIT_AUTHOR_DATE="${author_info[0]}" \
778
+ GIT_AUTHOR_EMAIL="${author_info[1]}" \
779
+ GIT_AUTHOR_NAME="${author_info[2]}" \
780
+ GIT_COMMITTER_DATE="${commiter_info[0]}" \
781
+ GIT_COMMITTER_EMAIL="${commiter_info[1]}" \
782
+ GIT_COMMITTER_NAME="${commiter_info[2]}" \
783
+ git commit-tree -F - $first_parent $second_parent "$commit":"$subdir")
784
+ else
785
+ o "Create empty placeholder"
786
+ prev_commit=$(git commit-tree -m "EMPTY" \
787
+ $first_parent $second_parent "4b825dc642cb6eb9a060e54bf8d69288fbee4904")
788
+ fi
789
+ done
790
+
791
+ o "Create branch '$branch' for this new commit set $prev_commit."
792
+ RUN git branch "$branch" "$prev_commit"
793
+ else
794
+ o "No parent setting, use the subdir content."
795
+ RUN git branch "$branch" HEAD
796
+ TTY=true FAIL=false RUN git filter-branch -f --subdirectory-filter \
797
+ "$subref" "$branch"
798
+ fi
799
+
800
+ o "Remove the .gitrepo file from $first_gitrepo_commit..$branch"
801
+ local filter="$branch"
802
+ [[ -n "$first_gitrepo_commit" ]] && filter="$first_gitrepo_commit..$branch"
803
+ FAIL=false RUN git filter-branch -f --prune-empty --tree-filter \
804
+ "rm -f .gitrepo" "$filter"
805
+
806
+ git:create-worktree "$branch"
807
+
808
+ o "Create ref '$refs_subrepo_branch'."
809
+ git:make-ref "$refs_subrepo_branch" "$branch"
810
+ }
811
+
812
+ # Commit a merged subrepo branch:
813
+ subrepo:commit() {
814
+ o "Check that '$subrepo_commit_ref' exists."
815
+ git:rev-exists "$subrepo_commit_ref" ||
816
+ error "Commit ref '$subrepo_commit_ref' does not exist."
817
+
818
+ if ! "$force_wanted"; then
819
+ local upstream="$upstream_head_commit"
820
+ o "Make sure '$subrepo_commit_ref' contains the upstream HEAD."
821
+ if ! git:commit-in-rev-list "$upstream" "$subrepo_commit_ref"; then
822
+ error \
823
+ "Can't commit: '$subrepo_commit_ref' doesn't contain upstream HEAD."
824
+ fi
825
+ fi
826
+
827
+ if git ls-files -- "$subdir" | grep -q .; then
828
+ o "Remove old content of the subdir."
829
+ RUN git rm -r -- "$subdir"
830
+ fi
831
+
832
+ o "Put remote subrepo content into '$subdir/'."
833
+ RUN git read-tree --prefix="$subdir" -u "$subrepo_commit_ref"
834
+
835
+ o "Put info into '$subdir/.gitrepo' file."
836
+ update-gitrepo-file
837
+ RUN git add -f -- "$gitrepo"
838
+
839
+ local commit_message
840
+ if [[ -n "$wanted_commit_message" ]]; then
841
+ commit_message="$wanted_commit_message"
842
+ else
843
+ commit_message="$(get-commit-message)"
844
+ fi
845
+
846
+ local edit_flag=
847
+ $edit_wanted && edit_flag=--edit
848
+
849
+ [[ -n $commit_message ]] || commit_message="$(get-commit-message)"
850
+
851
+ local edit_flag=
852
+ $edit_wanted && edit_flag=--edit
853
+
854
+ o "Commit to the '$original_head_branch' branch."
855
+ if [[ $original_head_commit != none ]]; then
856
+ RUN git commit $edit_flag -m "$commit_message"
857
+ else
858
+ # We had cloned into an empty repo, side effect of prior git reset --mixed
859
+ # command is that subrepo's history is now part of the index. Commit
860
+ # without that history.
861
+ OUT=true RUN git write-tree
862
+ OUT=true RUN git commit-tree $edit_flag -m "$commit_message" "$output"
863
+ RUN git reset --hard "$output"
864
+ fi
865
+
866
+ # Clean up worktree to indicate that we are ready
867
+ git:remove-worktree
868
+
869
+ o "Create ref '$refs_subrepo_commit'."
870
+ git:make-ref "$refs_subrepo_commit" "$subrepo_commit_ref"
871
+ }
872
+
873
+ subrepo:status() {
874
+ if [[ ${#command_arguments[@]} -eq 0 ]]; then
875
+ get-all-subrepos
876
+ local count=${#subrepos[@]}
877
+ if ! "$quiet_wanted"; then
878
+ if [[ $count -eq 0 ]]; then
879
+ echo "No subrepos."
880
+ return
881
+ else
882
+ local s=; [[ $count -eq 1 ]] || s=s
883
+ echo "$count subrepo$s:"
884
+ echo
885
+ fi
886
+ fi
887
+ else
888
+ subrepos=("${command_arguments[@]}")
889
+ fi
890
+
891
+ for subdir in "${subrepos[@]}"; do
892
+ check-and-normalize-subdir
893
+ encode-subdir
894
+
895
+ if [[ ! -f $subdir/.gitrepo ]]; then
896
+ echo "'$subdir' is not a subrepo"
897
+ echo
898
+ continue
899
+ fi
900
+
901
+ refs_subrepo_fetch="refs/subrepo/$subref/fetch"
902
+ upstream_head_commit="$(
903
+ git rev-parse --short "$refs_subrepo_fetch" 2> /dev/null || true
904
+ )"
905
+ subrepo_remote=
906
+ subrepo_branch=
907
+
908
+ read-gitrepo-file
909
+ if $fetch_wanted; then
910
+ subrepo:fetch
911
+ fi
912
+
913
+ if $quiet_wanted; then
914
+ echo "$subdir"
915
+ continue
916
+ fi
917
+
918
+ echo "Git subrepo '$subdir':"
919
+ git:branch-exists "subrepo/$subref" &&
920
+ echo " Subrepo Branch: subrepo/$subref"
921
+ local remote="subrepo/$subref"
922
+ FAIL=false OUT=true RUN git config "remote.$remote.url"
923
+ [[ -n $output ]] &&
924
+ echo " Remote Name: subrepo/$subref"
925
+ echo " Remote URL: $subrepo_remote"
926
+ [[ -n $upstream_head_commit ]] &&
927
+ echo " Upstream Ref: $upstream_head_commit"
928
+ echo " Tracking Branch: $subrepo_branch"
929
+ [[ -z $subrepo_commit ]] ||
930
+ echo " Pulled Commit: $(git rev-parse --short $subrepo_commit)"
931
+ if [[ -n $subrepo_parent ]]; then
932
+ echo " Pull Parent: $(git rev-parse --short $subrepo_parent)"
933
+ # TODO Remove this eventually:
934
+ elif [[ -n $subrepo_former ]]; then
935
+ printf " Former Commit: $(git rev-parse --short $subrepo_former)"
936
+ echo " *** DEPRECATED ***"
937
+ fi
938
+
939
+ # Grep for directory, branch can be in detached state due to conflicts
940
+ local _worktree=$(git worktree list | grep "$GIT_TMP/subrepo/$subdir")
941
+ if [[ -n $_worktree ]]; then
942
+ echo " Worktree: $_worktree"
943
+ fi
944
+
945
+ if "$verbose_wanted"; then
946
+ status-refs
947
+ fi
948
+
949
+ echo
950
+ done
951
+ }
952
+
953
+ subrepo:clean() {
954
+ # Remove subrepo branches if exist:
955
+ local branch="subrepo/$subref"
956
+ local ref="refs/heads/$branch"
957
+ local worktree="$GIT_TMP/$branch"
958
+
959
+ o "Clean $subdir"
960
+ git:remove-worktree
961
+ if [[ -e .git/$ref ]]; then
962
+ o "Remove branch '$branch'."
963
+ RUN git update-ref -d "$ref"
964
+ clean_list+=("branch '$branch'")
965
+ fi
966
+
967
+ if "$force_wanted"; then
968
+ o "Remove all subrepo refs."
969
+ if "$all_wanted"; then
970
+ RUN rm -fr .git/refs/subrepo/
971
+ else
972
+ RUN rm -fr .git/refs/subrepo/$subref/
973
+ fi
974
+ fi
975
+ }
976
+
977
+ #------------------------------------------------------------------------------
978
+ # Support functions:
979
+ #------------------------------------------------------------------------------
980
+
981
+
982
+ # TODO:
983
+ # Collect original options and arguments into an array for commit message
984
+ # They should be normalized and pruned
985
+
986
+ # Parse command line options:
987
+ get-command-options() {
988
+ [[ $# -eq 0 ]] && set -- --help
989
+
990
+ [[ -n $GIT_SUBREPO_QUIET ]] && quiet_wanted=true
991
+ [[ -n $GIT_SUBREPO_VERBOSE ]] && verbose_wanted=true
992
+ [[ -n $GIT_SUBREPO_DEBUG ]] && debug_wanted=true
993
+
994
+ eval "$(
995
+ echo "$GETOPT_SPEC" |
996
+ git rev-parse --parseopt -- "$@" ||
997
+ echo exit $?
998
+ )"
999
+
1000
+ while [[ $# -gt 0 ]]; do
1001
+ local option="$1"; shift
1002
+ case "$option" in
1003
+ --) break ;;
1004
+ -a) all_wanted=true ;;
1005
+ -A) ALL_wanted=true
1006
+ all_wanted=true ;;
1007
+ -b) subrepo_branch="$1"
1008
+ override_branch="$1"
1009
+ commit_msg_args+=("--branch=$1")
1010
+ shift ;;
1011
+ -e) edit_wanted=true ;;
1012
+ -f) force_wanted=true
1013
+ commit_msg_args+=("--force") ;;
1014
+ -F) fetch_wanted=true ;;
1015
+ -m) wanted_commit_message="$1"
1016
+ shift;;
1017
+ -M) join_method="$1"
1018
+ shift;;
1019
+ -M) join_method="$1"
1020
+ shift;;
1021
+ -r) subrepo_remote="$1"
1022
+ override_remote="$1"
1023
+ commit_msg_args+=("--remote=$1")
1024
+ shift ;;
1025
+ -s) squash_wanted=true ;;
1026
+ -u) update_wanted=true
1027
+ commit_msg_args+=("--update") ;;
1028
+ -q) quiet_wanted=true ;;
1029
+ -v) verbose_wanted=true ;;
1030
+ -d) debug_wanted=true ;;
1031
+ -x) set -x ;;
1032
+ --version)
1033
+ echo "$VERSION"
1034
+ exit ;;
1035
+ *) usage-error "Unexpected option: '$option'." ;;
1036
+ esac
1037
+ done
1038
+
1039
+ # Set subrepo command:
1040
+ command="$1"; shift
1041
+
1042
+ # Make sure command exists:
1043
+ can "command:$command" ||
1044
+ usage-error "'$command' is not a command. See 'git subrepo help'."
1045
+
1046
+ command_arguments=("$@")
1047
+ if [[ ${#command_arguments} -gt 0 ]]; then
1048
+ local first="${command_arguments[0]}"
1049
+ first="${first%/}"
1050
+ command_arguments[0]="$first"
1051
+ fi
1052
+ commit_msg_args+=("${command_arguments[@]}")
1053
+
1054
+ for option in all ALL edit fetch force squash; do
1055
+ var="${option}_wanted"
1056
+ if ${!var}; then
1057
+ check_option $option
1058
+ fi
1059
+ done
1060
+
1061
+ if [[ -n $override_branch ]]; then
1062
+ check_option branch
1063
+ fi
1064
+ if [[ -n $override_remote ]]; then
1065
+ check_option remote
1066
+ fi
1067
+ if [[ -n $wanted_commit_message ]]; then
1068
+ check_option message
1069
+ fi
1070
+ if $update_wanted; then
1071
+ check_option update
1072
+ if [[ -z $subrepo_branch && -z $subrepo_remote ]]; then
1073
+ usage-error "Can't use '--update' without '--branch' or '--remote'."
1074
+ fi
1075
+ fi
1076
+ }
1077
+
1078
+ options_help='all'
1079
+ options_branch='all fetch force'
1080
+ options_clean='ALL all force'
1081
+ options_clone='branch edit force message method'
1082
+ options_config='force'
1083
+ options_commit='edit fetch force message'
1084
+ options_fetch='all branch remote'
1085
+ options_init='branch remote method'
1086
+ options_pull='all branch edit force message remote update'
1087
+ options_push='all branch force remote squash update'
1088
+ options_status='ALL all fetch'
1089
+ check_option() {
1090
+ local var="options_${command//-/_}"
1091
+ [[ ${!var} =~ $1 ]] ||
1092
+ usage-error "Invalid option '--$1' for '$command'."
1093
+ }
1094
+
1095
+ #------------------------------------------------------------------------------
1096
+ # Command argument validation:
1097
+ #------------------------------------------------------------------------------
1098
+
1099
+ command-init() {
1100
+ # Export variable to let other processes (possibly git hooks) know that they
1101
+ # are running under git-subrepo. Set to current process pid, so it can be
1102
+ # further verified if need be:
1103
+ export GIT_SUBREPO_RUNNING="$$"
1104
+ export GIT_SUBREPO_COMMAND="$command"
1105
+
1106
+ : "${GIT_SUBREPO_PAGER:=${PAGER:-less}}"
1107
+ if [[ $GIT_SUBREPO_PAGER == less ]]; then
1108
+ GIT_SUBREPO_PAGER='less -FRX'
1109
+ fi
1110
+ }
1111
+
1112
+ command-prepare() {
1113
+ local output=
1114
+ if git:rev-exists HEAD; then
1115
+ git:get-head-branch-commit
1116
+ fi
1117
+ original_head_commit="${output:-none}"
1118
+ }
1119
+
1120
+ # Do the setup steps needed by most of the subrepo subcommands:
1121
+ command-setup() {
1122
+ get-params "$@"
1123
+
1124
+ check-and-normalize-subdir
1125
+ encode-subdir
1126
+ gitrepo="$subdir/.gitrepo"
1127
+
1128
+ if ! $force_wanted; then
1129
+ o "Check for worktree with branch subrepo/$subdir"
1130
+ local _worktree=$(git worktree list | grep "\[subrepo/$subdir\]" | cut -d ' ' -f1)
1131
+ if [[ $command =~ ^(commit)$ && -z $_worktree ]]; then
1132
+ error "There is no worktree available, use the branch command first"
1133
+ elif [[ ! $command =~ ^(branch|clean|commit|push)$ && -n $_worktree ]]; then
1134
+ if [[ -e $gitrepo ]]; then
1135
+ error "There is already a worktree with branch subrepo/$subdir.
1136
+ Use the --force flag to override this check or perform a subrepo clean
1137
+ to remove the worktree."
1138
+ else
1139
+ error "There is already a worktree with branch subrepo/$subdir.
1140
+ Use the --force flag to override this check or remove the worktree with
1141
+ 1. rm -rf $_worktree
1142
+ 2. git worktree prune
1143
+ "
1144
+ fi
1145
+ fi
1146
+ fi
1147
+
1148
+ # Set refs_ variables:
1149
+ refs_subrepo_branch="refs/subrepo/$subref/branch"
1150
+ refs_subrepo_commit="refs/subrepo/$subref/commit"
1151
+ refs_subrepo_fetch="refs/subrepo/$subref/fetch"
1152
+ refs_subrepo_push="refs/subrepo/$subref/push"
1153
+
1154
+ # Read/parse the .gitrepo file (unless clone/init; doesn't exist yet)
1155
+ if [[ ! $command =~ ^(clone|init)$ ]]; then
1156
+ read-gitrepo-file
1157
+ fi
1158
+
1159
+ true
1160
+ }
1161
+
1162
+ # Parse command line args according to a simple dsl spec:
1163
+ get-params() {
1164
+ local i=0
1165
+ local num=${#command_arguments[@]}
1166
+ for arg in $@; do
1167
+ local value="${command_arguments[i]}"
1168
+ value="${value//%/%%}"
1169
+ value="${value//\\/\\\\}"
1170
+ # If arg starts with '+' then it is required
1171
+ if [[ $arg == +* ]]; then
1172
+ if [[ $i -ge $num ]]; then
1173
+ usage-error "Command '$command' requires arg '${arg#+}'."
1174
+ fi
1175
+ printf -v ${arg#+} -- "$value"
1176
+ # Look for function name after ':' to provide a default value
1177
+ else
1178
+ if [[ $i -lt $num ]]; then
1179
+ printf -v ${arg%:*} -- "$value"
1180
+ elif [[ $arg =~ : ]]; then
1181
+ "${arg#*:}"
1182
+ fi
1183
+ fi
1184
+ let i=$((i+1))
1185
+ done
1186
+
1187
+ # Check for extra arguments:
1188
+ if [[ $num -gt $i ]]; then
1189
+ set -- ${command_arguments[@]}
1190
+ for ((j = 1; j <= i; j++)); do shift; done
1191
+ error "Unknown argument(s) '$*' for '$command' command."
1192
+ fi
1193
+ }
1194
+
1195
+ check-and-normalize-subdir() {
1196
+ # Sanity check subdir:
1197
+ [[ -n $subdir ]] ||
1198
+ die "subdir not set"
1199
+ [[ $subdir =~ ^/ || $subdir =~ ^[A-Z]: ]] &&
1200
+ usage-error "The subdir '$subdir' should not be absolute path."
1201
+ subdir="${subdir#./}"
1202
+ subdir="${subdir%/}"
1203
+ [[ $subdir != *//* ]] || subdir=$(tr -s / <<< "$subdir")
1204
+ }
1205
+
1206
+ # Determine the correct subdir path to use:
1207
+ guess-subdir() {
1208
+ local dir="$subrepo_remote"
1209
+ dir="${dir%.git}"
1210
+ dir="${dir%/}"
1211
+ dir="${dir##*/}"
1212
+ [[ $dir =~ ^[-_a-zA-Z0-9]+$ ]] ||
1213
+ error "Can't determine subdir from '$subrepo_remote'."
1214
+ subdir="$dir"
1215
+ check-and-normalize-subdir
1216
+ encode-subdir
1217
+ }
1218
+
1219
+ # Encode the subdir as a valid git ref format
1220
+ #
1221
+ # Input: env $subdir
1222
+ # Output: env $subref
1223
+ #
1224
+ # For detail rules about valid git refs, see the manual of git-check-ref-format:
1225
+ # URL: https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
1226
+ # Shell: git check-ref-format --help
1227
+ #
1228
+ encode-subdir() {
1229
+ subref=$subdir
1230
+ if [[ ! $subref ]] || git check-ref-format "subrepo/$subref"; then
1231
+ return
1232
+ fi
1233
+
1234
+ ## 0. escape %, ensure the subref can be (almost) decoded back to subdir
1235
+ subref=${subref//%/%25}
1236
+
1237
+ ## 1. They can include slash / for hierarchical (directory) grouping,
1238
+ ## but no slash-separated component can begin with a dot . or
1239
+ ## end with the sequence .lock.
1240
+ subref=/$subref/
1241
+ subref=${subref//\/.//%2e}
1242
+ subref=${subref//.lock\//%2elock/}
1243
+ subref=${subref#/}
1244
+ subref=${subref%/}
1245
+
1246
+ ## 2. They must contain at least one /.
1247
+ ## Note: 'subrepo/' be will prefixed, so this is always true.
1248
+ ## 3. They cannot have two consecutive dots .. anywhere.
1249
+ subref=${subref//../%2e%2e}
1250
+ subref=${subref//%2e./%2e%2e}
1251
+ subref=${subref//.%2e/%2e%2e}
1252
+
1253
+ ## 4. They cannot have ASCII control characters
1254
+ ## (i.e. bytes whose values are lower than \040, or \177 DEL), space,
1255
+ ## tilde ~, caret ^, or colon : anywhere.
1256
+ ## 5. They cannot have question-mark ?, asterisk *,
1257
+ ## or open bracket [ anywhere.
1258
+ local i
1259
+ for (( i = 1; i < 32; ++i )); do
1260
+ # skip substitute NUL char (i=0), as bash will skip NUL in env
1261
+ local x=$(printf "%02x" $i)
1262
+ subref=${subref//$(printf "%b" "\x$x")/%$x}
1263
+ done
1264
+ subref=${subref//$'\177'/%7f}
1265
+ subref=${subref// /%20}
1266
+ subref=${subref//\~/%7e}
1267
+ subref=${subref//^/%5e}
1268
+ subref=${subref//:/%3a}
1269
+ subref=${subref//\?/%3f}
1270
+ subref=${subref//\*/%2a}
1271
+ subref=${subref//\[/%5b}
1272
+ subref=${subref//$'\n'/%0a}
1273
+
1274
+ ## 6. They cannot begin or end with a slash / or contain multiple
1275
+ ## consecutive slashes.
1276
+ ## Note: This rule is not revertable.
1277
+ [[ $subref != *//* ]] || subref=$(tr -s / <<< "$subref")
1278
+
1279
+ ## 7. They cannot end with a dot ..
1280
+ case "$subref" in
1281
+ *.) subref=${subref%.}
1282
+ subref+=%2e
1283
+ ;;
1284
+ esac
1285
+
1286
+ ## 8. They cannot contain a sequence @\{.
1287
+ subref=${subref//@\{/%40\{}
1288
+
1289
+ ## 9. They cannot be the single character @.
1290
+ ## Note: 'subrepo/' be will prefixed, so this is always true.
1291
+
1292
+ ## 10. They cannot contain a \.
1293
+ subref=${subref//\\/%5c}
1294
+
1295
+ subref=$(git check-ref-format --normalize --allow-onelevel "$subref") ||
1296
+ error "Can't determine valid subref from '$subdir'."
1297
+ }
1298
+
1299
+ #------------------------------------------------------------------------------
1300
+ # State file (`.gitrepo`) functions:
1301
+ #------------------------------------------------------------------------------
1302
+
1303
+ # Set subdir and gitrepo vars:
1304
+ read-gitrepo-file() {
1305
+ gitrepo="$subdir/.gitrepo"
1306
+
1307
+ if [[ ! -f $gitrepo ]]; then
1308
+ error "No '$gitrepo' file."
1309
+ fi
1310
+
1311
+ # Read .gitrepo values:
1312
+ if [[ -z $subrepo_remote ]]; then
1313
+ SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.remote
1314
+ subrepo_remote="$output"
1315
+ fi
1316
+
1317
+ if [[ -z $subrepo_branch ]]; then
1318
+ SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.branch
1319
+ subrepo_branch="$output"
1320
+ fi
1321
+
1322
+ SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.commit
1323
+ subrepo_commit="$output"
1324
+
1325
+ FAIL=false \
1326
+ SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.parent
1327
+ subrepo_parent="$output"
1328
+
1329
+ FAIL=false \
1330
+ SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.method
1331
+ if [[ $output == "rebase" ]]; then
1332
+ join_method="rebase"
1333
+ else
1334
+ # This is the default method
1335
+ join_method="merge"
1336
+ fi
1337
+
1338
+ if [[ -z $subrepo_parent ]]; then
1339
+ FAIL=false \
1340
+ SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.former
1341
+ subrepo_former="$output"
1342
+ fi
1343
+ }
1344
+
1345
+
1346
+ # Update the subdir/.gitrepo state file:
1347
+ update-gitrepo-file() {
1348
+ local short_commit=
1349
+
1350
+ local newfile=false
1351
+ if [[ ! -e $gitrepo ]]; then
1352
+
1353
+ FAIL=false RUN git cat-file -e "$original_head_commit":"$gitrepo"
1354
+
1355
+ if OK; then
1356
+ o "Try to recreate gitrepo file from $original_head_commit"
1357
+ git cat-file -p "$original_head_commit":"$gitrepo" > "$gitrepo"
1358
+ else
1359
+ newfile=true
1360
+ cat <<... > "$gitrepo"
1361
+ ; DO NOT EDIT (unless you know what you are doing)
1362
+ ;
1363
+ ; This subdirectory is a git "subrepo", and this file is maintained by the
1364
+ ; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
1365
+ ;
1366
+ ...
1367
+ fi
1368
+ fi
1369
+
1370
+
1371
+ # TODO: only update remote and branch if supplied and $update_wanted
1372
+ if $newfile || [[ $update_wanted && -n $override_remote ]]; then
1373
+ RUN git config --file="$gitrepo" subrepo.remote "$subrepo_remote"
1374
+ fi
1375
+
1376
+ if $newfile || [[ $update_wanted && -n $override_branch ]]; then
1377
+ RUN git config --file="$gitrepo" subrepo.branch "$subrepo_branch"
1378
+ fi
1379
+
1380
+ RUN git config --file="$gitrepo" subrepo.commit "$upstream_head_commit"
1381
+ # Only write new parent when we are at the head of upstream
1382
+ if [[ -n $upstream_head_commit && -n $subrepo_commit_ref ]]; then
1383
+ OUT=true RUN git rev-parse "$subrepo_commit_ref"
1384
+ o "$upstream_head_commit == $output"
1385
+ if [[ $upstream_head_commit == $output ]]; then
1386
+ RUN git config --file="$gitrepo" subrepo.parent "$original_head_commit"
1387
+ fi
1388
+ fi
1389
+
1390
+ [[ -z $join_method ]] && join_method="merge"
1391
+ RUN git config --file="$gitrepo" subrepo.method "$join_method"
1392
+
1393
+ RUN git config --file="$gitrepo" subrepo.cmdver "$VERSION"
1394
+
1395
+ RUN git add -f -- "$gitrepo"
1396
+ }
1397
+
1398
+ #------------------------------------------------------------------------------
1399
+ # Enviroment checks:
1400
+ #------------------------------------------------------------------------------
1401
+
1402
+ # Check that system is ok for this command:
1403
+ assert-environment-ok() {
1404
+ type git &> /dev/null ||
1405
+ error "Can't find your 'git' command in '$PATH'."
1406
+
1407
+ git_version=$(git --version | cut -d ' ' -f3)
1408
+
1409
+ if [[ $(
1410
+ printf "$REQUIRED_GIT_VERSION\n$git_version" |
1411
+ sort -t. -k 1,1n -k 2,2n -k 3,3n |
1412
+ head -n1
1413
+ ) == "$git_version" &&
1414
+ $git_version != "$REQUIRED_GIT_VERSION"
1415
+ ]]; then
1416
+ error "Requires git version $REQUIRED_GIT_VERSION or higher; "`
1417
+ `"you have '$git_version'."
1418
+ fi
1419
+ }
1420
+
1421
+ # Make sure git repo is ready:
1422
+ assert-repo-is-ready() {
1423
+ # Skip this for trivial info commands:
1424
+ [[ $command =~ ^(help|version|upgrade)$ ]] && return
1425
+
1426
+ # We must be inside a git repo:
1427
+ git rev-parse --git-dir &> /dev/null ||
1428
+ error "Not inside a git repository."
1429
+
1430
+ # Get the original branch and commit:
1431
+ git:get-head-branch-name
1432
+ original_head_branch="$output"
1433
+
1434
+ # If a subrepo branch is currently checked out, then note it:
1435
+ if [[ $original_head_branch =~ ^subrepo/(.*) ]]; then
1436
+ error "Can't '$command' while subrepo branch is checked out."
1437
+ fi
1438
+
1439
+ # Make sure we are on a branch:
1440
+ [[ $original_head_branch == HEAD || -z $original_head_branch ]] &&
1441
+ error "Must be on a branch to run this command."
1442
+
1443
+ # In a work-tree:
1444
+ SAY=false OUT=true RUN git rev-parse --is-inside-work-tree
1445
+ [[ $output == true ]] ||
1446
+ error "Can't 'subrepo $command' outside a working tree."
1447
+
1448
+ # HEAD exists:
1449
+ [[ $command == clone ]] ||
1450
+ RUN git rev-parse --verify HEAD
1451
+
1452
+ assert-working-copy-is-clean
1453
+
1454
+ # For now, only support actions from top of repo:
1455
+ if [[ -n "$(git rev-parse --show-prefix)" ]]; then
1456
+ error "Need to run subrepo command from top level directory of the repo."
1457
+ fi
1458
+ }
1459
+
1460
+ assert-working-copy-is-clean() {
1461
+ # Repo is in a clean state:
1462
+ if [[ $command =~ ^(clone|init|pull|push|branch|commit)$ ]]; then
1463
+ # TODO: Should we check for untracked files?
1464
+ local pwd=$(pwd)
1465
+ o "Assert that working copy is clean: $pwd"
1466
+ git update-index -q --ignore-submodules --refresh
1467
+ git diff-files --quiet --ignore-submodules ||
1468
+ error "Can't $command subrepo. Unstaged changes. ($pwd)"
1469
+ if [[ $command != clone ]] || git:rev-exists HEAD; then
1470
+ git diff-index --quiet --ignore-submodules HEAD ||
1471
+ error "Can't $command subrepo. Working tree has changes. ($pwd)"
1472
+ git diff-index --quiet --cached --ignore-submodules HEAD ||
1473
+ error "Can't $command subrepo. Index has changes. ($pwd)"
1474
+ else
1475
+ # Repo has no commits and we're cloning a subrepo. Working tree won't
1476
+ # possibly have changes as there was nothing initial to change.
1477
+ [[ -z $(git ls-files) ]] ||
1478
+ error "Can't $command subrepo. Index has changes. ($pwd)"
1479
+ fi
1480
+ fi
1481
+ }
1482
+
1483
+ # If subdir exists, make sure it is empty:
1484
+ assert-subdir-ready-for-init() {
1485
+ if [[ ! -e $subdir ]]; then
1486
+ error "The subdir '$subdir' does not exist."
1487
+ fi
1488
+ if [[ -e $subdir/.gitrepo ]]; then
1489
+ error "The subdir '$subdir' is already a subrepo."
1490
+ fi
1491
+ # Check that subdir is part of the repo
1492
+ if [[ -z $(git log -1 -- $subdir) ]]; then
1493
+ error "The subdir '$subdir' is not part of this repo."
1494
+ fi
1495
+ }
1496
+
1497
+ # If subdir exists, make sure it is empty:
1498
+ assert-subdir-empty() {
1499
+ if [[ -e $subdir ]] && [[ -n $(ls -A $subdir) ]]; then
1500
+ error "The subdir '$subdir' exists and is not empty."
1501
+ fi
1502
+ }
1503
+
1504
+ #------------------------------------------------------------------------------
1505
+ # Getters of various information:
1506
+ #------------------------------------------------------------------------------
1507
+
1508
+ # Find all the current subrepos by looking for all the subdirectories that
1509
+ # contain a `.gitrepo` file.
1510
+ get-all-subrepos() {
1511
+ local paths=($(
1512
+ find . -name '.gitrepo' |
1513
+ grep -v '/.git/' |
1514
+ grep '/.gitrepo$' |
1515
+ sed 's/.gitrepo$//' |
1516
+ sort
1517
+ ))
1518
+ subrepos=()
1519
+ local path
1520
+ for path in "${paths[@]}"; do
1521
+ add-subrepo "$path"
1522
+ done
1523
+ }
1524
+
1525
+ add-subrepo() {
1526
+ if ! $ALL_wanted; then
1527
+ for path in "${subrepos[@]}"; do
1528
+ [[ $1 =~ ^$path ]] && return
1529
+ done
1530
+ fi
1531
+ subrepos+=("$1")
1532
+ }
1533
+
1534
+ # Determine the upstream's default head branch:
1535
+ get-upstream-head-branch() {
1536
+ OUT=true RUN git ls-remote $subrepo_remote
1537
+ local remotes="$output"
1538
+ [[ -n $remotes ]] ||
1539
+ error "Failed to 'git ls-remote $subrepo_remote'."
1540
+ local commit="$(
1541
+ echo "$remotes" |
1542
+ grep HEAD |
1543
+ cut -f1
1544
+ )"
1545
+ local branch="$(
1546
+ echo "$remotes" |
1547
+ grep -E "$commit[[:space:]]+refs/heads/" |
1548
+ grep -v HEAD |
1549
+ head -n1 |
1550
+ cut -f2
1551
+ )"
1552
+ [[ $branch =~ refs/heads/ ]] ||
1553
+ error "Problem finding remote default head branch."
1554
+ output="${branch#refs/heads/}"
1555
+ }
1556
+
1557
+ # Commit msg for an action commit:
1558
+ # Don't use RUN here as it will pollute commit message
1559
+ get-commit-message() {
1560
+ local commit="none"
1561
+ if git:rev-exists "$upstream_head_commit"; then
1562
+ commit=$(git rev-parse --short "$upstream_head_commit")
1563
+ fi
1564
+
1565
+ local args=() debug_wanted=false
1566
+ if $all_wanted; then
1567
+ args+=("$subdir")
1568
+ fi
1569
+ args+=(${commit_msg_args[@]})
1570
+
1571
+ # Find the specific git-subrepo code used:
1572
+ local command_remote='???'
1573
+ local command_commit='???'
1574
+ get-command-info
1575
+
1576
+ local merged="none"
1577
+ if git:rev-exists "$subrepo_commit_ref"; then
1578
+ merged=$(git rev-parse --short "$subrepo_commit_ref")
1579
+ fi
1580
+
1581
+ local is_merge=""
1582
+ if [[ $command != push ]]; then
1583
+ if git:is_merge_commit "$subrepo_commit_ref"; then
1584
+ is_merge=" (merge)"
1585
+ fi
1586
+ fi
1587
+
1588
+ # TODO: Consider output for push!
1589
+
1590
+ # Format subrepo commit message:
1591
+ cat <<...
1592
+ git subrepo $command$is_merge ${args[@]}
1593
+
1594
+ subrepo:
1595
+ subdir: "$subdir"
1596
+ merged: "$merged"
1597
+ upstream:
1598
+ origin: "$subrepo_remote"
1599
+ branch: "$subrepo_branch"
1600
+ commit: "$commit"
1601
+ git-subrepo:
1602
+ version: "$VERSION"
1603
+ origin: "$command_remote"
1604
+ commit: "$command_commit"
1605
+ ...
1606
+ }
1607
+
1608
+ # Get location and version info about the git-subrepo command itself. This
1609
+ # info goes into commit messages, so we can find out exactly how the commits
1610
+ # were done.
1611
+ get-command-info() {
1612
+ local bin="$0"
1613
+ if [[ $bin =~ / ]]; then
1614
+ local lib="$(dirname "$bin")"
1615
+ # XXX Makefile needs to install these symlinks:
1616
+ # If `git-subrepo` was system-installed (`make install`):
1617
+ if [[ -e $lib/git-subrepo.d/upstream ]] &&
1618
+ [[ -e $lib/git-subrepo.d/commit ]]; then
1619
+ command_remote=$(readlink "$lib/git-subrepo.d/upstream")
1620
+ command_commit=$(readlink "$lib/git-subrepo.d/commit")
1621
+ elif [[ $lib =~ / ]]; then
1622
+ lib="$(dirname "$lib")"
1623
+ if [[ -d $lib/.git ]]; then
1624
+ local remote="$(
1625
+ GIT_DIR=$lib/.git git remote -v |
1626
+ grep '^origin' |
1627
+ head -n1 |
1628
+ cut -f2 |
1629
+ cut -d ' ' -f1
1630
+ )"
1631
+ if [[ -n $remote ]]; then
1632
+ command_remote="$remote"
1633
+ else
1634
+ local remote="$(
1635
+ GIT_DIR=$lib/.git git remote -v |
1636
+ head -n1 |
1637
+ cut -f2 |
1638
+ cut -d ' ' -f1
1639
+ )"
1640
+ if [[ -n $remote ]]; then
1641
+ command_remote="$remote"
1642
+ fi
1643
+ fi
1644
+ local commit="$(GIT_DIR="$lib/.git" git rev-parse --short HEAD)"
1645
+ if [[ -n $commit ]]; then
1646
+ command_commit="$commit"
1647
+ fi
1648
+ fi
1649
+ fi
1650
+ fi
1651
+ }
1652
+
1653
+ #------------------------------------------------------------------------------
1654
+ # Instructional errors:
1655
+ #------------------------------------------------------------------------------
1656
+
1657
+ error-join() {
1658
+ cat <<...
1659
+
1660
+ You will need to finish the $command by hand. A new working tree has been
1661
+ created at $worktree so that you can resolve the conflicts
1662
+ shown in the output above.
1663
+
1664
+ This is the common conflict resolution workflow:
1665
+
1666
+ 1. cd $worktree
1667
+ 2. Resolve the conflicts (see "git status").
1668
+ 3. "git add" the resolved files.
1669
+ ...
1670
+
1671
+ if [[ "$join_method" == "rebase" ]]; then
1672
+ cat <<...
1673
+ 4. git rebase --continue
1674
+ ...
1675
+ else
1676
+ cat <<...
1677
+ 4. git commit
1678
+ ...
1679
+ fi
1680
+
1681
+ cat <<...
1682
+ 5. If there are more conflicts, restart at step 2.
1683
+ 6. cd $start_pwd
1684
+ ...
1685
+ local branch_name="${branch:=subrepo/$subdir}"
1686
+ if [[ "$command" == "push" ]]; then
1687
+ cat <<...
1688
+ 7. git subrepo push $subdir $branch_name
1689
+ ...
1690
+ else
1691
+ cat <<...
1692
+ 7. git subrepo commit $subdir
1693
+ ...
1694
+ fi
1695
+
1696
+ if [[ "$command" == "pull" && "$join_method" == "rebase" ]]; then
1697
+ cat <<...
1698
+
1699
+ After you have performed the steps above you can push your local changes
1700
+ without repeating the rebase by:
1701
+ 1. git subrepo push $subdir $branch_name
1702
+
1703
+ ...
1704
+ fi
1705
+
1706
+ cat <<...
1707
+ See "git help $join_method" for details.
1708
+
1709
+ Alternatively, you can abort the $command and reset back to where you started:
1710
+
1711
+ 1. git subrepo clean $subdir
1712
+
1713
+ See "git help subrepo" for more help.
1714
+
1715
+ ...
1716
+ }
1717
+
1718
+ #------------------------------------------------------------------------------
1719
+ # Git command wrappers:
1720
+ #------------------------------------------------------------------------------
1721
+
1722
+ git:branch-exists() {
1723
+ git:rev-exists "refs/heads/$1"
1724
+ }
1725
+
1726
+ git:rev-exists() {
1727
+ git rev-list "$1" -1 &> /dev/null
1728
+ }
1729
+
1730
+ git:ref-exists() {
1731
+ test -n "$(git for-each-ref "$1")"
1732
+ }
1733
+
1734
+ git:get-head-branch-name() {
1735
+ output=
1736
+ local name="$(git symbolic-ref --short --quiet HEAD)"
1737
+ [[ $name == HEAD ]] && return
1738
+ output="$name"
1739
+ }
1740
+
1741
+ git:get-head-branch-commit() {
1742
+ output="$(git rev-parse HEAD)"
1743
+ }
1744
+
1745
+ git:commit-in-rev-list() {
1746
+ local commit="$1"
1747
+ local list_head="$2"
1748
+ git rev-list "$list_head" | grep -q "^$commit"
1749
+ }
1750
+
1751
+ git:make-ref() {
1752
+ local ref_name="$1"
1753
+ local commit="$(git rev-parse "$2")"
1754
+ RUN git update-ref "$ref_name" "$commit"
1755
+ }
1756
+
1757
+ git:is_merge_commit() {
1758
+ local commit="$1"
1759
+ git show --summary "$commit" | grep -q ^Merge:
1760
+ }
1761
+
1762
+ git:create-worktree() {
1763
+ local branch="$1"
1764
+ worktree="$GIT_TMP/$branch"
1765
+ RUN git worktree add "$worktree" "$branch"
1766
+ }
1767
+
1768
+ git:remove-worktree() {
1769
+ o "Remove worktree: $worktree"
1770
+ if [[ -d "$worktree" ]]; then
1771
+ o "Check worktree for unsaved changes"
1772
+ cd "$worktree"
1773
+ assert-working-copy-is-clean
1774
+ cd "$start_pwd"
1775
+
1776
+ o "Clean up worktree $worktree"
1777
+ rm -rf "$worktree"
1778
+ RUN git worktree prune
1779
+ fi
1780
+ }
1781
+
1782
+ git:delete-branch() {
1783
+ local branch="$1"
1784
+ o "Deleting old '$branch' branch."
1785
+ # Remove worktree first, otherwise you can't delete the branch
1786
+ git:remove-worktree
1787
+ FAIL=false RUN git branch -D "$branch"
1788
+ }
1789
+
1790
+
1791
+ #------------------------------------------------------------------------------
1792
+ # Low level sugar commands:
1793
+ #------------------------------------------------------------------------------
1794
+
1795
+ # Smart command runner:
1796
+ RUN() {
1797
+ $debug_wanted && $SAY && say '>>>' $*
1798
+ if $EXEC; then
1799
+ "$@"
1800
+ return $?
1801
+ fi
1802
+
1803
+ OK=true
1804
+ set +e
1805
+ local rc=
1806
+ local out=
1807
+ if $debug_wanted && $TTY && interactive; then
1808
+ "$@"
1809
+ else
1810
+ if $OUT; then
1811
+ out="$("$@" 2>/dev/null)"
1812
+ else
1813
+ out="$("$@" 2>&1)"
1814
+ fi
1815
+ fi
1816
+ rc=$?
1817
+ set -e
1818
+
1819
+ if [[ $rc -ne 0 ]]; then
1820
+ OK=false
1821
+ $FAIL && error "Command failed: '$*'.\n$out"
1822
+ fi
1823
+ output="$out"
1824
+ }
1825
+
1826
+
1827
+ interactive() {
1828
+ if [[ -t 0 && -t 1 ]]; then
1829
+ return 0
1830
+ else
1831
+ return 1
1832
+ fi
1833
+ }
1834
+
1835
+ # Call a function with indent increased:
1836
+ CALL() {
1837
+ local INDENT=" $INDENT"
1838
+ "$@" || true
1839
+ }
1840
+
1841
+ # Print verbose steps for commands with steps:
1842
+ o() {
1843
+ if $verbose_wanted; then
1844
+ echo "$INDENT* $@"
1845
+ fi
1846
+ }
1847
+
1848
+ # Print unless quiet mode:
1849
+ say() {
1850
+ $quiet_wanted || echo "$@"
1851
+ }
1852
+
1853
+ # Print to stderr:
1854
+ err() {
1855
+ echo "$@" >&2
1856
+ }
1857
+
1858
+ # Check if OK:
1859
+ OK() {
1860
+ $OK
1861
+ }
1862
+
1863
+ # Nicely report common error messages:
1864
+ usage-error() {
1865
+ local msg="git-subrepo: $1" usage=
1866
+ if [[ $GIT_SUBREPO_TEST_ERRORS != true ]]; then
1867
+ source "${SOURCE_DIR}/git-subrepo.d/help-functions.bash"
1868
+ if can "help:$command"; then
1869
+ msg=$'\n'"$msg"$'\n'"$("help:$command")"$'\n'
1870
+ fi
1871
+ fi
1872
+ echo "$msg" >&2
1873
+ exit 1
1874
+ }
1875
+
1876
+ # Nicely report common error messages:
1877
+ error() {
1878
+ local msg="git-subrepo: $1" usage=
1879
+ echo -e "$msg" >&2
1880
+ exit 1
1881
+ }
1882
+
1883
+ # Start at the end:
1884
+ [[ $BASH_SOURCE != "$0" ]] || main "$@"
1885
+
1886
+ # Local Variables:
1887
+ # tab-width: 2
1888
+ # sh-indentation: 2
1889
+ # sh-basic-offset: 2
1890
+ # End:
1891
+ # vim: set ft=sh sw=2 lisp: