Skip to content

Commit ce6724b

Browse files
committed
Support spaces in subrepo path
subrepo residing in a path that contained an element with a space would fail due to insufficient grouping in some scripts.
1 parent f83d6ec commit ce6724b

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

lib/git-subrepo

+3-3
Original file line numberDiff line numberDiff line change
@@ -1542,8 +1542,8 @@ add-subrepo() {
15421542
# Determine the upstream's default head branch:
15431543
get-upstream-head-branch() {
15441544
local remotes branch
1545-
OUT=true RUN git ls-remote --symref $subrepo_remote
1546-
remotes="$output"
1545+
OUT=true RUN git ls-remote --symref "$subrepo_remote"
1546+
remotes=$output
15471547
[[ -n $remotes ]] ||
15481548
error "Failed to 'git ls-remote --symref $subrepo_remote'."
15491549

@@ -1553,7 +1553,7 @@ get-upstream-head-branch() {
15531553
grep "^ref:" | grep 'HEAD$' | cut -f2 -d':' | cut -f1 |
15541554
head -n1
15551555
)"
1556-
branch="${branch/ }"
1556+
branch=${branch/ }
15571557
[[ $branch =~ refs/heads/ ]] ||
15581558
error "Problem finding remote default head branch."
15591559
output="${branch#refs/heads/}"

test/branch.t

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@ clone-foo-and-bar
1010

1111
subrepo-clone-bar-into-foo
1212

13-
before="$(date -r $OWNER/foo/Foo '+%s')"
13+
before="$(date -r "$OWNER"/foo/Foo '+%s')"
1414

1515
(
16-
cd $OWNER/foo
16+
cd "$OWNER"/foo
1717
add-new-files bar/file
1818
add-new-files .gitrepo
1919
)
2020

21-
save-original-state $OWNER/foo bar
21+
save-original-state "$OWNER"/foo bar
2222

2323
# Make sure that time stamps differ
2424
sleep 1
2525

2626
is "$(
27-
cd $OWNER/foo
27+
cd "$OWNER"/foo
2828
git subrepo branch bar
2929
)" \
3030
"Created branch 'subrepo/bar' and worktree '.git/tmp/subrepo/bar'." \
3131
"subrepo branch command output is correct"
3232

3333

34-
after="$(date -r $OWNER/foo/Foo '+%s')"
35-
assert-original-state $OWNER/foo bar
34+
after="$(date -r "$OWNER"/foo/Foo '+%s')"
35+
assert-original-state "$OWNER"/foo bar
3636

3737
# Check that we haven't checked out any temporary files
3838
is "$before" "$after" \
3939
"No modification on Foo"
4040

41-
test-exists "$OWNER/foo/.git/tmp/subrepo/bar/"
41+
test-exists "$OWNER"/foo/.git/tmp/subrepo/bar/
4242

4343
is "$(
44-
cd $OWNER/foo/.git/tmp/subrepo/bar
44+
cd "$OWNER"/foo/.git/tmp/subrepo/bar
4545
git branch | grep \*
4646
)" \
4747
"* subrepo/bar" \

test/setup

+28-28
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ git config core.autocrlf input
66
set -e
77

88
# Set the GIT_SUBREPO_ROOT for testing.
9-
source $PWD/.rc
9+
source "$PWD"/.rc
10+
11+
BASHLIB="$(
12+
find "$PWD"/ -type d -name bin -o -type d -name lib | tr '\n' ':'
13+
)"
14+
export BASHLIB
1015

