eac_git 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/lib/eac_git/local/changed_file.rb +6 -0
  3. data/lib/eac_git/local/remote.rb +0 -2
  4. data/lib/eac_git/local/subrepo/config.rb +2 -0
  5. data/lib/eac_git/local.rb +1 -1
  6. data/lib/eac_git/remote_like/ls_result.rb +1 -1
  7. data/lib/eac_git/remote_like.rb +0 -1
  8. data/lib/eac_git/rspec/stubbed_git_local_repo.rb +0 -2
  9. data/lib/eac_git/rspec.rb +0 -1
  10. data/lib/eac_git/version.rb +1 -1
  11. data/lib/eac_git.rb +0 -2
  12. data/vendor/git-subrepo/.fish.rc +20 -0
  13. data/vendor/git-subrepo/.gitattributes +1 -0
  14. data/vendor/git-subrepo/.github/workflows/test.yml +29 -0
  15. data/vendor/git-subrepo/.gitignore +1 -0
  16. data/vendor/git-subrepo/.gitrepo +7 -0
  17. data/vendor/git-subrepo/.rc +32 -0
  18. data/vendor/git-subrepo/Changes +66 -0
  19. data/vendor/git-subrepo/Intro.pod +2 -5
  20. data/vendor/git-subrepo/Makefile +45 -5
  21. data/vendor/git-subrepo/Meta +2 -2
  22. data/vendor/git-subrepo/ReadMe.pod +26 -31
  23. data/vendor/git-subrepo/doc/git-subrepo.swim +22 -18
  24. data/vendor/git-subrepo/doc/intro-to-subrepo.swim +2 -4
  25. data/vendor/git-subrepo/ext/bashplus/.gitrepo +12 -0
  26. data/vendor/git-subrepo/ext/bashplus/.travis.yml +6 -0
  27. data/vendor/git-subrepo/ext/bashplus/Changes +19 -0
  28. data/vendor/git-subrepo/ext/bashplus/License +1 -1
  29. data/vendor/git-subrepo/ext/bashplus/Makefile +25 -0
  30. data/vendor/git-subrepo/ext/bashplus/Meta +4 -4
  31. data/vendor/git-subrepo/ext/bashplus/ReadMe.pod +2 -2
  32. data/vendor/git-subrepo/ext/bashplus/bin/bash+ +8 -7
  33. data/vendor/git-subrepo/ext/bashplus/doc/bash+.swim +1 -1
  34. data/vendor/git-subrepo/ext/bashplus/lib/bash+.bash +85 -38
  35. data/vendor/git-subrepo/ext/bashplus/man/man1/bash+.1 +8 -8
  36. data/vendor/git-subrepo/ext/bashplus/man/man3/bash+.3 +8 -8
  37. data/vendor/git-subrepo/ext/bashplus/test/base.t +4 -5
  38. data/vendor/git-subrepo/ext/bashplus/test/die.t +16 -0
  39. data/vendor/git-subrepo/ext/bashplus/test/fcopy.t +2 -3
  40. data/vendor/git-subrepo/ext/bashplus/test/{test.bash → setup} +18 -8
  41. data/vendor/git-subrepo/ext/bashplus/test/shellcheck.t +37 -0
  42. data/vendor/git-subrepo/ext/bashplus/test/source-bash+-std.t +10 -11
  43. data/vendor/git-subrepo/ext/bashplus/test/source-bash+.t +10 -11
  44. data/vendor/git-subrepo/ext/bashplus/test/use.t +8 -5
  45. data/vendor/git-subrepo/ext/bashplus/test/version-check.t +23 -0
  46. data/vendor/git-subrepo/ext/test-more-bash/.gitrepo +12 -0
  47. data/vendor/git-subrepo/ext/test-more-bash/.travis.yml +6 -0
  48. data/vendor/git-subrepo/ext/test-more-bash/Changes +11 -0
  49. data/vendor/git-subrepo/ext/test-more-bash/License +1 -1
  50. data/vendor/git-subrepo/ext/test-more-bash/Makefile +25 -0
  51. data/vendor/git-subrepo/ext/test-more-bash/Meta +5 -5
  52. data/vendor/git-subrepo/ext/test-more-bash/ReadMe.pod +9 -3
  53. data/vendor/git-subrepo/ext/test-more-bash/doc/test-more.swim +7 -2
  54. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/.gitrepo +12 -0
  55. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/.travis.yml +6 -0
  56. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/Changes +11 -0
  57. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/License +1 -1
  58. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/Makefile +25 -0
  59. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/Meta +3 -3
  60. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/ReadMe.pod +2 -2
  61. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/bin/bash+ +8 -7
  62. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/doc/bash+.swim +1 -1
  63. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/lib/bash+.bash +85 -38
  64. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/man/man1/bash+.1 +8 -8
  65. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/man/man3/bash+.3 +8 -8
  66. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/base.t +4 -4
  67. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/die.t +17 -0
  68. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/fcopy.t +2 -2
  69. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/{test.bash → setup} +17 -8
  70. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/shellcheck.t +38 -0
  71. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/source-bash+-std.t +10 -10
  72. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/source-bash+.t +10 -10
  73. data/vendor/git-subrepo/ext/test-more-bash/ext/bashplus/test/use.t +8 -4
  74. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/.gitrepo +12 -0
  75. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/.travis.yml +5 -0
  76. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/Changes +11 -0
  77. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/License +1 -1
  78. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/Makefile +30 -0
  79. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/Meta +3 -3
  80. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/ReadMe.pod +2 -2
  81. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/doc/test-tap.swim +1 -1
  82. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/lib/test/tap.bash +46 -42
  83. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/man/man3/test-tap.3 +8 -8
  84. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/bail_out.t +1 -1
  85. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/fail.t +1 -1
  86. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/fail_fast.t +1 -1
  87. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/helper.bash +1 -1
  88. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/shellcheck.t +42 -0
  89. data/vendor/git-subrepo/ext/test-more-bash/ext/test-tap-bash/test/tap.t +11 -5
  90. data/vendor/git-subrepo/ext/test-more-bash/lib/test/more.bash +35 -15
  91. data/vendor/git-subrepo/ext/test-more-bash/man/man3/test-more.3 +16 -10
  92. data/vendor/git-subrepo/ext/test-more-bash/test/fail.t +15 -1
  93. data/vendor/git-subrepo/ext/test-more-bash/test/more.t +12 -4
  94. data/vendor/git-subrepo/ext/test-more-bash/test/setup +3 -3
  95. data/vendor/git-subrepo/ext/test-more-bash/test/shellcheck.t +35 -0
  96. data/vendor/git-subrepo/ext/test-more-bash/test/test/fail1.t +14 -1
  97. data/vendor/git-subrepo/lib/git-subrepo +375 -260
  98. data/vendor/git-subrepo/lib/git-subrepo.d/help-functions.bash +21 -22
  99. data/vendor/git-subrepo/man/man1/git-subrepo.1 +125 -141
  100. data/vendor/git-subrepo/pkg/bin/generate-completion.pl +0 -7
  101. data/vendor/git-subrepo/pkg/bin/generate-help-functions.pl +0 -2
  102. data/vendor/git-subrepo/share/completion.bash +1 -3
  103. data/vendor/git-subrepo/share/enable-completion.sh +3 -3
  104. data/vendor/git-subrepo/share/zsh-completion/_git-subrepo +2 -7
  105. data/vendor/git-subrepo/test/Dockerfile +112 -0
  106. data/vendor/git-subrepo/test/branch-all.t +6 -6
  107. data/vendor/git-subrepo/test/branch-rev-list-one-path.t +7 -8
  108. data/vendor/git-subrepo/test/branch-rev-list.t +7 -8
  109. data/vendor/git-subrepo/test/branch.t +9 -9
  110. data/vendor/git-subrepo/test/clean.t +3 -3
  111. data/vendor/git-subrepo/test/clone-annotated-tag.t +7 -7
  112. data/vendor/git-subrepo/test/clone.t +20 -25
  113. data/vendor/git-subrepo/test/config.t +7 -6
  114. data/vendor/git-subrepo/test/encode.t +17 -17
  115. data/vendor/git-subrepo/test/error.t +18 -18
  116. data/vendor/git-subrepo/test/fetch.t +4 -4
  117. data/vendor/git-subrepo/test/gitignore.t +8 -8
  118. data/vendor/git-subrepo/test/init.t +6 -7
  119. data/vendor/git-subrepo/test/issue29.t +3 -3
  120. data/vendor/git-subrepo/test/issue95.t +2 -2
  121. data/vendor/git-subrepo/test/issue96.t +3 -3
  122. data/vendor/git-subrepo/test/pull-all.t +5 -5
  123. data/vendor/git-subrepo/test/pull-merge.t +16 -15
  124. data/vendor/git-subrepo/test/pull-message.t +12 -12
  125. data/vendor/git-subrepo/test/pull-new-branch.t +8 -7
  126. data/vendor/git-subrepo/test/pull-ours.t +10 -10
  127. data/vendor/git-subrepo/test/pull-theirs.t +8 -8
  128. data/vendor/git-subrepo/test/pull-twice.t +4 -4
  129. data/vendor/git-subrepo/test/pull-worktree.t +5 -5
  130. data/vendor/git-subrepo/test/pull.t +14 -14
  131. data/vendor/git-subrepo/test/push-after-init.t +7 -6
  132. data/vendor/git-subrepo/test/push-after-push-no-changes.t +27 -0
  133. data/vendor/git-subrepo/test/push-force.t +7 -6
  134. data/vendor/git-subrepo/test/push-new-branch.t +10 -10
  135. data/vendor/git-subrepo/test/push-no-changes.t +3 -3
  136. data/vendor/git-subrepo/test/push-squash.t +7 -7
  137. data/vendor/git-subrepo/test/push.t +35 -34
  138. data/vendor/git-subrepo/test/rebase.t +63 -0
  139. data/vendor/git-subrepo/test/reclone.t +15 -8
  140. data/vendor/git-subrepo/test/setup +62 -55
  141. data/vendor/git-subrepo/test/shellcheck.t +37 -0
  142. data/vendor/git-subrepo/test/status.t +47 -27
  143. data/vendor/git-subrepo/test/submodule.t +4 -4
  144. data/vendor/git-subrepo/test/zsh.t +27 -0
  145. metadata +45 -13
