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
This commit is contained in:
commit
ace83dc26a
2
remote.c
2
remote.c
@ -693,7 +693,7 @@ static struct remote *remote_get_1(const char *name,
|
|||||||
name = get_default(current_branch, &name_given);
|
name = get_default(current_branch, &name_given);
|
||||||
|
|
||||||
ret = make_remote(name, 0);
|
ret = make_remote(name, 0);
|
||||||
if (valid_remote_nick(name)) {
|
if (valid_remote_nick(name) && have_git_dir()) {
|
||||||
if (!valid_remote(ret))
|
if (!valid_remote(ret))
|
||||||
read_remotes_file(ret);
|
read_remotes_file(ret);
|
||||||
if (!valid_remote(ret))
|
if (!valid_remote(ret))
|
||||||
|
@ -248,4 +248,13 @@ test_expect_success PIPE,JGIT,GIT_DAEMON 'indicate no refs in standards-complian
|
|||||||
test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git
|
test_expect_code 2 git ls-remote --exit-code git://localhost:$JGIT_DAEMON_PORT/empty.git
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'ls-remote works outside repository' '
|
||||||
|
# It is important for this repo to be inside the nongit
|
||||||
|
# area, as we want a repo name that does not include
|
||||||
|
# slashes (because those inhibit some of our configuration
|
||||||
|
# lookups).
|
||||||
|
nongit git init --bare dst.git &&
|
||||||
|
nongit git ls-remote dst.git
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
@ -34,6 +34,15 @@ test_expect_success 'clone http repository' '
|
|||||||
test_cmp file clone/file
|
test_cmp file clone/file
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'list refs from outside any repository' '
|
||||||
|
cat >expect <<-EOF &&
|
||||||
|
$(git rev-parse master) HEAD
|
||||||
|
$(git rev-parse master) refs/heads/master
|
||||||
|
EOF
|
||||||
|
nongit git ls-remote "$HTTPD_URL/dumb/repo.git" >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'create password-protected repository' '
|
test_expect_success 'create password-protected repository' '
|
||||||
mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
|
mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
|
||||||
cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
|
cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
|
||||||
|
@ -124,8 +124,9 @@ static struct child_process *get_helper(struct transport *transport)
|
|||||||
helper->git_cmd = 0;
|
helper->git_cmd = 0;
|
||||||
helper->silent_exec_failure = 1;
|
helper->silent_exec_failure = 1;
|
||||||
|
|
||||||
argv_array_pushf(&helper->env_array, "%s=%s", GIT_DIR_ENVIRONMENT,
|
if (have_git_dir())
|
||||||
get_git_dir());
|
argv_array_pushf(&helper->env_array, "%s=%s",
|
||||||
|
GIT_DIR_ENVIRONMENT, get_git_dir());
|
||||||
|
|
||||||
code = start_command(helper);
|
code = start_command(helper);
|
||||||
if (code < 0 && errno == ENOENT)
|
if (code < 0 && errno == ENOENT)
|
||||||
|
Loading…
Reference in New Issue
Block a user