@@ -21,6 +21,10 @@ VCSH_SELF='@TRANSFORMED_PACKAGE_NAME@'; export VCSH_SELF
21
21
# Ensure all files created are accessible only to the current user.
22
22
umask 0077
23
23
24
+ # Allow override of shell dependencies (including outside of $PATH) either by
25
+ # setting ENV vars at build time or run time.
26
+ alias git=" ${GIT:-@ GIT@ } "
27
+
24
28
fatal () {
25
29
echo " $VCSH_SELF : fatal: $1 " >&2
26
30
[ -z " $2 " ] && exit 1
@@ -169,7 +173,7 @@ info() {
169
173
clone () {
170
174
hook pre-clone
171
175
# Check if remote is reachable. Abort early if there's a typo, TLS certificate problem, etc
172
- @GIT@ ls-remote " $GIT_REMOTE " 2> /dev/null || fatal " Can not reach '$GIT_REMOTE '"
176
+ git ls-remote " $GIT_REMOTE " 2> /dev/null || fatal " Can not reach '$GIT_REMOTE '"
173
177
init
174
178
# Test which, if any, given or detected branches can be pulled from.
175
179
# In a future version, if we need the logic, we could do the following:
@@ -179,7 +183,7 @@ clone() {
179
183
# set VCSH_BRANCH if only one match
180
184
# offer a list of all matching refs for the user to choose
181
185
for VCSH_BRANCH_TEST in " $VCSH_BRANCH " master trunk development; do
182
- if [ $( @GIT@ ls-remote " $GIT_REMOTE " " $VCSH_BRANCH_TEST " 2> /dev/null | @WC@ -l ) -lt 1 ]; then
186
+ if [ $( git ls-remote " $GIT_REMOTE " " $VCSH_BRANCH_TEST " 2> /dev/null | @WC@ -l ) -lt 1 ]; then
183
187
info " remote branch '$VCSH_BRANCH_TEST ' empty"
184
188
else
185
189
info " remote branch '$VCSH_BRANCH_TEST ' found"
@@ -194,21 +198,21 @@ clone() {
194
198
VCSH_BRANCH=$VCSH_BRANCH_REMOTE
195
199
196
200
# Set up remote
197
- @GIT@ remote add origin " $GIT_REMOTE "
198
- @GIT@ checkout -b " $VCSH_BRANCH " || return $?
199
- @GIT@ config branch." $VCSH_BRANCH " .remote origin
200
- @GIT@ config branch." $VCSH_BRANCH " .merge refs/heads/" $VCSH_BRANCH "
201
- GIT_VERSION_MAJOR=$( @GIT@ --version | @SED@ -E -n ' s/.* ([0-9]+)\..*/\1/p' )
201
+ git remote add origin " $GIT_REMOTE "
202
+ git checkout -b " $VCSH_BRANCH " || return $?
203
+ git config branch." $VCSH_BRANCH " .remote origin
204
+ git config branch." $VCSH_BRANCH " .merge refs/heads/" $VCSH_BRANCH "
205
+ GIT_VERSION_MAJOR=$( git --version | @SED@ -E -n ' s/.* ([0-9]+)\..*/\1/p' )
202
206
if [ 1 -lt " $GIT_VERSION_MAJOR " ]; then
203
- @GIT@ fetch origin " $VCSH_BRANCH "
207
+ git fetch origin " $VCSH_BRANCH "
204
208
else
205
- @GIT@ fetch origin
209
+ git fetch origin
206
210
fi
207
211
hook pre-merge
208
- @GIT@ read-tree -n -mu origin/" $VCSH_BRANCH " \
212
+ git read-tree -n -mu origin/" $VCSH_BRANCH " \
209
213
|| fatal " will stop after fetching and not try to merge!
210
214
Once this situation has been resolved, run 'vcsh $VCSH_REPO_NAME pull' to finish cloning." 17 # editorconfig-checker-disable-line
211
- @GIT@ -c merge.ff=true merge origin/" $VCSH_BRANCH "
215
+ git -c merge.ff=true merge origin/" $VCSH_BRANCH "
212
216
hook post-merge
213
217
hook post-clone
214
218
retire
@@ -224,7 +228,7 @@ commit() {
224
228
GIT_DIR=$VCSH_REPO_D /$VCSH_REPO_NAME .git; export GIT_DIR
225
229
use
226
230
hook_repo pre-commit
227
- @GIT@ commit --untracked-files=no --quiet " $@ "
231
+ git commit --untracked-files=no --quiet " $@ "
228
232
hook_repo post-commit
229
233
VCSH_COMMAND_RETURN_CODE=$?
230
234
echo
@@ -236,7 +240,7 @@ delete() {
236
240
cd " $VCSH_BASE " || fatal " could not enter '$VCSH_BASE '" 11
237
241
use
238
242
info " This operation WILL DESTROY DATA!"
239
- files=$( @GIT@ ls-files)
243
+ files=$( git ls-files)
240
244
echo " These files will be deleted:
241
245
242
246
$files
@@ -263,7 +267,7 @@ foreach() {
263
267
264
268
# We default to prefixing `git` to all commands passed to foreach, but
265
269
# allow running in general context with -g
266
- command_prefix=@GIT@
270
+ command_prefix=git
267
271
# shellcheck disable=SC2220
268
272
while getopts gp flag; do
269
273
case " $flag " in
@@ -319,7 +323,7 @@ init() {
319
323
[ ! -e " $GIT_DIR " ] || fatal " '$GIT_DIR ' exists" 10
320
324
mkdir -p " $VCSH_BASE " || fatal " could not create '$VCSH_BASE '" 50
321
325
cd " $VCSH_BASE " || fatal " could not enter '$VCSH_BASE '" 11
322
- @GIT@ init --shared=false
326
+ git init --shared=false
323
327
upgrade
324
328
hook post-init
325
329
}
@@ -335,13 +339,13 @@ list_has_remote() {
335
339
GIT_DIR=$VCSH_REPO_D /$VCSH_REPO_NAME .git; export GIT_DIR
336
340
# This command returns the tracking branch of the currently-checked-out local
337
341
# branch, if any. See https://stackoverflow.com/a/9753364
338
- [ -n " $( @GIT@ for-each-ref " $( @GIT@ symbolic-ref -q HEAD) " ) " ] && echo " $VCSH_REPO_NAME "
342
+ [ -n " $( git for-each-ref " $( git symbolic-ref -q HEAD) " ) " ] && echo " $VCSH_REPO_NAME "
339
343
done
340
344
}
341
345
342
346
get_files () {
343
347
GIT_DIR=$VCSH_REPO_D /$VCSH_REPO_NAME .git; export GIT_DIR
344
- @GIT@ ls-files --full-name
348
+ git ls-files --full-name
345
349
}
346
350
347
351
list_tracked () {
@@ -397,7 +401,7 @@ list_untracked() {
397
401
398
402
list_untracked_helper () {
399
403
export GIT_DIR=" $VCSH_REPO_D /$VCSH_REPO_NAME .git"
400
- @GIT@ ls-files --others $exclude_standard_opt $directory_opt | (
404
+ git ls-files --others $exclude_standard_opt $directory_opt | (
401
405
while read -r line; do
402
406
echo " $line "
403
407
directory_component=${line%%/* }
@@ -420,7 +424,7 @@ pull() {
420
424
GIT_DIR=$VCSH_REPO_D /$VCSH_REPO_NAME .git; export GIT_DIR
421
425
use
422
426
hook_repo pre-pull
423
- @GIT@ pull
427
+ git pull
424
428
hook_repo post-pull
425
429
VCSH_COMMAND_RETURN_CODE=$?
426
430
echo
@@ -436,7 +440,7 @@ push() {
436
440
GIT_DIR=$VCSH_REPO_D /$VCSH_REPO_NAME .git; export GIT_DIR
437
441
use
438
442
hook_repo pre-push
439
- @GIT@ push
443
+ git push
440
444
hook_repo post-push
441
445
VCSH_COMMAND_RETURN_CODE=$?
442
446
echo
@@ -494,13 +498,13 @@ status_helper() {
494
498
use
495
499
# Shellcheck isn't understanding a complex block.
496
500
# shellcheck disable=SC1083
497
- remote_tracking_branch=$( @GIT@ rev-parse --abbrev-ref --symbolic-full-name @{u} 2> /dev/null) && {
498
- commits_behind=$( @GIT@ log ..${remote_tracking_branch} --oneline | @WC@ -l)
499
- commits_ahead=$( @GIT@ log ${remote_tracking_branch} .. --oneline | @WC@ -l)
501
+ remote_tracking_branch=$( git rev-parse --abbrev-ref --symbolic-full-name @{u} 2> /dev/null) && {
502
+ commits_behind=$( git log ..${remote_tracking_branch} --oneline | @WC@ -l)
503
+ commits_ahead=$( git log ${remote_tracking_branch} .. --oneline | @WC@ -l)
500
504
[ ${commits_behind} -ne 0 ] && echo " Behind $remote_tracking_branch by $commits_behind commits"
501
505
[ ${commits_ahead} -ne 0 ] && echo " Ahead of $remote_tracking_branch by $commits_ahead commits"
502
506
}
503
- @GIT@ ${VCSH_GIT_OPTIONS} status --short --untracked-files=' no' | @SED@ -E ' s@([^ ] +)@\1~/@'
507
+ git ${VCSH_GIT_OPTIONS} status --short --untracked-files=' no' | @SED@ -E ' s@([^ ] +)@\1~/@'
504
508
VCSH_COMMAND_RETURN_CODE=$?
505
509
}
506
510
@@ -509,20 +513,20 @@ upgrade() {
509
513
# fake-bare repositories are not bare, actually. Set this to false
510
514
# because otherwise Git complains "fatal: core.bare and core.worktree
511
515
# do not make sense"
512
- @GIT@ config core.bare false
516
+ git config core.bare false
513
517
# core.worktree may be absolute or relative to $GIT_DIR, depending on
514
518
# user preference
515
519
if [ ! " x$VCSH_WORKTREE " = ' xabsolute' ]; then
516
- @GIT@ config core.worktree " $( cd " $GIT_DIR " && GIT_WORK_TREE=$VCSH_BASE @GIT@ rev-parse --show-cdup) "
520
+ git config core.worktree " $( cd " $GIT_DIR " && GIT_WORK_TREE=$VCSH_BASE git rev-parse --show-cdup) "
517
521
elif [ ! " x$VCSH_WORKTREE " = ' xrelative' ]; then
518
- @GIT@ config core.worktree " $VCSH_BASE "
522
+ git config core.worktree " $VCSH_BASE "
519
523
fi
520
- [ ! " x$VCSH_GITIGNORE " = ' xnone' ] && @GIT@ config core.excludesfile " .gitignore.d/$VCSH_REPO_NAME "
521
- [ ! " x$VCSH_GITATTRIBUTES " = ' xnone' ] && @GIT@ config core.attributesfile " .gitattributes.d/$VCSH_REPO_NAME "
522
- @GIT@ config vcsh.vcsh ' true'
524
+ [ ! " x$VCSH_GITIGNORE " = ' xnone' ] && git config core.excludesfile " .gitignore.d/$VCSH_REPO_NAME "
525
+ [ ! " x$VCSH_GITATTRIBUTES " = ' xnone' ] && git config core.attributesfile " .gitattributes.d/$VCSH_REPO_NAME "
526
+ git config vcsh.vcsh ' true'
523
527
use
524
- [ -e " $VCSH_BASE /.gitignore.d/$VCSH_REPO_NAME " ] && @GIT@ add -f " $VCSH_BASE /.gitignore.d/$VCSH_REPO_NAME "
525
- [ -e " $VCSH_BASE /.gitattributes.d/$VCSH_REPO_NAME " ] && @GIT@ add -f " $VCSH_BASE /.gitattributes.d/$VCSH_REPO_NAME "
528
+ [ -e " $VCSH_BASE /.gitignore.d/$VCSH_REPO_NAME " ] && git add -f " $VCSH_BASE /.gitignore.d/$VCSH_REPO_NAME "
529
+ [ -e " $VCSH_BASE /.gitattributes.d/$VCSH_REPO_NAME " ] && git add -f " $VCSH_BASE /.gitattributes.d/$VCSH_REPO_NAME "
526
530
hook post-upgrade
527
531
}
528
532
@@ -558,12 +562,12 @@ write_gitignore() {
558
562
# Works in all shells we care about.
559
563
# shellcheck disable=SC2039,SC3043
560
564
local GIT_VERSION GIT_VERSION_MAJOR GIT_VERSION_MINOR
561
- GIT_VERSION=" $( @GIT@ --version) "
565
+ GIT_VERSION=" $( git --version) "
562
566
GIT_VERSION_MAJOR=" $( echo " $GIT_VERSION " | @SED@ -E -n ' s/.* ([0-9]+)\..*/\1/p' ) "
563
567
GIT_VERSION_MINOR=" $( echo " $GIT_VERSION " | @SED@ -E -n ' s/.* ([0-9]+)\.([0-9]+)\..*/\2/p' ) "
564
568
OLDIFS=$IFS
565
569
IFS=$( printf ' \n\t' )
566
- gitignores=$( for file in $( @GIT@ ls-files) ; do
570
+ gitignores=$( for file in $( git ls-files) ; do
567
571
while true ; do
568
572
echo " $file " ; new=${file%/* }
569
573
[ x" $file " = x" $new " ] && break
@@ -604,7 +608,7 @@ write_gitignore() {
604
608
fatal " could not move '$tempfile ' to '$GIT_IGNORE_PATH '" 53
605
609
}
606
610
607
- debug " $( @GIT@ version) "
611
+ debug " $( git version) "
608
612
609
613
if [ ! " x$VCSH_GITIGNORE " = ' xexact' ] && [ ! " x$VCSH_GITIGNORE " = ' xnone' ] && [ ! " x$VCSH_GITIGNORE " = ' xrecursive' ]; then
610
614
fatal " '\$ VCSH_GITIGNORE' must equal 'exact', 'none', or 'recursive'" 1
@@ -658,7 +662,7 @@ elif [ "$VCSH_COMMAND" = 'help' ]; then
658
662
help && exit
659
663
elif [ " $VCSH_COMMAND " = ' version' ]; then
660
664
echo " $VCSH_SELF $VCSH_VERSION "
661
- @GIT@ version
665
+ git version
662
666
exit
663
667
elif [ x" $VCSH_COMMAND " = x' which' ]; then
664
668
[ -z " $2 " ] && fatal " $VCSH_COMMAND : please specify a filename" 1
@@ -705,7 +709,7 @@ elif [ -n "$2" ]; then
705
709
GIT_DIR=$VCSH_REPO_D /$VCSH_REPO_NAME .git; export GIT_DIR
706
710
[ -d " $GIT_DIR " ] || { help ; exit 1; }
707
711
shift 1
708
- set -- " @GIT@ " " $@ "
712
+ set -- " git " " $@ "
709
713
elif [ -n " $VCSH_COMMAND " ]; then
710
714
VCSH_COMMAND=' enter' ; export VCSH_COMMAND
711
715
VCSH_REPO_NAME=$1 ; export VCSH_REPO_NAME
0 commit comments