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. Do export GIT_DIR for a remote helper. Switch testgit to use env instead of less favoured capability gitdir. Mention it's possible uses in documentation: data storage, auxiliary git commands needed by a helper. Signed-off-by: Dmitry Ivankov <divanorama@xxxxxxxxx> --- Instead of documenting capability gitdir export GIT_DIR. Turned out to be quite straightforward. Documentation/git-remote-helpers.txt | 18 ++++++++++++++++++ git-remote-testgit.py | 14 +------------- transport-helper.c | 10 ++++++++++ 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Documentation/git-remote-helpers.txt b/Documentation/git-remote-helpers.txt index 58f6ad4..394fc8e 100644 --- a/Documentation/git-remote-helpers.txt +++ b/Documentation/git-remote-helpers.txt @@ -47,6 +47,9 @@ arguments. The first argument specifies a remote repository as in git; it is either the name of a configured remote or a URL. The second argument specifies a URL; it is usually of the form '<transport>://<address>', but any arbitrary string is possible. +'GIT_DIR' environment variable is set up for the remote helper and +can be used to store some additional data or to invoke auxiliary git +commands. When git encounters a URL of the form '<transport>://<address>', where '<transport>' is a protocol that it cannot handle natively, it @@ -159,6 +162,14 @@ Supported if the helper has the "import" capability. + Supported if the helper has the "connect" capability. +'gitdir' <path>:: + Tells helper the location of current repository .git + directory. The path is absolute. The command is issued + immediately after "gitdir" capability line is read by + the caller. ++ +Supported if the helper has the "gitdir" capability. + If a fatal error occurs, the program writes the error message to stderr and exits. The caller should expect that a suitable error message has been printed if the child closes the connection without @@ -175,6 +186,7 @@ CAPABILITIES 'push':: 'import':: 'connect':: +'gitdir':: This helper supports the corresponding command with the same name. 'refspec' 'spec':: @@ -187,6 +199,12 @@ CAPABILITIES all, it must cover all refs reported by the list command; if it is not used, it is effectively "{asterisk}:{asterisk}" +'gitdir':: + The helper wants to know .git directory location. The gitdir + command is sent immediately after reading this capability. + The helper can read it immediately too or it can proceed with + reporting other capabilities and read it as a next command. + REF LIST ATTRIBUTES ------------------- diff --git a/git-remote-testgit.py b/git-remote-testgit.py index df9d512..df3e37f 100644 --- a/git-remote-testgit.py +++ b/git-remote-testgit.py @@ -35,7 +35,7 @@ def get_repo(alias, url): prefix = 'refs/testgit/%s/' % alias debug("prefix: '%s'", prefix) - repo.gitdir = "" + repo.gitdir = os.environ["GIT_DIR"] repo.alias = alias repo.prefix = prefix @@ -70,7 +70,6 @@ def do_capabilities(repo, args): print "import" print "export" - print "gitdir" print "refspec refs/heads/*:%s*" % repo.prefix print # end capabilities @@ -150,22 +149,11 @@ def do_export(repo, args): repo.non_local.push(repo.gitdir) -def do_gitdir(repo, args): - """Stores the location of the gitdir. - """ - - if not args: - die("gitdir needs an argument") - - repo.gitdir = ' '.join(args) - - COMMANDS = { 'capabilities': do_capabilities, 'list': do_list, 'import': do_import, 'export': do_export, - 'gitdir': do_gitdir, } diff --git a/transport-helper.c b/transport-helper.c index 660147f..3282693 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -105,6 +105,12 @@ static struct child_process *get_helper(struct transport *transport) int refspec_alloc = 0; int duped; int code; + char git_dir_buf[sizeof(GIT_DIR_ENVIRONMENT) + PATH_MAX + 1]; + const char *helper_env[] = { + git_dir_buf, + NULL + }; + if (data->helper) return data->helper; @@ -120,6 +126,10 @@ static struct child_process *get_helper(struct transport *transport) helper->argv[2] = remove_ext_force(transport->url); helper->git_cmd = 0; helper->silent_exec_failure = 1; + + snprintf(git_dir_buf, sizeof(git_dir_buf), "%s=%s", GIT_DIR_ENVIRONMENT, get_git_dir()); + helper->env = helper_env; + code = start_command(helper); if (code < 0 && errno == ENOENT) die("Unable to find remote helper for '%s'", data->name); -- 1.7.3.4 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html