Skip to content

Commit ace83dc

Browse files
committed
Merge branch 'jn/remote-helpers-with-git-dir'
"git ls-remote" and "git archive --remote" are designed to work without being in a directory under Git's control. However, recent updates revealed that we randomly look into a directory called .git/ without actually doing necessary set-up when working in a repository. Stop doing so. * jn/remote-helpers-with-git-dir: remote helpers: avoid blind fall-back to ".git" when setting GIT_DIR remote: avoid reading $GIT_DIR config in non-repo
2 parents 036465a + 4b0c3c7 commit ace83dc

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ static struct remote *remote_get_1(const char *name,
693693
name = get_default(current_branch, &name_given);
694694

695695
ret = make_remote(name, 0);
696-
if (valid_remote_nick(name)) {
696+
if (valid_remote_nick(name) && have_git_dir()) {
697697
if (!valid_remote(ret))
698698
read_remotes_file(ret);
699699
if (!valid_remote(ret))

t/t5512-ls-remote.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,13 @@ test_expect_success PIPE,JGIT,GIT_DAEMON 'indicate no refs in standards-complian
248248
test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git
249249
'
250250

251+
test_expect_success 'ls-remote works outside repository' '
252+
# It is important for this repo to be inside the nongit
253+
# area, as we want a repo name that does not include
254+
# slashes (because those inhibit some of our configuration
255+
# lookups).
256+
nongit git init --bare dst.git &&
257+
nongit git ls-remote dst.git
258+
'
259+
251260
test_done

t/t5550-http-fetch-dumb.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ test_expect_success 'clone http repository' '
3434
test_cmp file clone/file
3535
'
3636

37+
test_expect_success 'list refs from outside any repository' '
38+
cat >expect <<-EOF &&
39+
$(git rev-parse master) HEAD
40+
$(git rev-parse master) refs/heads/master
41+
EOF
42+
nongit git ls-remote "$HTTPD_URL/dumb/repo.git" >actual &&
43+
test_cmp expect actual
44+
'
45+
3746
test_expect_success 'create password-protected repository' '
3847
mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
3948
cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \

transport-helper.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ static struct child_process *get_helper(struct transport *transport)
124124
helper->git_cmd = 0;
125125
helper->silent_exec_failure = 1;
126126

127-
argv_array_pushf(&helper->env_array, "%s=%s", GIT_DIR_ENVIRONMENT,
128-
get_git_dir());
127+
if (have_git_dir())
128+
argv_array_pushf(&helper->env_array, "%s=%s",
129+
GIT_DIR_ENVIRONMENT, get_git_dir());
129130

130131
code = start_command(helper);
131132
if (code < 0 && errno == ENOENT)

0 commit comments

Comments
 (0)