11-
export BASHLIB="`
12-
find $PWD -type d |
13-
grep -E '/(bin|lib)$' |
14-
xargs -n1 printf "%s:"
15-
`"
1616
export PATH="$BASHLIB:$PATH"
1717
source bash+ :std
1818

@@ -64,7 +64,7 @@ subrepo-clone-bar-into-foo() {
6464

6565
add-new-files() {
6666
local file
67-
for file in $*; do
67+
for file in "$@"; do
6868
echo "new file $file" > "$file"
6969
git add "$file"
7070
done
@@ -73,15 +73,15 @@ add-new-files() {
7373

7474
remove-files() {
7575
local file
76-
for file in $*; do
76+
for file in "$@"; do
7777
git rm "$file"
7878
done
7979
git commit --quiet -m "Removed file: $file" &> /dev/null
8080
}
8181

8282
modify-files() {
8383
local file
84-
for file in $*; do
84+
for file in "$@"; do
8585
echo 'a new line' >> "$file"
8686
git add "$file"
8787
done
@@ -90,7 +90,7 @@ modify-files() {
9090

9191
modify-files-ex() {
9292
local file
93-
for file in $*; do
93+
for file in "$@"; do
9494
echo "$file" >> "$file"
9595
git add "$file"
9696
done
@@ -102,49 +102,49 @@ test-exists() {
102102
if [[ $f =~ ^! ]]; then
103103
f="${f#!}"
104104
if [[ $f =~ /$ ]]; then
105-
ok "`[ ! -d "$f" ]`" \
105+
ok "$([ ! -d "$f" ])" \
106106
"Directory '$f' does not exist"
107107
else
108-
ok "`[ ! -f "$f" ]`" \
108+
ok "$([ ! -f "$f" ])" \
109109
"File '$f' does not exist"
110110
fi
111111
else
112112
if [[ $f =~ /$ ]]; then
113-
ok "`[ -d "$f" ]`" \
113+
ok "$([ -d "$f" ])" \
114114
"Directory '$f' exists"
115115
else
116-
ok "`[ -f "$f" ]`" \
116+
ok "$([ -f "$f" ])" \
117117
"File '$f' exists"
118118
fi
119119
fi
120120
done
121121
}
122122

123123
test-exists-in-index() {
124-
for f in $*; do
124+
for f in "$@"; do
125125
if [[ "$f" =~ ^! ]]; then
126126
f="${f#!}"
127127
if [[ "$f" =~ /$ ]]; then
128-
ok "`[ ! $(git ls-tree --full-tree --name-only -r HEAD "$f") ]`" \
128+
ok "$([ ! "$(git ls-tree --full-tree --name-only -r HEAD "$f")" ])" \
129129
"Directory '$f' does not exist in index"
130130
else
131-
ok "`[ ! $(git ls-tree --full-tree --name-only -r HEAD "$f") ]`" \
131+
ok "$([ ! "$(git ls-tree --full-tree --name-only -r HEAD "$f")" ])" \
132132
"File '$f' does not exist in index"
133133
fi
134134
else
135135
if [[ "$f" =~ /$ ]]; then
136-
ok "`[ $(git ls-tree --full-tree --name-only -r HEAD "$f") ]`" \
136+
ok "$([ "$(git ls-tree --full-tree --name-only -r HEAD "$f")" ])" \
137137
"Directory '$f' exists in index"
138138
else
139-
ok "`[ $(git ls-tree --full-tree --name-only -r HEAD "$f") ]`" \
139+
ok "$([ "$(git ls-tree --full-tree --name-only -r HEAD "$f")" ])" \
140140
"File '$f' exists in index"
141141
fi
142142
fi
143143
done
144144
}
145145

146146
test-gitrepo-comment-block() {
147-
is "$(grep -E '^;' $gitrepo)" "\
147+
is "$(grep -E '^;' "$gitrepo")" "\
148148
; DO NOT EDIT (unless you know what you are doing)
149149
;
150150
; This subdirectory is a git \"subrepo\", and this file is maintained by the
@@ -154,29 +154,29 @@ test-gitrepo-comment-block() {
154154
}
155155

156156
test-gitrepo-field() {
157-
is "`git config -f $gitrepo subrepo.$1`" \
157+
is "$(git config -f "$gitrepo" subrepo."$1")" \
158158
"$2" \
159159
".gitrepo $1 is correct"
160160
}
161161

162162
test-commit-count() {
163-
is "`cd $1; git rev-list --count $2`" \
163+
is "$(cd "$1"; git rev-list --count "$2")" \
164164
"$3" \
165165
"commit count is correct"
166166
}
167167

168168
save-original-state() {
169-
original_head_ref="$(cd $1; cat .git/HEAD)"
169+
original_head_ref="$(cd "$1"; cat .git/HEAD)"
170170
original_branch="${original_head_ref#ref: refs/heads/}"
171-
original_head_commit="$(cd $1; git rev-parse HEAD)"
172-
original_gitrepo="$(cd $1; cat $2/.gitrepo)"
171+
original_head_commit="$(cd "$1"; git rev-parse HEAD)"
172+
original_gitrepo="$(cd "$1"; cat "$2"/.gitrepo)"
173173
}
174174

175175
assert-original-state() {
176-
current_head_ref="$(cd $1; cat .git/HEAD)"
176+
current_head_ref="$(cd "$1"; cat .git/HEAD)"
177177
current_branch="${current_head_ref#ref: refs/heads/}"
178-
current_head_commit="$(cd $1; git rev-parse HEAD)"
179-
current_gitrepo="$(cd $1; cat $2/.gitrepo)"
178+
current_head_commit="$(cd "$1"; git rev-parse HEAD)"
179+
current_gitrepo="$(cd "$1"; cat "$2"/.gitrepo)"
180180

181181
is "$current_head_ref" \
182182
"$original_head_ref" \

0 commit comments

Comments
 (0)