@@ -4,6 +4,7 @@
4
4
  # Copyright 2013-2020 - Ingy döt Net <ingy@ingy.net>
5
5
  #
6
6
 
7
+ # shellcheck disable=1090,1091,2034
7
8
 
8
9
  # Exit on any errors:
9
10
  set -e
@@ -11,26 +12,28 @@ set -e
11
12
  export FILTER_BRANCH_SQUELCH_WARNING=1
12
13
 
13
14
  # Import Bash+ helper functions:
14
- SOURCE="$BASH_SOURCE"
15
+ SOURCE=${BASH_SOURCE[0]}
15
16
  while [[ -h $SOURCE ]]; do
16
- DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
17
- SOURCE="$(readlink "$SOURCE")"
18
- [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
17
+ DIR=$( cd -P "$( dirname "$SOURCE" )" && pwd )
18
+ SOURCE=$(readlink "$SOURCE")
19
+ [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE
19
20
  done
20
- SOURCE_DIR="$(dirname "$SOURCE")"
21
+ SOURCE_DIR=$(dirname "$SOURCE")
21
22
 
22
- if [[ -z "$GIT_SUBREPO_ROOT" ]]; then
23
+ if [[ -z $GIT_SUBREPO_ROOT ]]; then
23
24
  # If `make install` installation used:
24
25
  source "${SOURCE_DIR}/git-subrepo.d/bash+.bash"
25
26
  else
26
27
  # If `source .rc` method used:
27
28
  source "${SOURCE_DIR}/../ext/bashplus/lib/bash+.bash"
28
29
  fi
29
- bash+:import :std can
30
+ bash+:import :std can version-check
30
31
 
31
- VERSION=0.4.1
32
+
33
+ VERSION=0.4.9
34
+ REQUIRED_BASH_VERSION=4.0
32
35
  REQUIRED_GIT_VERSION=2.7.0
33
- GIT_TMP="$(git rev-parse --git-common-dir 2> /dev/null || echo .git)/tmp"
36
+ GIT_TMP=$(git rev-parse --git-common-dir 2> /dev/null || echo .git)/tmp
34
37
 
35
38
  # `git rev-parse` turns this into a getopt parser and a command usage message:
36
39
  GETOPT_SPEC="\
@@ -61,20 +64,20 @@ Options:
61
64
  h Show the command summary
62
65
  help Help overview
63
66
  version Print the git-subrepo version number
64
-
67
+
65
68
  a,all Perform command on all current subrepos
66
69
  A,ALL Perform command on all subrepos and subsubrepos
67
70
  b,branch= Specify the upstream branch to push/pull/fetch
68
71
  e,edit Edit commit message
69
72
  f,force Force certain operations
70
73
  F,fetch Fetch the upstream content first
71
- M,method= Method when you join, valid options are 'merge' or 'rebase'
72
- Default is 'merge'
74
+ M,method= Join method: 'merge' (default) or 'rebase'
73
75
  m,message= Specify a commit message
76
+ file= Specify a commit message file
74
77
  r,remote= Specify the upstream remote to push/pull/fetch
75
78
  s,squash Squash commits on push
76
79
  u,update Add the --branch and/or --remote overrides to .gitrepo
77
-
80
+
78
81
  q,quiet Show minimal output
79
82
  v,verbose Show verbose output
80
83
  d,debug Show the actual commands used
@@ -106,7 +109,8 @@ main() {
106
109
  local subref= # Valid git ref format of subdir
107
110
  local gitrepo= # Path to .gitrepo file
108
111
  local worktree= # Worktree created by 'git worktree'
109
- local start_pwd=$(pwd) # Store the original directory
112
+ local start_pwd
113
+ start_pwd=$(pwd) # Store the original directory
110
114
 
111
115
  local original_head_commit= # HEAD commit id at start of command
112
116
  local original_head_branch= # HEAD ref at start of command
@@ -128,6 +132,7 @@ main() {
128
132
 
129
133
  local edit_wanted=false # Edit commit message using -e
130
134
  local wanted_commit_message= # Custom commit message using -m
135
+ local commit_msg_file= # Custom commit message using --file
131
136
 
132
137
  local join_method= # Current join method (rebase/merge)
133
138
 
@@ -154,10 +159,14 @@ main() {
154
159
  command-init
155
160
 
156
161
  if $all_wanted && [[ ! $command =~ ^(help|status)$ ]]; then
162
+ if [[ -n $subrepo_branch ]]; then
163
+ error "options --branch and --all are not compatible"
164
+ fi
165
+
157
166
  # Run the command on all subrepos
158
167
  local args=( "${command_arguments[@]}" )
159
168
  get-all-subrepos
160
- for subdir in ${subrepos[*]}; do
169
+ for subdir in "${subrepos[@]}"; do
161
170
  command-prepare
162
171
  subrepo_remote=
163
172
  subrepo_branch=
@@ -195,15 +204,18 @@ command:clone() {
195
204
  # Successful command output:
196
205
  local re=
197
206
  $force_wanted && re=re
198
- local remote="$subrepo_remote"
207
+ local remote=$subrepo_remote
199
208
  say "Subrepo '$remote' ($subrepo_branch) ${re}cloned into '$subdir'."
200
209
  }
201
210
 
202
211
  # `git subrepo init <subdir>` command:
203
212
  command:init() {
204
213
  command-setup +subdir
205
- local remote="${subrepo_remote:=none}"
206
- local branch="${subrepo_branch:=master}"
214
+ local default_branch=
215
+ default_branch=$(git config init.defaultbranch)
216
+ default_branch=${default_branch:=master}
217
+ local remote=${subrepo_remote:=none}
218
+ local branch=${subrepo_branch:=$default_branch}
207
219
 
208
220
  # Init new subrepo from the subdir:
209
221
  subrepo:init
@@ -259,7 +271,7 @@ command:push() {
259
271
  # `git subrepo fetch <subdir>` command
260
272
  command:fetch() {
261
273
  command-setup +subdir
262
- if [[ $subrepo_remote == "none" ]]; then
274
+ if [[ $subrepo_remote == none ]]; then
263
275
  say "Ignored '$subdir', no remote."
264
276
  else
265
277
  subrepo:fetch
@@ -274,10 +286,10 @@ command:branch() {
274
286
  CALL subrepo:fetch
275
287
  fi
276
288
 
277
- local branch="subrepo/$subref"
289
+ local branch=subrepo/$subref
278
290
  if $force_wanted; then
279
291
  # We must make sure that the worktree is removed as well
280
- worktree="$GIT_TMP/$branch"
292
+ worktree=$GIT_TMP/$branch
281
293
  git:delete-branch "$branch"
282
294
  fi
283
295
 
@@ -300,10 +312,10 @@ command:commit() {
300
312
  fi
301
313
  git:rev-exists "$refs_subrepo_fetch" ||
302
314
  error "Can't find ref '$refs_subrepo_fetch'. Try using -F."
303
- upstream_head_commit="$(git rev-parse "$refs_subrepo_fetch")"
315
+ upstream_head_commit=$(git rev-parse "$refs_subrepo_fetch")
304
316
 
305
- [[ -n $subrepo_commit_ref ]] ||
306
- subrepo_commit_ref="subrepo/$subref"
317
+ [[ ${subrepo_commit_ref-} ]] ||
318
+ subrepo_commit_ref=subrepo/$subref
307
319
  subrepo:commit
308
320
 
309
321
  say "Subrepo commit '$subrepo_commit_ref' committed as"
@@ -317,11 +329,11 @@ command:status() {
317
329
 
318
330
  status-refs() {
319
331
  local output=
320
- while read line; do
332
+ while read -r line; do
321
333
  [[ $line =~ ^([0-9a-f]+)\ refs/subrepo/$subref/([a-z]+) ]] || continue
322
- local sha1=; sha1="$(git rev-parse --short "${BASH_REMATCH[1]}")"
323
- local type="${BASH_REMATCH[2]}"
324
- local ref="refs/subrepo/$subref/$type"
334
+ local sha1=; sha1=$(git rev-parse --short "${BASH_REMATCH[1]}")
335
+ local type=${BASH_REMATCH[2]}
336
+ local ref=refs/subrepo/$subref/$type
325
337
  if [[ $type == branch ]]; then
326
338
  output+=" Branch Ref: $sha1 ($ref)"$'\n'
327
339
  elif [[ $type == commit ]]; then
@@ -334,8 +346,8 @@ status-refs() {
334
346
  output+=" Push Ref: $sha1 ($ref)"$'\n'
335
347
  fi
336
348
  done < <(git show-ref)
337
- if [[ -n $output ]]; then
338
- printf " Refs:\n$output"
349
+ if [[ $output ]]; then
350
+ printf " Refs:\n%s" "$output"
339
351
  fi
340
352
  }
341
353
 
@@ -352,13 +364,14 @@ command:clean() {
352
364
  # Wrap git config $gitrepo
353
365
  command:config() {
354
366
  command-setup +subdir +config_option config_value
355
- o "Update '$subdir' configuration with $config_option=$config_value"
367
+ # shellcheck disable=2154
368
+ o "Update '$subdir' configuration with $config_option=${config_value-}"
356
369
 
357
370
  if [[ ! $config_option =~ ^(branch|cmdver|commit|method|remote|version)$ ]]; then
358
371
  error "Option $config_option not recognized"
359
372
  fi
360
373
 
361
- if [[ -z $config_value ]]; then
374
+ if [[ -z ${config_value-} ]]; then
362
375
  OUT=true RUN git config --file="$gitrepo" "subrepo.$config_option"
363
376
  say "Subrepo '$subdir' option '$config_option' has value '$output'."
364
377
  return
@@ -366,12 +379,12 @@ command:config() {
366
379
 
367
380
  if ! $force_wanted; then
368
381
  # Only allow changing method without force
369
- if [[ ! $config_option == "method" ]]; then
382
+ if [[ $config_option != method ]]; then
370
383
  error "This option is autogenerated, use '--force' to override."
371
384
  fi
372
385
  fi
373
386
 
374
- if [[ $config_option == "method" ]]; then
387
+ if [[ $config_option == method ]]; then
375
388
  if [[ ! $config_value =~ ^(merge|rebase)$ ]]; then
376
389
  error "Not a valid method. Valid options are 'merge' or 'rebase'."
377
390
  fi
@@ -385,8 +398,8 @@ command:config() {
385
398
  # Launch the manpage viewer:
386
399
  command:help() {
387
400
  source "${SOURCE_DIR}/git-subrepo.d/help-functions.bash"
388
- local cmd="${command_arguments[0]}"
389
- if [[ -n $cmd ]]; then
401
+ local cmd=${command_arguments[0]}
402
+ if [[ $cmd ]]; then
390
403
  if can "help:$cmd"; then
391
404
  "help:$cmd"
392
405
  echo
@@ -409,7 +422,7 @@ command:version() {
409
422
  git-subrepo Version: $VERSION
410
423
  Copyright 2013-2020 Ingy döt Net
411
424
  https://github.com/ingydotnet/git-subrepo
412
- $BASH_SOURCE
425
+ ${BASH_SOURCE[0]}
413
426
  Git Version: $git_version
414
427
 
415
428
  ...
@@ -417,15 +430,15 @@ Git Version: $git_version
417
430
  }
418
431
 
419
432
  command:upgrade() {
420
- local path="$0"
433
+ local path=$0
421
434
  if [[ $path =~ ^/ && $path =~ ^(.*/git-subrepo)/lib/git-subrepo$ ]]; then
422
- local subrepo_root="${BASH_REMATCH[1]}"
435
+ local subrepo_root=${BASH_REMATCH[1]}
423
436
  (
424
437
  o "Change directory to '$subrepo_root'."
425
438
  cd "${BASH_REMATCH[1]}"
426
439
 
427
- local branch="$(git rev-parse --abbrev-ref HEAD)"
428
- if [[ $branch != master ]]; then
440
+ branch_name=$(git rev-parse --abbrev-ref HEAD)
441
+ if [[ $branch_name != master ]]; then
429
442
  error "git-subrepo repo is not on the 'master' branch"
430
443
  fi
431
444
 
@@ -457,8 +470,6 @@ If you used 'make install' to install git-subrepo, then just do this:
457
470
 
458
471
  # Clone by fetching remote content into our subdir:
459
472
  subrepo:clone() {
460
- re="$1"
461
-
462
473
  FAIL=false RUN git rev-parse HEAD
463
474
  if ! OK; then
464
475
  error "You can't clone into an empty repository"
@@ -474,18 +485,25 @@ subrepo:clone() {
474
485
  CALL subrepo:fetch
475
486
  read-gitrepo-file
476
487
  o "Check if we already are up to date."
477
- if [[ $upstream_head_commit == $subrepo_commit ]]; then
488
+ if [[ $upstream_head_commit == "$subrepo_commit" ]]; then
478
489
  reclone_up_to_date=true
479
490
  return
480
491
  fi
481
492
  o "Remove the old subdir."
482
493
  RUN git rm -r -- "$subdir"
494
+
495
+ if [[ -z $override_branch ]]; then
496
+ o "Determine the upstream head branch."
497
+ get-upstream-head-branch
498
+ subrepo_branch="$output"
499
+ override_branch="$output" # Force update of the branch in .gitrepo
500
+ fi
483
501
  else
484
502
  assert-subdir-empty
485
503
  if [[ -z $subrepo_branch ]]; then
486
504
  o "Determine the upstream head branch."
487
505
  get-upstream-head-branch
488
- subrepo_branch="$output"
506
+ subrepo_branch=$output
489
507
  fi
490
508
 
491
509
  CALL subrepo:fetch
@@ -495,13 +513,13 @@ subrepo:clone() {
495
513
  RUN mkdir -p -- "$subdir"
496
514
 
497
515
  o "Commit the new '$subdir/' content."
498
- subrepo_commit_ref="$upstream_head_commit"
516
+ subrepo_commit_ref=$upstream_head_commit
499
517
  CALL subrepo:commit
500
518
  }
501
519
 
502
520
  # Init a new subrepo from current repo:
503
521
  subrepo:init() {
504
- local branch_name="subrepo/${subref:??}"
522
+ local branch_name=subrepo/${subref:??}
505
523
  # Check if subdir is proper candidate for this init:
506
524
  assert-subdir-ready-for-init
507
525
 
@@ -513,7 +531,7 @@ subrepo:init() {
513
531
  RUN git add -f -- "$gitrepo"
514
532
 
515
533
  o "Commit new subrepo to the '$original_head_branch' branch."
516
- subrepo_commit_ref="$original_head_commit"
534
+ subrepo_commit_ref=$original_head_commit
517
535
  RUN git commit -m "$(get-commit-message)"
518
536
 
519
537
  o "Create ref '$refs_subrepo_commit'."
@@ -524,22 +542,28 @@ subrepo:init() {
524
542
  subrepo:pull() {
525
543
  CALL subrepo:fetch
526
544
 
545
+ # If forced pull, then clone instead
546
+ if $force_wanted; then
547
+ CALL subrepo:clone
548
+ return
549
+ fi
550
+
527
551
  # Check if we already are up to date
528
552
  # If the -u flag is present, always perform the operation
529
- if [[ $upstream_head_commit == $subrepo_commit ]] && ! $update_wanted; then
553
+ if [[ $upstream_head_commit == "$subrepo_commit" ]] && ! $update_wanted; then
530
554
  OK=false; CODE=-1; return
531
555
  fi
532
556
 
533
- local branch_name="subrepo/$subref"
557
+ local branch_name=subrepo/$subref
534
558
  git:delete-branch "$branch_name"
535
559
 
536
- subrepo_commit_ref="$branch_name"
560
+ subrepo_commit_ref=$branch_name
537
561
 
538
562
  o "Create subrepo branch '$branch_name'."
539
563
  CALL subrepo:branch
540
564
  cd "$worktree";
541
565
 
542
- if [[ "$join_method" == "rebase" ]]; then
566
+ if [[ $join_method == rebase ]]; then
543
567
  o "Rebase changes to $refs_subrepo_fetch"
544
568
  FAIL=false OUT=true RUN git rebase "$refs_subrepo_fetch" "$branch_name"
545
569
  if ! OK; then
@@ -573,7 +597,7 @@ subrepo:pull() {
573
597
 
574
598
  # Push a properly merged subrepo branch upstream:
575
599
  subrepo:push() {
576
- local branch_name="$branch"
600
+ local branch_name=$branch
577
601
  local new_upstream=false
578
602
  local branch_created=false
579
603
 
@@ -595,25 +619,27 @@ subrepo:push() {
595
619
  # Check that we are up to date:
596
620
  o "Check upstream head against .gitrepo commit."
597
621
  if ! $force_wanted; then
598
- if [[ $upstream_head_commit != $subrepo_commit ]]; then
622
+ if [[ $upstream_head_commit != "$subrepo_commit" ]]; then
599
623
  error "There are new changes upstream, you need to pull first."
600
624
  fi
601
625
  fi
602
626
  fi
603
627
 
604
- branch_name="subrepo/$subref"
628
+ branch_name=subrepo/$subref
629
+ # We must make sure that a stale worktree is removed as well
630
+ worktree=$GIT_TMP/$branch_name
605
631
  git:delete-branch "$branch_name"
606
632
 
607
633
  if $squash_wanted; then
608
634
  o "Squash commits"
609
- subrepo_parent="HEAD^"
635
+ subrepo_parent=HEAD^
610
636
  fi
611
637
 
612
638
  o "Create subrepo branch '$branch_name'."
613
639
  CALL subrepo:branch "$branch_name"
614
640
  cd "$worktree";
615
641
 
616
- if [[ "$join_method" == "rebase" ]]; then
642
+ if [[ $join_method == rebase ]]; then
617
643
  o "Rebase changes to $refs_subrepo_fetch"
618
644
  FAIL=false OUT=true RUN git rebase "$refs_subrepo_fetch" "$branch_name"
619
645
  if ! OK; then
@@ -637,9 +663,13 @@ subrepo:push() {
637
663
  error "No subrepo branch '$branch_name' to push."
638
664
 
639
665
  o "Check if we have something to push"
640
- new_upstream_head_commit="$(git rev-parse "$branch_name")"
666
+ new_upstream_head_commit=$(git rev-parse "$branch_name")
641
667
  if ! $new_upstream; then
642
- if [[ $upstream_head_commit == $new_upstream_head_commit ]]; then
668
+ if [[ $upstream_head_commit == "$new_upstream_head_commit" ]]; then
669
+ if $branch_created; then
670
+ o "Remove branch '$branch_name'."
671
+ git:delete-branch "$branch_name"
672
+ fi
643
673
  OK=false
644
674
  CODE=-2
645
675
  return
@@ -658,6 +688,7 @@ subrepo:push() {
658
688
  "$force_wanted" && force=' --force'
659
689
 
660
690
  o "Push$force branch '$branch_name' to '$subrepo_remote' ($subrepo_branch)."
691
+ # shellcheck disable=2086
661
692
  RUN git push$force "$subrepo_remote" "$branch_name":"$subrepo_branch"
662
693
 
663
694
  o "Create ref '$refs_subrepo_push' for branch '$branch_name'."
@@ -669,10 +700,22 @@ subrepo:push() {
669
700
  fi
670
701
 
671
702
  o "Put updates into '$subdir/.gitrepo' file."
672
- upstream_head_commit="$new_upstream_head_commit"
673
- subrepo_commit_ref="$upstream_head_commit"
703
+ upstream_head_commit=$new_upstream_head_commit
704
+ subrepo_commit_ref=$upstream_head_commit
674
705
  update-gitrepo-file
675
- RUN git commit -m "$(get-commit-message)"
706
+
707
+ local commit_message
708
+ if [[ $wanted_commit_message ]]; then
709
+ commit_message=$wanted_commit_message
710
+ else
711
+ commit_message=$(get-commit-message)
712
+ fi
713
+
714
+ if [[ $commit_msg_file ]]; then
715
+ RUN git command --file "$commit_msg_file"
716
+ else
717
+ RUN git commit -m "$commit_message"
718
+ fi
676
719
  }
677
720
 
678
721
  # Fetch the subrepo's remote branch content:
@@ -687,15 +730,16 @@ subrepo:fetch() {
687
730
 
688
731
  o "Get the upstream subrepo HEAD commit."
689
732
  OUT=true RUN git rev-parse FETCH_HEAD^0
690
- upstream_head_commit="$output"
733
+ upstream_head_commit=$output
691
734
 
692
735
  o "Create ref '$refs_subrepo_fetch'."
693
736
  git:make-ref "$refs_subrepo_fetch" FETCH_HEAD^0
694
737
  }
695
738
 
696
739
  # Create a subrepo branch containing all changes
740
+ # shellcheck disable=2120
697
741
  subrepo:branch() {
698
- local branch="${1:-"subrepo/$subref"}"
742
+ local branch=${1:-"subrepo/$subref"}
699
743
  o "Check if the '$branch' branch already exists."
700
744
  git:branch-exists "$branch" && return
701
745
 
@@ -703,39 +747,63 @@ subrepo:branch() {
703
747
  local first_gitrepo_commit=
704
748
 
705
749
  o "Subrepo parent: $subrepo_parent"
706
- if [[ -n "$subrepo_parent" ]]; then
750
+
751
+ if [[ $subrepo_parent ]]; then
752
+
753
+ # Check if the subrepo parent is an ancestor of HEAD.
754
+ # For example rebasing the commit that touched the subrepo
755
+ # could make the commit no longer match.
756
+ local parent_is_ancestor=
757
+ git merge-base --is-ancestor "$subrepo_parent" HEAD && parent_is_ancestor="true"
758
+ if [[ -z "$parent_is_ancestor" ]]; then
759
+ local prev_merge_point
760
+ prev_merge_point=$(git log -1 -G "commit =" --format="%H" "$gitrepo")
761
+ # We want the SHA of the patch before the sync point just in case someone made a modifcation in the
762
+ # actual sync commit
763
+ prev_merge_point=$(git log -1 --format="%H" "$prev_merge_point"^)
764
+ error "The last sync point (where upstream and the subrepo were equal) is not an ancestor. \n \
765
+ This is usually caused by a rebase affecting that commit. \n \
766
+ To recover set the subrepo parent in '$gitrepo'\n \
767
+ to '$prev_merge_point' \n \
768
+ and validate the subrepo by comparing with 'git subrepo branch $subdir'"
769
+ fi
770
+
707
771
  local prev_commit=
708
772
  local ancestor=
709
773
  o "Create new commits with parents into the subrepo fetch"
710
774
  OUT=true RUN git rev-list --reverse --ancestry-path --topo-order "$subrepo_parent..HEAD"
711
- local commit_list="$output"
775
+ local commit_list=$output
712
776
  for commit in $commit_list; do
713
777
  o "Working on $commit"
714
778
 
715
779
  FAIL=false OUT=true RUN git config --blob \
716
- "$commit":"$subdir/.gitrepo" "subrepo.commit"
717
- if [[ -z "$output" ]]; then
780
+ "$commit:$subdir/.gitrepo" "subrepo.commit"
781
+ if [[ -z $output ]]; then
718
782
  o "Ignore commit, no .gitrepo file"
719
783
  continue
720
784
  fi
721
785
 
722
- local gitrepo_commit="$output"
786
+ local gitrepo_commit=$output
723
787
  o ".gitrepo reference commit: $gitrepo_commit"
724
788
 
725
789
 
726
790
  # Only include the commit if it's a child of the previous commit
727
791
  # This way we create a single path between $subrepo_parent..HEAD
728
- if [[ -n "$ancestor" ]]; then
729
- local is_direct_child=$(git show -s --pretty=format:"%P" $commit | grep "$ancestor")
792
+ if [[ $ancestor ]]; then
793
+ local is_direct_child
794
+ is_direct_child=$(
795
+ git show -s --pretty=format:"%P" "$commit" |
796
+ grep "$ancestor"
797
+ ) || true
730
798
  o "is child: $is_direct_child"
731
- if [[ -z "$is_direct_child" ]]; then
799
+ if [[ -z $is_direct_child ]]; then
732
800
  o "Ignore $commit, it's not in the selected path"
733
801
  continue
734
802
  fi
735
803
  fi
736
804
 
737
805
  # Remember the previous commit from the parent repo path
738
- ancestor="$commit"
806
+ ancestor=$commit
739
807
 
740
808
  o "Check for rebase"
741
809
  if git:rev-exists "$refs_subrepo_fetch"; then
@@ -745,30 +813,33 @@ subrepo:branch() {
745
813
  fi
746
814
 
747
815
  o "Find parents"
748
- local first_parent=
749
- [[ -n $prev_commit ]] && first_parent="-p $prev_commit"
750
- local second_parent=
751
- if [[ -z "$first_gitrepo_commit" ]]; then
752
- first_gitrepo_commit="$gitrepo_commit"
753
- second_parent="-p $gitrepo_commit"
816
+ local first_parent second_parent
817
+ first_parent=()
818
+ [[ $prev_commit ]] && first_parent=(-p "$prev_commit")
819
+ second_parent=()
820
+ if [[ -z $first_gitrepo_commit ]]; then
821
+ first_gitrepo_commit=$gitrepo_commit
822
+ second_parent=(-p "$gitrepo_commit")
754
823
  fi
755
824
 
756
- if [[ "$join_method" != "rebase" ]]; then
825
+ if [[ $join_method != rebase ]]; then
757
826
  # In the rebase case we don't create merge commits
758
- if [[ "$gitrepo_commit" != "$last_gitrepo_commit" ]]; then
759
- second_parent="-p $gitrepo_commit"
760
- last_gitrepo_commit="$gitrepo_commit"
827
+ if [[ $gitrepo_commit != "$last_gitrepo_commit" ]]; then
828
+ second_parent=(-p "$gitrepo_commit")
829
+ last_gitrepo_commit=$gitrepo_commit
761
830
  fi
762
831
  fi
763
832
 
764
- o "Create a new commit $first_parent $second_parent"
833
+ o "Create a new commit ${first_parent[*]} ${second_parent[*]}"
765
834
  FAIL=false RUN git cat-file -e "$commit":"$subdir"
766
835
  if OK; then
767
836
  o "Create with content"
768
837
  local PREVIOUS_IFS=$IFS
769
838
  IFS=$'\n'
770
- local author_info=( $(git log -1 --date=default --format=%ad%n%ae%n%an "$commit") )
771
- local commiter_info=( $(git log -1 --date=default --format=%cd%n%ce%n%cn "$commit") )
839
+ local author_info
840
+ mapfile -t author_info < <(git log -1 --date=default --format=%ad%n%ae%n%an "$commit")
841
+ local commiter_info
842
+ mapfile -t commiter_info < <(git log -1 --date=default --format=%cd%n%ce%n%cn "$commit")
772
843
  IFS=$PREVIOUS_IFS
773
844
 
774
845
  # When we create new commits we leave the author information unchanged
@@ -777,17 +848,17 @@ subrepo:branch() {
777
848
  # to store both the original author but also the responsible committer
778
849
  # that created the local version of the commit and pushed it.
779
850
  prev_commit=$(git log -n 1 --date=default --format=%B "$commit" |
780
- GIT_AUTHOR_DATE="${author_info[0]}" \
781
- GIT_AUTHOR_EMAIL="${author_info[1]}" \
782
- GIT_AUTHOR_NAME="${author_info[2]}" \
851
+ GIT_AUTHOR_DATE=${author_info[0]} \
852
+ GIT_AUTHOR_EMAIL=${author_info[1]} \
853
+ GIT_AUTHOR_NAME=${author_info[2]} \
783
854
  GIT_COMMITTER_DATE="${commiter_info[0]}" \
784
855
  GIT_COMMITTER_EMAIL="${commiter_info[1]}" \
785
856
  GIT_COMMITTER_NAME="${commiter_info[2]}" \
786
- git commit-tree -F - $first_parent $second_parent "$commit":"$subdir")
857
+ git commit-tree -F - "${first_parent[@]}" "${second_parent[@]}" "$commit":"$subdir")
787
858
  else
788
859
  o "Create empty placeholder"
789
860
  prev_commit=$(git commit-tree -m "EMPTY" \
790
- $first_parent $second_parent "4b825dc642cb6eb9a060e54bf8d69288fbee4904")
861
+ "${first_parent[*]}" "${second_parent[*]}" "4b825dc642cb6eb9a060e54bf8d69288fbee4904")
791
862
  fi
792
863
  done
793
864
 
@@ -801,8 +872,8 @@ subrepo:branch() {
801
872
  fi
802
873
 
803
874
  o "Remove the .gitrepo file from $first_gitrepo_commit..$branch"
804
- local filter="$branch"
805
- [[ -n "$first_gitrepo_commit" ]] && filter="$first_gitrepo_commit..$branch"
875
+ local filter=$branch
876
+ [[ $first_gitrepo_commit ]] && filter=$first_gitrepo_commit..$branch
806
877
  FAIL=false RUN git filter-branch -f --prune-empty --tree-filter \
807
878
  "rm -f .gitrepo" "$filter"
808
879
 
@@ -819,7 +890,7 @@ subrepo:commit() {
819
890
  error "Commit ref '$subrepo_commit_ref' does not exist."
820
891
 
821
892
  if ! "$force_wanted"; then
822
- local upstream="$upstream_head_commit"
893
+ local upstream=$upstream_head_commit
823
894
  o "Make sure '$subrepo_commit_ref' contains the upstream HEAD."
824
895
  if ! git:commit-in-rev-list "$upstream" "$subrepo_commit_ref"; then
825
896
  error \
@@ -840,29 +911,37 @@ subrepo:commit() {
840
911
  RUN git add -f -- "$gitrepo"
841
912
 
842
913
  local commit_message
843
- if [[ -n "$wanted_commit_message" ]]; then
844
- commit_message="$wanted_commit_message"
914
+ if [[ $wanted_commit_message ]]; then
915
+ commit_message=$wanted_commit_message
845
916
  else
846
- commit_message="$(get-commit-message)"
917
+ commit_message=$(get-commit-message)
847
918
  fi
848
919
 
849
920
  local edit_flag=
850
921
  $edit_wanted && edit_flag=--edit
851
922
 
852
- [[ -n $commit_message ]] || commit_message="$(get-commit-message)"
923
+ [[ $commit_message ]] || commit_message=$(get-commit-message)
853
924
 
854
925
  local edit_flag=
855
926
  $edit_wanted && edit_flag=--edit
856
927
 
857
928
  o "Commit to the '$original_head_branch' branch."
858
929
  if [[ $original_head_commit != none ]]; then
859
- RUN git commit $edit_flag -m "$commit_message"
930
+ if [[ $commit_msg_file ]]; then
931
+ RUN git commit $edit_flag --file "$commit_msg_file"
932
+ else
933
+ RUN git commit $edit_flag -m "$commit_message"
934
+ fi
860
935
  else
861
936
  # We had cloned into an empty repo, side effect of prior git reset --mixed
862
937
  # command is that subrepo's history is now part of the index. Commit
863
938
  # without that history.
864
939
  OUT=true RUN git write-tree
865
- OUT=true RUN git commit-tree $edit_flag -m "$commit_message" "$output"
940
+ if [[ $commit_msg_file ]]; then
941
+ OUT=true RUN git commit-tree $edit_flag --file "$commit_msg_file" "$output"
942
+ else
943
+ OUT=true RUN git commit-tree $edit_flag -m "$commit_message" "$output"
944
+ fi
866
945
  RUN git reset --hard "$output"
867
946
  fi
868
947
 
@@ -901,10 +980,10 @@ subrepo:status() {
901
980
  continue
902
981
  fi
903
982
 
904
- refs_subrepo_fetch="refs/subrepo/$subref/fetch"
905
- upstream_head_commit="$(
983
+ refs_subrepo_fetch=refs/subrepo/$subref/fetch
984
+ upstream_head_commit=$(
906
985
  git rev-parse --short "$refs_subrepo_fetch" 2> /dev/null || true
907
- )"
986
+ )
908
987
  subrepo_remote=
909
988
  subrepo_branch=
910
989
 
@@ -921,27 +1000,31 @@ subrepo:status() {
921
1000
  echo "Git subrepo '$subdir':"
922
1001
  git:branch-exists "subrepo/$subref" &&
923
1002
  echo " Subrepo Branch: subrepo/$subref"
924
- local remote="subrepo/$subref"
1003
+ local remote=subrepo/$subref
925
1004
  FAIL=false OUT=true RUN git config "remote.$remote.url"
926
- [[ -n $output ]] &&
1005
+ [[ $output ]] &&
927
1006
  echo " Remote Name: subrepo/$subref"
928
1007
  echo " Remote URL: $subrepo_remote"
929
- [[ -n $upstream_head_commit ]] &&
1008
+ [[ $upstream_head_commit ]] &&
930
1009
  echo " Upstream Ref: $upstream_head_commit"
931
1010
  echo " Tracking Branch: $subrepo_branch"
932
1011
  [[ -z $subrepo_commit ]] ||
933
- echo " Pulled Commit: $(git rev-parse --short $subrepo_commit)"
934
- if [[ -n $subrepo_parent ]]; then
935
- echo " Pull Parent: $(git rev-parse --short $subrepo_parent)"
1012
+ echo " Pulled Commit: $(git rev-parse --short "$subrepo_commit")"
1013
+ if [[ $subrepo_parent ]]; then
1014
+ echo " Pull Parent: $(git rev-parse --short "$subrepo_parent")"
936
1015
  # TODO Remove this eventually:
937
- elif [[ -n $subrepo_former ]]; then
938
- printf " Former Commit: $(git rev-parse --short $subrepo_former)"
1016
+ elif [[ $subrepo_former ]]; then
1017
+ printf " Former Commit: %s" "$(git rev-parse --short "$subrepo_former")"
939
1018
  echo " *** DEPRECATED ***"
940
1019
  fi
941
1020
 
942
1021
  # Grep for directory, branch can be in detached state due to conflicts
943
- local _worktree=$(git worktree list | grep "$GIT_TMP/subrepo/$subdir")
944
- if [[ -n $_worktree ]]; then
1022
+ local _worktree
1023
+ _worktree=$(
1024
+ git worktree list |
1025
+ grep "$GIT_TMP/subrepo/$subdir "
1026
+ ) || true
1027
+ if [[ $_worktree ]]; then
945
1028
  echo " Worktree: $_worktree"
946
1029
  fi
947
1030
 
@@ -955,9 +1038,9 @@ subrepo:status() {
955
1038
 
956
1039
  subrepo:clean() {
957
1040
  # Remove subrepo branches if exist:
958
- local branch="subrepo/$subref"
959
- local ref="refs/heads/$branch"
960
- local worktree="$GIT_TMP/$branch"
1041
+ local branch=subrepo/$subref
1042
+ local ref=refs/heads/$branch
1043
+ local worktree=$GIT_TMP/$branch
961
1044
 
962
1045
  o "Clean $subdir"
963
1046
  git:remove-worktree
@@ -969,12 +1052,17 @@ subrepo:clean() {
969
1052
 
970
1053
  if "$force_wanted"; then
971
1054
  o "Remove all subrepo refs."
972
- local suffix=""
1055
+ local suffix=''
973
1056
  if ! $all_wanted; then
974
- suffix="$subref/"
1057
+ suffix=$subref/
975
1058
  fi
976
- git show-ref | while read hash ref; do
977
- if [[ "$ref" == refs/subrepo/$suffix* ]]; then
1059
+ git show-ref | while read -r hash ref; do
1060
+ if [[ $ref == "refs/subrepo/$suffix"* ]]; then
1061
+ git update-ref -d "$ref"
1062
+ fi
1063
+ done
1064
+ git show-ref | while read -r hash ref; do
1065
+ if [[ $ref == "refs/original/refs/heads/subrepo/$suffix"* ]]; then
978
1066
  git update-ref -d "$ref"
979
1067
  fi
980
1068
  done
@@ -994,9 +1082,9 @@ subrepo:clean() {
994
1082
  get-command-options() {
995
1083
  [[ $# -eq 0 ]] && set -- --help
996
1084
 
997
- [[ -n $GIT_SUBREPO_QUIET ]] && quiet_wanted=true
998
- [[ -n $GIT_SUBREPO_VERBOSE ]] && verbose_wanted=true
999
- [[ -n $GIT_SUBREPO_DEBUG ]] && debug_wanted=true
1085
+ [[ ${GIT_SUBREPO_QUIET-} ]] && quiet_wanted=true
1086
+ [[ ${GIT_SUBREPO_VERBOSE-} ]] && verbose_wanted=true
1087
+ [[ ${GIT_SUBREPO_DEBUG-} ]] && debug_wanted=true
1000
1088
 
1001
1089
  eval "$(
1002
1090
  echo "$GETOPT_SPEC" |
@@ -1005,28 +1093,30 @@ get-command-options() {
1005
1093
  )"
1006
1094
 
1007
1095
  while [[ $# -gt 0 ]]; do
1008
- local option="$1"; shift
1096
+ local option=$1; shift
1009
1097
  case "$option" in
1010
1098
  --) break ;;
1011
1099
  -a) all_wanted=true ;;
1012
1100
  -A) ALL_wanted=true
1013
1101
  all_wanted=true ;;
1014
- -b) subrepo_branch="$1"
1015
- override_branch="$1"
1102
+ -b) subrepo_branch=$1
1103
+ override_branch=$1
1016
1104
  commit_msg_args+=("--branch=$1")
1017
1105
  shift ;;
1018
1106
  -e) edit_wanted=true ;;
1019
1107
  -f) force_wanted=true
1020
1108
  commit_msg_args+=("--force") ;;
1021
1109
  -F) fetch_wanted=true ;;
1022
- -m) wanted_commit_message="$1"
1023
- shift;;
1024
- -M) join_method="$1"
1110
+ -m)
1111
+ if [[ $commit_msg_file ]]; then
1112
+ error "fatal: options '-m' and '--file' cannot be used together"
1113
+ fi
1114
+ wanted_commit_message=$1
1025
1115
  shift;;
1026
- -M) join_method="$1"
1116
+ -M) join_method=$1
1027
1117
  shift;;
1028
- -r) subrepo_remote="$1"
1029
- override_remote="$1"
1118
+ -r) subrepo_remote=$1
1119
+ override_remote=$1
1030
1120
  commit_msg_args+=("--remote=$1")
1031
1121
  shift ;;
1032
1122
  -s) squash_wanted=true ;;
@@ -1036,6 +1126,16 @@ get-command-options() {
1036
1126
  -v) verbose_wanted=true ;;
1037
1127
  -d) debug_wanted=true ;;
1038
1128
  -x) set -x ;;
1129
+ --file)
1130
+ if [[ $wanted_commit_message ]]; then
1131
+ error "fatal: options '-m' and '--file' cannot be used together"
1132
+ fi
1133
+ if [ -f "$1" ]; then
1134
+ commit_msg_file="$1"
1135
+ else
1136
+ error "Commit msg file at $1 not found"
1137
+ fi
1138
+ shift ;;
1039
1139
  --version)
1040
1140
  echo "$VERSION"
1041
1141
  exit ;;
@@ -1044,34 +1144,34 @@ get-command-options() {
1044
1144
  done
1045
1145
 
1046
1146
  # Set subrepo command:
1047
- command="$1"; shift
1147
+ command=$1; shift
1048
1148
 
1049
1149
  # Make sure command exists:
1050
1150
  can "command:$command" ||
1051
1151
  usage-error "'$command' is not a command. See 'git subrepo help'."
1052
1152
 
1053
1153
  command_arguments=("$@")
1054
- if [[ ${#command_arguments} -gt 0 ]]; then
1055
- local first="${command_arguments[0]}"
1056
- first="${first%/}"
1057
- command_arguments[0]="$first"
1154
+ if [[ ${command_arguments[*]-} && ${#command_arguments[@]} -gt 0 ]]; then
1155
+ local first=${command_arguments[0]}
1156
+ first=${first%/}
1157
+ command_arguments[0]=$first
1058
1158
  fi
1059
1159
  commit_msg_args+=("${command_arguments[@]}")
1060
1160
 
1061
1161
  for option in all ALL edit fetch force squash; do
1062
- var="${option}_wanted"
1162
+ var=${option}_wanted
1063
1163
  if ${!var}; then
1064
1164
  check_option $option
1065
1165
  fi
1066
1166
  done
1067
1167
 
1068
- if [[ -n $override_branch ]]; then
1168
+ if [[ $override_branch ]]; then
1069
1169
  check_option branch
1070
1170
  fi
1071
- if [[ -n $override_remote ]]; then
1171
+ if [[ $override_remote ]]; then
1072
1172
  check_option remote
1073
1173
  fi
1074
- if [[ -n $wanted_commit_message ]]; then
1174
+ if [[ $wanted_commit_message || $commit_msg_file ]]; then
1075
1175
  check_option message
1076
1176
  fi
1077
1177
  if $update_wanted; then
@@ -1088,13 +1188,13 @@ options_clean='ALL all force'
1088
1188
  options_clone='branch edit force message method'
1089
1189
  options_config='force'
1090
1190
  options_commit='edit fetch force message'
1091
- options_fetch='all branch remote'
1191
+ options_fetch='all branch force remote'
1092
1192
  options_init='branch remote method'
1093
1193
  options_pull='all branch edit force message remote update'
1094
- options_push='all branch force remote squash update'
1194
+ options_push='all branch force message remote squash update'
1095
1195
  options_status='ALL all fetch'
1096
1196
  check_option() {
1097
- local var="options_${command//-/_}"
1197
+ local var=options_${command//-/_}
1098
1198
  [[ ${!var} =~ $1 ]] ||
1099
1199
  usage-error "Invalid option '--$1' for '$command'."
1100
1200
  }
@@ -1107,8 +1207,8 @@ command-init() {
1107
1207
  # Export variable to let other processes (possibly git hooks) know that they
1108
1208
  # are running under git-subrepo. Set to current process pid, so it can be
1109
1209
  # further verified if need be:
1110
- export GIT_SUBREPO_RUNNING="$$"
1111
- export GIT_SUBREPO_COMMAND="$command"
1210
+ export GIT_SUBREPO_RUNNING=$$
1211
+ export GIT_SUBREPO_COMMAND=$command
1112
1212
 
1113
1213
  : "${GIT_SUBREPO_PAGER:=${PAGER:-less}}"
1114
1214
  if [[ $GIT_SUBREPO_PAGER == less ]]; then
@@ -1121,7 +1221,7 @@ command-prepare() {
1121
1221
  if git:rev-exists HEAD; then
1122
1222
  git:get-head-branch-commit
1123
1223
  fi
1124
- original_head_commit="${output:-none}"
1224
+ original_head_commit=${output:-none}
1125
1225
  }
1126
1226
 
1127
1227
  # Do the setup steps needed by most of the subrepo subcommands:
@@ -1130,14 +1230,19 @@ command-setup() {
1130
1230
 
1131
1231
  check-and-normalize-subdir
1132
1232
  encode-subdir
1133
- gitrepo="$subdir/.gitrepo"
1233
+ gitrepo=$subdir/.gitrepo
1134
1234
 
1135
1235
  if ! $force_wanted; then
1136
1236
  o "Check for worktree with branch subrepo/$subdir"
1137
- local _worktree=$(git worktree list | grep "\[subrepo/$subdir\]" | cut -d ' ' -f1)
1237
+ local _worktree
1238
+ _worktree=$(
1239
+ git worktree list |
1240
+ grep "\[subrepo/$subdir\]" |
1241
+ cut -d ' ' -f1
1242
+ ) || true
1138
1243
  if [[ $command =~ ^(commit)$ && -z $_worktree ]]; then
1139
1244
  error "There is no worktree available, use the branch command first"
1140
- elif [[ ! $command =~ ^(branch|clean|commit|push)$ && -n $_worktree ]]; then
1245
+ elif [[ ! $command =~ ^(branch|clean|commit|push)$ && $_worktree ]]; then
1141
1246
  if [[ -e $gitrepo ]]; then
1142
1247
  error "There is already a worktree with branch subrepo/$subdir.
1143
1248
  Use the --force flag to override this check or perform a subrepo clean
@@ -1153,10 +1258,10 @@ Use the --force flag to override this check or remove the worktree with
1153
1258
  fi
1154
1259
 
1155
1260
  # Set refs_ variables:
1156
- refs_subrepo_branch="refs/subrepo/$subref/branch"
1157
- refs_subrepo_commit="refs/subrepo/$subref/commit"
1158
- refs_subrepo_fetch="refs/subrepo/$subref/fetch"
1159
- refs_subrepo_push="refs/subrepo/$subref/push"
1261
+ refs_subrepo_branch=refs/subrepo/$subref/branch
1262
+ refs_subrepo_commit=refs/subrepo/$subref/commit
1263
+ refs_subrepo_fetch=refs/subrepo/$subref/fetch
1264
+ refs_subrepo_push=refs/subrepo/$subref/push
1160
1265
 
1161
1266
  # Read/parse the .gitrepo file (unless clone/init; doesn't exist yet)
1162
1267
  if [[ ! $command =~ ^(clone|init)$ ]]; then
@@ -1167,33 +1272,34 @@ Use the --force flag to override this check or remove the worktree with
1167
1272
  }
1168
1273
 
1169
1274
  # Parse command line args according to a simple dsl spec:
1275
+ # shellcheck disable=2059
1170
1276
  get-params() {
1171
1277
  local i=0
1172
1278
  local num=${#command_arguments[@]}
1173
- for arg in $@; do
1174
- local value="${command_arguments[i]}"
1175
- value="${value//%/%%}"
1176
- value="${value//\\/\\\\}"
1279
+ for arg in "$@"; do
1280
+ local value=${command_arguments[i]-}
1281
+ value=${value//%/%%}
1282
+ value=${value//\\/\\\\}
1177
1283
  # If arg starts with '+' then it is required
1178
1284
  if [[ $arg == +* ]]; then
1179
1285
  if [[ $i -ge $num ]]; then
1180
1286
  usage-error "Command '$command' requires arg '${arg#+}'."
1181
1287
  fi
1182
- printf -v ${arg#+} -- "$value"
1288
+ printf -v "${arg#+}" -- "$value"
1183
1289
  # Look for function name after ':' to provide a default value
1184
1290
  else
1185
1291
  if [[ $i -lt $num ]]; then
1186
- printf -v ${arg%:*} -- "$value"
1292
+ printf -v "${arg%:*}" -- "$value"
1187
1293
  elif [[ $arg =~ : ]]; then
1188
1294
  "${arg#*:}"
1189
1295
  fi
1190
1296
  fi
1191
- let i=$((i+1))
1297
+ : $((i++))
1192
1298
  done
1193
1299
 
1194
1300
  # Check for extra arguments:
1195
1301
  if [[ $num -gt $i ]]; then
1196
- set -- ${command_arguments[@]}
1302
+ set -- "${command_arguments[@]}"
1197
1303
  for ((j = 1; j <= i; j++)); do shift; done
1198
1304
  error "Unknown argument(s) '$*' for '$command' command."
1199
1305
  fi
@@ -1201,24 +1307,24 @@ get-params() {
1201
1307
 
1202
1308
  check-and-normalize-subdir() {
1203
1309
  # Sanity check subdir:
1204
- [[ -n $subdir ]] ||
1310
+ [[ $subdir ]] ||
1205
1311
  die "subdir not set"
1206
1312
  [[ $subdir =~ ^/ || $subdir =~ ^[A-Z]: ]] &&
1207
1313
  usage-error "The subdir '$subdir' should not be absolute path."
1208
- subdir="${subdir#./}"
1209
- subdir="${subdir%/}"
1314
+ subdir=${subdir#./}
1315
+ subdir=${subdir%/}
1210
1316
  [[ $subdir != *//* ]] || subdir=$(tr -s / <<< "$subdir")
1211
1317
  }
1212
1318
 
1213
1319
  # Determine the correct subdir path to use:
1214
1320
  guess-subdir() {
1215
- local dir="$subrepo_remote"
1216
- dir="${dir%.git}"
1217
- dir="${dir%/}"
1218
- dir="${dir##*/}"
1321
+ local dir=$subrepo_remote
1322
+ dir=${dir%.git}
1323
+ dir=${dir%/}
1324
+ dir=${dir##*/}
1219
1325
  [[ $dir =~ ^[-_a-zA-Z0-9]+$ ]] ||
1220
1326
  error "Can't determine subdir from '$subrepo_remote'."
1221
- subdir="$dir"
1327
+ subdir=$dir
1222
1328
  check-and-normalize-subdir
1223
1329
  encode-subdir
1224
1330
  }
@@ -1265,7 +1371,8 @@ encode-subdir() {
1265
1371
  local i
1266
1372
  for (( i = 1; i < 32; ++i )); do
1267
1373
  # skip substitute NUL char (i=0), as bash will skip NUL in env
1268
- local x=$(printf "%02x" $i)
1374
+ local x
1375
+ x=$(printf "%02x" "$i")
1269
1376
  subref=${subref//$(printf "%b" "\x$x")/%$x}
1270
1377
  done
1271
1378
  subref=${subref//$'\177'/%7f}
@@ -1309,7 +1416,7 @@ encode-subdir() {
1309
1416
 
1310
1417
  # Set subdir and gitrepo vars:
1311
1418
  read-gitrepo-file() {
1312
- gitrepo="$subdir/.gitrepo"
1419
+ gitrepo=$subdir/.gitrepo
1313
1420
 
1314
1421
  if [[ ! -f $gitrepo ]]; then
1315
1422
  error "No '$gitrepo' file."
@@ -1318,34 +1425,34 @@ read-gitrepo-file() {
1318
1425
  # Read .gitrepo values:
1319
1426
  if [[ -z $subrepo_remote ]]; then
1320
1427
  SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.remote
1321
- subrepo_remote="$output"
1428
+ subrepo_remote=$output
1322
1429
  fi
1323
1430
 
1324
1431
  if [[ -z $subrepo_branch ]]; then
1325
1432
  SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.branch
1326
- subrepo_branch="$output"
1433
+ subrepo_branch=$output
1327
1434
  fi
1328
1435
 
1329
1436
  SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.commit
1330
- subrepo_commit="$output"
1437
+ subrepo_commit=$output
1331
1438
 
1332
1439
  FAIL=false \
1333
1440
  SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.parent
1334
- subrepo_parent="$output"
1441
+ subrepo_parent=$output
1335
1442
 
1336
1443
  FAIL=false \
1337
1444
  SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.method
1338
- if [[ $output == "rebase" ]]; then
1339
- join_method="rebase"
1445
+ if [[ $output == rebase ]]; then
1446
+ join_method=rebase
1340
1447
  else
1341
1448
  # This is the default method
1342
- join_method="merge"
1449
+ join_method=merge
1343
1450
  fi
1344
1451
 
1345
1452
  if [[ -z $subrepo_parent ]]; then
1346
1453
  FAIL=false \
1347
1454
  SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.former
1348
- subrepo_former="$output"
1455
+ subrepo_former=$output
1349
1456
  fi
1350
1457
  }
1351
1458
 
@@ -1368,7 +1475,7 @@ update-gitrepo-file() {
1368
1475
  ; DO NOT EDIT (unless you know what you are doing)
1369
1476
  ;
1370
1477
  ; This subdirectory is a git "subrepo", and this file is maintained by the
1371
- ; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
1478
+ ; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme
1372
1479
  ;
1373
1480
  ...
1374
1481
  fi
@@ -1376,25 +1483,25 @@ update-gitrepo-file() {
1376
1483
 
1377
1484
 
1378
1485
  # TODO: only update remote and branch if supplied and $update_wanted
1379
- if $newfile || [[ $update_wanted && -n $override_remote ]]; then
1486
+ if $newfile || [[ $update_wanted && $override_remote ]]; then
1380
1487
  RUN git config --file="$gitrepo" subrepo.remote "$subrepo_remote"
1381
1488
  fi
1382
1489
 
1383
- if $newfile || [[ $update_wanted && -n $override_branch ]]; then
1490
+ if $newfile || [[ $update_wanted && $override_branch ]]; then
1384
1491
  RUN git config --file="$gitrepo" subrepo.branch "$subrepo_branch"
1385
1492
  fi
1386
1493
 
1387
1494
  RUN git config --file="$gitrepo" subrepo.commit "$upstream_head_commit"
1388
1495
  # Only write new parent when we are at the head of upstream
1389
- if [[ -n $upstream_head_commit && -n $subrepo_commit_ref ]]; then
1496
+ if [[ $upstream_head_commit && $subrepo_commit_ref ]]; then
1390
1497
  OUT=true RUN git rev-parse "$subrepo_commit_ref"
1391
1498
  o "$upstream_head_commit == $output"
1392
- if [[ $upstream_head_commit == $output ]]; then
1499
+ if [[ $upstream_head_commit == "$output" ]]; then
1393
1500
  RUN git config --file="$gitrepo" subrepo.parent "$original_head_commit"
1394
1501
  fi
1395
1502
  fi
1396
1503
 
1397
- [[ -z $join_method ]] && join_method="merge"
1504
+ [[ -z $join_method ]] && join_method=merge
1398
1505
  RUN git config --file="$gitrepo" subrepo.method "$join_method"
1399
1506
 
1400
1507
  RUN git config --file="$gitrepo" subrepo.cmdver "$VERSION"
@@ -1413,16 +1520,20 @@ assert-environment-ok() {
1413
1520
 
1414
1521
  git_version=$(git --version | cut -d ' ' -f3)
1415
1522
 
1416
- if [[ $(
1417
- printf "$REQUIRED_GIT_VERSION\n$git_version" |
1418
- sort -t. -k 1,1n -k 2,2n -k 3,3n |
1419
- head -n1
1420
- ) == "$git_version" &&
1421
- $git_version != "$REQUIRED_GIT_VERSION"
1422
- ]]; then
1523
+ version-check bash "$REQUIRED_BASH_VERSION" || {
1524
+ echo "The 'bashplus' library requires that 'Bash ${REQUIRED_BASH_VERSION}+' is installed." >&2
1525
+ echo "It doesn't need to be your shell, but it must be in your PATH." >&2
1526
+ if [[ ${OSTYPE-} == darwin* ]]; then
1527
+ echo "You appear to be on macOS." >&2
1528
+ echo "Try: 'brew install bash'." >&2
1529
+ echo "This will not change your user shell, it just installs 'Bash 5.x'." >&2
1530
+ fi
1531
+ exit 1
1532
+ }
1533
+
1534
+ version-check git "$REQUIRED_GIT_VERSION" ||
1423
1535
  error "Requires git version $REQUIRED_GIT_VERSION or higher; "`
1424
1536
  `"you have '$git_version'."
1425
- fi
1426
1537
 
1427
1538
  if [[ ${BASH_VERSINFO[0]} -lt 4 ]] ; then
1428
1539
  echo "The git-subrepo command requires that 'Bash 4+' is installed."
@@ -1447,7 +1558,7 @@ assert-repo-is-ready() {
1447
1558
 
1448
1559
  # Get the original branch and commit:
1449
1560
  git:get-head-branch-name
1450
- original_head_branch="$output"
1561
+ original_head_branch=$output
1451
1562
 
1452
1563
  # If a subrepo branch is currently checked out, then note it:
1453
1564
  if [[ $original_head_branch =~ ^subrepo/(.*) ]]; then
@@ -1470,7 +1581,7 @@ assert-repo-is-ready() {
1470
1581
  assert-working-copy-is-clean
1471
1582
 
1472
1583
  # For now, only support actions from top of repo:
1473
- if [[ -n "$(git rev-parse --show-prefix)" ]]; then
1584
+ if [[ $(git rev-parse --show-prefix) ]]; then
1474
1585
  error "Need to run subrepo command from top level directory of the repo."
1475
1586
  fi
1476
1587
  }
@@ -1479,7 +1590,8 @@ assert-working-copy-is-clean() {
1479
1590
  # Repo is in a clean state:
1480
1591
  if [[ $command =~ ^(clone|init|pull|push|branch|commit)$ ]]; then
1481
1592
  # TODO: Should we check for untracked files?
1482
- local pwd=$(pwd)
1593
+ local pwd
1594
+ pwd=$(pwd)
1483
1595
  o "Assert that working copy is clean: $pwd"
1484
1596
  git update-index -q --ignore-submodules --refresh
1485
1597
  git diff-files --quiet --ignore-submodules ||
@@ -1507,14 +1619,14 @@ assert-subdir-ready-for-init() {
1507
1619
  error "The subdir '$subdir' is already a subrepo."
1508
1620
  fi
1509
1621
  # Check that subdir is part of the repo
1510
- if [[ -z $(git log -1 --date=default -- $subdir) ]]; then
1622
+ if [[ -z $(git log -1 --date=default -- "$subdir") ]]; then
1511
1623
  error "The subdir '$subdir' is not part of this repo."
1512
1624
  fi
1513
1625
  }
1514
1626
 
1515
1627
  # If subdir exists, make sure it is empty:
1516
1628
  assert-subdir-empty() {
1517
- if [[ -e $subdir ]] && [[ -n $(ls -A $subdir) ]]; then
1629
+ if [[ -e $subdir ]] && [[ $(ls -A "$subdir") ]]; then
1518
1630
  error "The subdir '$subdir' exists and is not empty."
1519
1631
  fi
1520
1632
  }
@@ -1526,7 +1638,8 @@ assert-subdir-empty() {
1526
1638
  # Find all the current subrepos by looking for all the subdirectories that
1527
1639
  # contain a `.gitrepo` file.
1528
1640
  get-all-subrepos() {
1529
- local paths=($(git ls-files | sed -n 's!/\.gitrepo$!!p' | sort))
1641
+ local paths
1642
+ mapfile -t paths < <(git ls-files | sed -n 's!/\.gitrepo$!!p' | sort)
1530
1643
  subrepos=()
1531
1644
  local path
1532
1645
  for path in "${paths[@]}"; do
@@ -1545,31 +1658,28 @@ add-subrepo() {
1545
1658
 
1546
1659
  # Determine the upstream's default head branch:
1547
1660
  get-upstream-head-branch() {
1548
- OUT=true RUN git ls-remote $subrepo_remote
1549
- local remotes="$output"
1550
- [[ -n $remotes ]] ||
1551
- error "Failed to 'git ls-remote $subrepo_remote'."
1552
- local commit="$(
1553
- echo "$remotes" |
1554
- grep HEAD |
1555
- cut -f1
1556
- )"
1557
- local branch="$(
1661
+ local remotes branch
1662
+ OUT=true RUN git ls-remote --symref "$subrepo_remote"
1663
+ remotes=$output
1664
+ [[ $remotes ]] ||
1665
+ error "Failed to 'git ls-remote --symref $subrepo_remote'."
1666
+
1667
+ # 'ref: refs/heads/master HEAD'
1668
+ branch=$(
1558
1669
  echo "$remotes" |
1559
- grep -E "$commit[[:space:]]+refs/heads/" |
1560
- grep -v HEAD |
1561
- head -n1 |
1562
- cut -f2
1563
- )"
1670
+ grep "^ref:" | grep 'HEAD$' | cut -f2 -d':' | cut -f1 |
1671
+ head -n1
1672
+ )
1673
+ branch=${branch/ }
1564
1674
  [[ $branch =~ refs/heads/ ]] ||
1565
1675
  error "Problem finding remote default head branch."
1566
- output="${branch#refs/heads/}"
1676
+ output=${branch#refs/heads/}
1567
1677
  }
1568
1678
 
1569
1679
  # Commit msg for an action commit:
1570
1680
  # Don't use RUN here as it will pollute commit message
1571
1681
  get-commit-message() {
1572
- local commit="none"
1682
+ local commit=none
1573
1683
  if git:rev-exists "$upstream_head_commit"; then
1574
1684
  commit=$(git rev-parse --short "$upstream_head_commit")
1575
1685
  fi
@@ -1578,19 +1688,19 @@ get-commit-message() {
1578
1688
  if $all_wanted; then
1579
1689
  args+=("$subdir")
1580
1690
  fi
1581
- args+=(${commit_msg_args[@]})
1691
+ args+=("${commit_msg_args[@]}")
1582
1692
 
1583
1693
  # Find the specific git-subrepo code used:
1584
1694
  local command_remote='???'
1585
1695
  local command_commit='???'
1586
1696
  get-command-info
1587
1697
 
1588
- local merged="none"
1698
+ local merged=none
1589
1699
  if git:rev-exists "$subrepo_commit_ref"; then
1590
1700
  merged=$(git rev-parse --short "$subrepo_commit_ref")
1591
1701
  fi
1592
1702
 
1593
- local is_merge=""
1703
+ local is_merge=''
1594
1704
  if [[ $command != push ]]; then
1595
1705
  if git:is_merge_commit "$subrepo_commit_ref"; then
1596
1706
  is_merge=" (merge)"
@@ -1601,7 +1711,7 @@ get-commit-message() {
1601
1711
 
1602
1712
  # Format subrepo commit message:
1603
1713
  cat <<...
1604
- git subrepo $command$is_merge ${args[@]}
1714
+ git subrepo $command$is_merge ${args[*]}
1605
1715
 
1606
1716
  subrepo:
1607
1717
  subdir: "$subdir"
@@ -1621,9 +1731,10 @@ git-subrepo:
1621
1731
  # info goes into commit messages, so we can find out exactly how the commits
1622
1732
  # were done.
1623
1733
  get-command-info() {
1624
- local bin="$0"
1734
+ local bin=$0
1625
1735
  if [[ $bin =~ / ]]; then
1626
- local lib="$(dirname "$bin")"
1736
+ local lib
1737
+ lib=$(dirname "$bin")
1627
1738
  # XXX Makefile needs to install these symlinks:
1628
1739
  # If `git-subrepo` was system-installed (`make install`):
1629
1740
  if [[ -e $lib/git-subrepo.d/upstream ]] &&
@@ -1631,31 +1742,34 @@ get-command-info() {
1631
1742
  command_remote=$(readlink "$lib/git-subrepo.d/upstream")
1632
1743
  command_commit=$(readlink "$lib/git-subrepo.d/commit")
1633
1744
  elif [[ $lib =~ / ]]; then
1634
- lib="$(dirname "$lib")"
1745
+ lib=$(dirname "$lib")
1635
1746
  if [[ -d $lib/.git ]]; then
1636
- local remote="$(
1747
+ local remote
1748
+ remote=$(
1637
1749
  GIT_DIR=$lib/.git git remote -v |
1638
1750
  grep '^origin' |
1639
1751
  head -n1 |
1640
1752
  cut -f2 |
1641
1753
  cut -d ' ' -f1
1642
- )"
1643
- if [[ -n $remote ]]; then
1644
- command_remote="$remote"
1754
+ )
1755
+ if [[ $remote ]]; then
1756
+ command_remote=$remote
1645
1757
  else
1646
- local remote="$(
1758
+ local remote
1759
+ remote=$(
1647
1760
  GIT_DIR=$lib/.git git remote -v |
1648
1761
  head -n1 |
1649
1762
  cut -f2 |
1650
1763
  cut -d ' ' -f1
1651
- )"
1652
- if [[ -n $remote ]]; then
1653
- command_remote="$remote"
1764
+ )
1765
+ if [[ $remote ]]; then
1766
+ command_remote=$remote
1654
1767
  fi
1655
1768
  fi
1656
- local commit="$(GIT_DIR="$lib/.git" git rev-parse --short HEAD)"
1657
- if [[ -n $commit ]]; then
1658
- command_commit="$commit"
1769
+ local commit
1770
+ commit=$(GIT_DIR=$lib/.git git rev-parse --short HEAD)
1771
+ if [[ $commit ]]; then
1772
+ command_commit=$commit
1659
1773
  fi
1660
1774
  fi
1661
1775
  fi
@@ -1680,7 +1794,7 @@ This is the common conflict resolution workflow:
1680
1794
  3. "git add" the resolved files.
1681
1795
  ...
1682
1796
 
1683
- if [[ "$join_method" == "rebase" ]]; then
1797
+ if [[ $join_method == rebase ]]; then
1684
1798
  cat <<...
1685
1799
  4. git rebase --continue
1686
1800
  ...
@@ -1694,8 +1808,8 @@ This is the common conflict resolution workflow:
1694
1808
  5. If there are more conflicts, restart at step 2.
1695
1809
  6. cd $start_pwd
1696
1810
  ...
1697
- local branch_name="${branch:=subrepo/$subdir}"
1698
- if [[ "$command" == "push" ]]; then
1811
+ local branch_name=${branch:=subrepo/$subdir}
1812
+ if [[ $command == push ]]; then
1699
1813
  cat <<...
1700
1814
  7. git subrepo push $subdir $branch_name
1701
1815
  ...
@@ -1705,7 +1819,7 @@ This is the common conflict resolution workflow:
1705
1819
  ...
1706
1820
  fi
1707
1821
 
1708
- if [[ "$command" == "pull" && "$join_method" == "rebase" ]]; then
1822
+ if [[ $command == pull && $join_method == rebase ]]; then
1709
1823
  cat <<...
1710
1824
 
1711
1825
  After you have performed the steps above you can push your local changes
@@ -1740,46 +1854,48 @@ git:rev-exists() {
1740
1854
  }
1741
1855
 
1742
1856
  git:ref-exists() {
1743
- test -n "$(git for-each-ref "$1")"
1857
+ [[ $(git for-each-ref "$1") ]]
1744
1858
  }
1745
1859
 
1746
1860
  git:get-head-branch-name() {
1747
1861
  output=
1748
- local name="$(git symbolic-ref --short --quiet HEAD)"
1862
+ local name
1863
+ name=$(git symbolic-ref --short --quiet HEAD) || true
1749
1864
  [[ $name == HEAD ]] && return
1750
- output="$name"
1865
+ output=$name
1751
1866
  }
1752
1867
 
1753
1868
  git:get-head-branch-commit() {
1754
- output="$(git rev-parse HEAD)"
1869
+ output=$(git rev-parse HEAD)
1755
1870
  }
1756
1871
 
1757
1872
  git:commit-in-rev-list() {
1758
- local commit="$1"
1759
- local list_head="$2"
1873
+ local commit=$1
1874
+ local list_head=$2
1760
1875
  git rev-list "$list_head" | grep -q "^$commit"
1761
1876
  }
1762
1877
 
1763
1878
  git:make-ref() {
1764
- local ref_name="$1"
1765
- local commit="$(git rev-parse "$2")"
1879
+ local ref_name=$1
1880
+ local commit
1881
+ commit=$(git rev-parse "$2")
1766
1882
  RUN git update-ref "$ref_name" "$commit"
1767
1883
  }
1768
1884
 
1769
1885
  git:is_merge_commit() {
1770
- local commit="$1"
1886
+ local commit=$1
1771
1887
  git show --summary "$commit" | grep -q ^Merge:
1772
1888
  }
1773
1889
 
1774
1890
  git:create-worktree() {
1775
- local branch="$1"
1776
- worktree="$GIT_TMP/$branch"
1891
+ local branch=$1
1892
+ worktree=$GIT_TMP/$branch
1777
1893
  RUN git worktree add "$worktree" "$branch"
1778
1894
  }
1779
1895
 
1780
1896
  git:remove-worktree() {
1781
1897
  o "Remove worktree: $worktree"
1782
- if [[ -d "$worktree" ]]; then
1898
+ if [[ -d $worktree ]]; then
1783
1899
  o "Check worktree for unsaved changes"
1784
1900
  cd "$worktree"
1785
1901
  assert-working-copy-is-clean
@@ -1792,7 +1908,7 @@ git:remove-worktree() {
1792
1908
  }
1793
1909
 
1794
1910
  git:delete-branch() {
1795
- local branch="$1"
1911
+ local branch=$1
1796
1912
  o "Deleting old '$branch' branch."
1797
1913
  # Remove worktree first, otherwise you can't delete the branch
1798
1914
  git:remove-worktree
@@ -1806,7 +1922,7 @@ git:delete-branch() {
1806
1922
 
1807
1923
  # Smart command runner:
1808
1924
  RUN() {
1809
- $debug_wanted && $SAY && say '>>>' $*
1925
+ $debug_wanted && $SAY && say ">>> $*"
1810
1926
  if $EXEC; then
1811
1927
  "$@"
1812
1928
  return $?
@@ -1820,9 +1936,9 @@ RUN() {
1820
1936
  "$@"
1821
1937
  else
1822
1938
  if $OUT; then
1823
- out="$("$@" 2>/dev/null)"
1939
+ out=$("$@" 2>/dev/null)
1824
1940
  else
1825
- out="$("$@" 2>&1)"
1941
+ out=$("$@" 2>&1)
1826
1942
  fi
1827
1943
  fi
1828
1944
  rc=$?
@@ -1832,7 +1948,7 @@ RUN() {
1832
1948
  OK=false
1833
1949
  $FAIL && error "Command failed: '$*'.\n$out"
1834
1950
  fi
1835
- output="$out"
1951
+ output=$out
1836
1952
  }
1837
1953
 
1838
1954
 
@@ -1853,7 +1969,7 @@ CALL() {
1853
1969
  # Print verbose steps for commands with steps:
1854
1970
  o() {
1855
1971
  if $verbose_wanted; then
1856
- echo "$INDENT* $@"
1972
+ echo "$INDENT* $*"
1857
1973
  fi
1858
1974
  }
1859
1975
 
@@ -1887,13 +2003,12 @@ usage-error() {
1887
2003
 
1888
2004
  # Nicely report common error messages:
1889
2005
  error() {
1890
- local msg="git-subrepo: $1" usage=
1891
- echo -e "$msg" >&2
2006
+ echo -e "git-subrepo:" "$@" >&2
1892
2007
  exit 1
1893
2008
  }
1894
2009
 
1895
2010
  # Start at the end:
1896
- [[ $BASH_SOURCE != "$0" ]] || main "$@"
2011
+ [[ ${BASH_SOURCE[0]} != "$0" ]] || main "$@"
1897
2012
 
1898
2013
  # Local Variables:
1899
2014
  # tab-width: 2