Skip to content

Commit e173587

Browse files
divanoramagitster
authored andcommitted
remote-helpers: export GIT_DIR variable to helpers
The gitdir capability is recognized by git and can be used to tell the helper where the .git directory is. But it is not mentioned in the documentation and considered worse than if gitdir was passed via GIT_DIR environment variable. Remove support for the gitdir capability and export GIT_DIR instead. Teach testgit to use env instead of the now-removed gitdir command. [sr: fixed up documentation] Signed-off-by: Dmitry Ivankov <[email protected]> Signed-off-by: Sverre Rabbelier <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b4b8729 commit e173587

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

Documentation/git-remote-helpers.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ arguments. The first argument specifies a remote repository as in git;
4747
it is either the name of a configured remote or a URL. The second
4848
argument specifies a URL; it is usually of the form
4949
'<transport>://<address>', but any arbitrary string is possible.
50+
The 'GIT_DIR' environment variable is set up for the remote helper
51+
and can be used to determine where to store additional data or from
52+
which directory to invoke auxiliary git commands.
5053

5154
When git encounters a URL of the form '<transport>://<address>', where
5255
'<transport>' is a protocol that it cannot handle natively, it

git-remote-testgit.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_repo(alias, url):
3535
prefix = 'refs/testgit/%s/' % alias
3636
debug("prefix: '%s'", prefix)
3737

38-
repo.gitdir = ""
38+
repo.gitdir = os.environ["GIT_DIR"]
3939
repo.alias = alias
4040
repo.prefix = prefix
4141

@@ -70,7 +70,6 @@ def do_capabilities(repo, args):
7070

7171
print "import"
7272
print "export"
73-
print "gitdir"
7473
print "refspec refs/heads/*:%s*" % repo.prefix
7574

7675
print # end capabilities
@@ -150,22 +149,11 @@ def do_export(repo, args):
150149
repo.non_local.push(repo.gitdir)
151150

152151

153-
def do_gitdir(repo, args):
154-
"""Stores the location of the gitdir.
155-
"""
156-
157-
if not args:
158-
die("gitdir needs an argument")
159-
160-
repo.gitdir = ' '.join(args)
161-
162-
163152
COMMANDS = {
164153
'capabilities': do_capabilities,
165154
'list': do_list,
166155
'import': do_import,
167156
'export': do_export,
168-
'gitdir': do_gitdir,
169157
}
170158

171159

transport-helper.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ static struct child_process *get_helper(struct transport *transport)
105105
int refspec_alloc = 0;
106106
int duped;
107107
int code;
108+
char git_dir_buf[sizeof(GIT_DIR_ENVIRONMENT) + PATH_MAX + 1];
109+
const char *helper_env[] = {
110+
git_dir_buf,
111+
NULL
112+
};
113+
108114

109115
if (data->helper)
110116
return data->helper;
@@ -120,6 +126,10 @@ static struct child_process *get_helper(struct transport *transport)
120126
helper->argv[2] = remove_ext_force(transport->url);
121127
helper->git_cmd = 0;
122128
helper->silent_exec_failure = 1;
129+
130+
snprintf(git_dir_buf, sizeof(git_dir_buf), "%s=%s", GIT_DIR_ENVIRONMENT, get_git_dir());
131+
helper->env = helper_env;
132+
123133
code = start_command(helper);
124134
if (code < 0 && errno == ENOENT)
125135
die("Unable to find remote helper for '%s'", data->name);
@@ -174,11 +184,6 @@ static struct child_process *get_helper(struct transport *transport)
174184
refspecs[refspec_nr++] = strdup(buf.buf + strlen("refspec "));
175185
} else if (!strcmp(capname, "connect")) {
176186
data->connect = 1;
177-
} else if (!strcmp(buf.buf, "gitdir")) {
178-
struct strbuf gitdir = STRBUF_INIT;
179-
strbuf_addf(&gitdir, "gitdir %s\n", get_git_dir());
180-
sendline(data, &gitdir);
181-
strbuf_release(&gitdir);
182187
} else if (mandatory) {
183188
die("Unknown mandatory capability %s. This remote "
184189
"helper probably needs newer version of Git.\n",

0 commit comments

Comments
 (0)