diff --git a/git_command.py b/git_command.py index 95db91f2..5d73c281 100644 --- a/git_command.py +++ b/git_command.py @@ -169,7 +169,8 @@ class GitCommand(object): disable_editor=False, ssh_proxy=None, cwd=None, - gitdir=None): + gitdir=None, + objdir=None): env = self._GetBasicEnv() if disable_editor: @@ -194,13 +195,24 @@ class GitCommand(object): cwd = project.worktree if not gitdir: gitdir = project.gitdir + # Git on Windows wants its paths only using / for reliability. + if platform_utils.isWindows(): + if objdir: + objdir = objdir.replace('\\', '/') + if gitdir: + gitdir = gitdir.replace('\\', '/') + + if objdir: + # Set to the place we want to save the objects. + env['GIT_OBJECT_DIRECTORY'] = objdir + if gitdir: + # Allow git to search the original place in case of local or unique refs + # that git will attempt to resolve even if we aren't fetching them. + env['GIT_ALTERNATE_OBJECT_DIRECTORIES'] = gitdir + '/objects' command = [GIT] if bare: if gitdir: - # Git on Windows wants its paths only using / for reliability. - if platform_utils.isWindows(): - gitdir = gitdir.replace('\\', '/') env[GIT_DIR] = gitdir cwd = None command.append(cmdv[0]) @@ -234,6 +246,11 @@ class GitCommand(object): dbg += ': export GIT_DIR=%s\n' % env[GIT_DIR] LAST_GITDIR = env[GIT_DIR] + if 'GIT_OBJECT_DIRECTORY' in env: + dbg += ': export GIT_OBJECT_DIRECTORY=%s\n' % env['GIT_OBJECT_DIRECTORY'] + if 'GIT_ALTERNATE_OBJECT_DIRECTORIES' in env: + dbg += ': export GIT_ALTERNATE_OBJECT_DIRECTORIES=%s\n' % env['GIT_ALTERNATE_OBJECT_DIRECTORIES'] + dbg += ': ' dbg += ' '.join(command) if stdin == subprocess.PIPE: diff --git a/project.py b/project.py index 8598de36..b70f6d41 100644 --- a/project.py +++ b/project.py @@ -2192,8 +2192,10 @@ class Project(object): retry_cur_sleep = retry_sleep_initial_sec ok = prune_tried = False for try_n in range(retry_fetches): - gitcmd = GitCommand(self, cmd, bare=True, ssh_proxy=ssh_proxy, - merge_output=True, capture_stdout=quiet or bool(output_redir)) + gitcmd = GitCommand( + self, cmd, bare=True, objdir=os.path.join(self.objdir, 'objects'), + ssh_proxy=ssh_proxy, + merge_output=True, capture_stdout=quiet or bool(output_redir)) if gitcmd.stdout and not quiet and output_redir: output_redir.write(gitcmd.stdout) ret = gitcmd.Wait() @@ -2309,7 +2311,8 @@ class Project(object): cmd.append(str(f)) cmd.append('+refs/tags/*:refs/tags/*') - ok = GitCommand(self, cmd, bare=True).Wait() == 0 + ok = GitCommand( + self, cmd, bare=True, objdir=os.path.join(self.objdir, 'objects')).Wait() == 0 platform_utils.remove(bundle_dst, missing_ok=True) platform_utils.remove(bundle_tmp, missing_ok=True) return ok