def _InitWorkTree(self): dotgit = os.path.join(self.worktree, '.git') if not os.path.exists(dotgit): os.makedirs(dotgit) for name in [ 'config', 'description', 'hooks', 'info', 'logs', 'objects', 'packed-refs', 'refs', 'rr-cache', 'svn' ]: try: src = os.path.join(self.gitdir, name) dst = os.path.join(dotgit, name) os.symlink(relpath(src, dst), dst) except OSError, e: if e.errno == errno.EPERM: raise GitError('filesystem must support symlinks') else: raise _lwrite(os.path.join(dotgit, HEAD), '%s\n' % self.GetRevisionId()) cmd = ['read-tree', '--reset', '-u'] cmd.append('-v') cmd.append(HEAD) if GitCommand(self, cmd).Wait() != 0: raise GitError("cannot initialize work tree") self._CopyFiles()
def UploadForReview(self, branch=None, replace_changes=None, people=([], [])): """Uploads the named branch for code review. """ if branch is None: branch = self.CurrentBranch if branch is None: raise GitError('not currently on a branch') branch = self.GetBranch(branch) if not branch.LocalMerge: raise GitError('branch %s does not track a remote' % branch.name) if not branch.remote.review: raise GitError('remote %s has no review url' % branch.remote.name) dest_branch = branch.merge if not dest_branch.startswith(R_HEADS): dest_branch = R_HEADS + dest_branch if not branch.remote.projectname: branch.remote.projectname = self.name branch.remote.Save() if branch.remote.ReviewProtocol == 'ssh': if dest_branch.startswith(R_HEADS): dest_branch = dest_branch[len(R_HEADS):] rp = ['gerrit receive-pack'] for e in people[0]: rp.append('--reviewer=%s' % sq(e)) for e in people[1]: rp.append('--cc=%s' % sq(e)) cmd = ['push'] cmd.append('--receive-pack=%s' % " ".join(rp)) cmd.append(branch.remote.SshReviewUrl(self.UserEmail)) cmd.append('%s:refs/for/%s' % (R_HEADS + branch.name, dest_branch)) if replace_changes: for change_id, commit_id in replace_changes.iteritems(): cmd.append('%s:refs/changes/%s/new' % (commit_id, change_id)) if GitCommand(self, cmd, bare=True).Wait() != 0: raise UploadError('Upload failed') else: raise UploadError('Unsupported protocol %s' \ % branch.remote.review) msg = "posted to %s for %s" % (branch.remote.review, dest_branch) self.bare_git.UpdateRef(R_PUB + branch.name, R_HEADS + branch.name, message=msg)
def _InitHooks(self): hooks = self._gitdir_path('hooks') if not os.path.exists(hooks): os.makedirs(hooks) for stock_hook in repo_hooks(): name = os.path.basename(stock_hook) if name in ('commit-msg') and not self.remote.review: # Don't install a Gerrit Code Review hook if this # project does not appear to use it for reviews. # continue dst = os.path.join(hooks, name) if os.path.islink(dst): continue if os.path.exists(dst): if filecmp.cmp(stock_hook, dst, shallow=False): os.remove(dst) else: _error("%s: Not replacing %s hook", self.relpath, name) continue try: os.symlink(relpath(stock_hook, dst), dst) except OSError, e: if e.errno == errno.EPERM: raise GitError('filesystem must support symlinks') else: raise
def _ResetHard(self, rev, quiet=True): cmd = ['reset', '--hard'] if quiet: cmd.append('-q') cmd.append(rev) if GitCommand(self, cmd).Wait() != 0: raise GitError('%s reset --hard %s ' % (self.name, rev))
def _Rebase(self, upstream, onto=None): cmd = ['rebase'] if onto is not None: cmd.extend(['--onto', onto]) cmd.append(upstream) if GitCommand(self, cmd).Wait() != 0: raise GitError('%s rebase %s ' % (self.name, upstream))
def _do(self, *args): command = ["config", "--file", self.file, "--includes"] command.extend(args) p = GitCommand(None, command, capture_stdout=True, capture_stderr=True) if p.Wait() == 0: return p.stdout else: GitError("git config %s: %s" % (str(args), p.stderr))
def _Checkout(self, rev, quiet=False): cmd = ['checkout'] if quiet: cmd.append('-q') cmd.append(rev) cmd.append('--') if GitCommand(self, cmd).Wait() != 0: if self._allrefs: raise GitError('%s checkout %s ' % (self.name, rev))
def _do(self, *args): command = ['config', '--file', self.file] command.extend(args) p = GitCommand(None, command, capture_stdout=True, capture_stderr=True) if p.Wait() == 0: return p.stdout else: GitError('git config %s: %s' % (str(args), p.stderr))
def Push(self, branch_base, branch=None, dest_branch=None, force=False): """Pushs the named branch. """ project = branch_base.project if branch is None: branch = project.CurrentBranch if branch is None: raise GitError('not currently on a branch') branch = project.GetBranch(branch) if not branch.LocalMerge: raise GitError('branch %s does not track a remote' % branch.name) if dest_branch is None: dest_branch = project.dest_branch if dest_branch is None: dest_branch = branch.merge if not dest_branch.startswith(R_HEADS): dest_branch = R_HEADS + dest_branch if not branch.remote.projectname: branch.remote.projectname = project.name branch.remote.Save() remote = branch.remote.name cmd = ['push'] if force: cmd.append('--force') cmd.append(remote) if dest_branch.startswith(R_HEADS): dest_branch = dest_branch[len(R_HEADS):] push_type = 'heads' ref_spec = '%s:refs/%s/%s' % (R_HEADS + branch.name, push_type, dest_branch) cmd.append(ref_spec) if GitCommand(project, cmd, bare=True).Wait() != 0: raise UploadError('Push failed')
def _InitWorkTree(self): dotgit = os.path.join(self.worktree, '.git') if not os.path.exists(dotgit): self._LinkWorkTree() _lwrite(os.path.join(dotgit, HEAD), '%s\n' % self.GetRevisionId()) cmd = ['read-tree', '--reset', '-u'] cmd.append('-v') cmd.append(HEAD) if GitCommand(self, cmd).Wait() != 0: raise GitError("cannot initialize work tree") self._CopyFiles()
def _LinkWorkTree(self, relink=False): dotgit = os.path.join(self.worktree, '.git') if not relink: os.makedirs(dotgit) for name in [ 'config', 'description', 'hooks', 'info', 'logs', 'objects', 'packed-refs', 'refs', 'rr-cache', 'svn' ]: try: src = os.path.join(self.gitdir, name) dst = os.path.join(dotgit, name) if relink: os.remove(dst) if os.path.islink(dst) or not os.path.exists(dst): os.symlink(relpath(src, dst), dst) else: raise GitError('cannot overwrite a local work tree') except OSError, e: if e.errno == errno.EPERM: raise GitError('filesystem must support symlinks') else: raise
def _do(self, *args): if self.file == self._SYSTEM_CONFIG: command = ['config', '--system', '--includes'] else: command = ['config', '--file', self.file, '--includes'] command.extend(args) p = GitCommand(None, command, capture_stdout=True, capture_stderr=True) if p.Wait() == 0: return p.stdout else: raise GitError('git config %s: %s' % (str(args), p.stderr))
def _InitHooks(self): hooks = self._gitdir_path('hooks') if not os.path.exists(hooks): os.makedirs(hooks) for stock_hook in repo_hooks(): dst = os.path.join(hooks, os.path.basename(stock_hook)) try: os.symlink(relpath(stock_hook, dst), dst) except OSError, e: if e.errno == errno.EEXIST: pass elif e.errno == errno.EPERM: raise GitError('filesystem must support symlinks') else: raise
def runner(*args): cmdv = [name] cmdv.extend(args) p = GitCommand(self._project, cmdv, bare=self._bare, capture_stdout=True, capture_stderr=True) if p.Wait() != 0: raise GitError('%s %s: %s' % (self._project.name, name, p.stderr)) r = p.stdout if r.endswith('\n') and r.index('\n') == len(r) - 1: return r[:-1] return r
def ToLocal(self, rev): """Convert a remote revision string to something we have locally. """ if IsId(rev): return rev if rev.startswith(R_TAGS): return rev if not rev.startswith('refs/'): rev = R_HEADS + rev for spec in self.fetch: if spec.SourceMatches(rev): return spec.MapSource(rev) raise GitError('remote %s does not have %s' % (self.name, rev))
def __init__(self, project, cmdv, provide_stdin=False, capture_stdout=False, capture_stderr=False, disable_editor=False, cwd=None): env = os.environ.copy() if disable_editor: _setenv(env, 'GIT_EDITOR', ':') #svn is locale dependent _setenv(env, 'LC_ALL', 'C') if project: if not cwd: cwd = project.worktree command = [SVN] command.extend(cmdv) if provide_stdin: stdin = subprocess.PIPE else: stdin = None if capture_stdout: stdout = subprocess.PIPE else: stdout = None if capture_stderr: stderr = subprocess.PIPE else: stderr = None try: p = subprocess.Popen(command, cwd=cwd, env=env, stdin=stdin, stdout=stdout, stderr=stderr) except Exception, e: raise GitError('%s: %s' % (command[1], e))
def ToLocal(self, rev): """Convert a remote revision string to something we have locally. """ if self.name == "." or IsId(rev): return rev if not rev.startswith("refs/"): rev = R_HEADS + rev for spec in self.fetch: if spec.SourceMatches(rev): return spec.MapSource(rev) if not rev.startswith(R_HEADS): return rev raise GitError( "%s: remote %s does not have %s" % (self.projectname, self.name, rev) )
def rev_list(self, *args, **kw): if 'format' in kw: cmdv = ['log', '--pretty=format:%s' % kw['format']] else: cmdv = ['rev-list'] cmdv.extend(args) p = GitCommand(self._project, cmdv, bare=self._bare, capture_stdout=True, capture_stderr=True) r = [] for line in p.process.stdout: if line[-1] == '\n': line = line[:-1] r.append(line) if p.Wait() != 0: raise GitError('%s rev-list %s: %s' % (self._project.name, str(args), p.stderr)) return r
def __init__(self, project, cmdv, bare = False, provide_stdin = False, capture_stdout = False, capture_stderr = False, disable_editor = False, ssh_proxy = False, cwd = None, gitdir = None): env = os.environ.copy() for key in [REPO_TRACE, GIT_DIR, 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_OBJECT_DIRECTORY', 'GIT_WORK_TREE', 'GIT_GRAFT_FILE', 'GIT_INDEX_FILE']: if key in env: del env[key] # If we are not capturing std* then need to print it. self.tee = {'stdout': not capture_stdout, 'stderr': not capture_stderr} if disable_editor: _setenv(env, 'GIT_EDITOR', ':') if ssh_proxy: _setenv(env, 'REPO_SSH_SOCK', ssh_sock()) _setenv(env, 'GIT_SSH', _ssh_proxy()) if 'http_proxy' in env and 'darwin' == sys.platform: s = "'http.proxy=%s'" % (env['http_proxy'],) p = env.get('GIT_CONFIG_PARAMETERS') if p is not None: s = p + ' ' + s _setenv(env, 'GIT_CONFIG_PARAMETERS', s) if project: if not cwd: cwd = project.worktree if not gitdir: gitdir = project.gitdir command = [GIT] if bare: if gitdir: _setenv(env, GIT_DIR, gitdir) cwd = None command.append(cmdv[0]) # Need to use the --progress flag for fetch/clone so output will be # displayed as by default git only does progress output if stderr is a TTY. if sys.stderr.isatty() and cmdv[0] in ('fetch', 'clone'): if '--progress' not in cmdv and '--quiet' not in cmdv: command.append('--progress') command.extend(cmdv[1:]) if provide_stdin: stdin = subprocess.PIPE else: stdin = None stdout = subprocess.PIPE stderr = subprocess.PIPE if IsTrace(): global LAST_CWD global LAST_GITDIR dbg = '' if cwd and LAST_CWD != cwd: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': cd %s\n' % cwd LAST_CWD = cwd if GIT_DIR in env and LAST_GITDIR != env[GIT_DIR]: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': export GIT_DIR=%s\n' % env[GIT_DIR] LAST_GITDIR = env[GIT_DIR] dbg += ': ' dbg += ' '.join(command) if stdin == subprocess.PIPE: dbg += ' 0<|' if stdout == subprocess.PIPE: dbg += ' 1>|' if stderr == subprocess.PIPE: dbg += ' 2>|' Trace('%s', dbg) try: p = subprocess.Popen(command, cwd = cwd, env = env, stdin = stdin, stdout = stdout, stderr = stderr) except Exception as e: raise GitError('%s: %s' % (command[1], e)) if ssh_proxy: _add_ssh_client(p) self.process = p self.stdin = p.stdin
def __init__(self, project, cmdv, bare=False, provide_stdin=False, capture_stdout=False, capture_stderr=False, disable_editor=False, ssh_proxy=False, cwd=None, gitdir=None): env = os.environ.copy() for key in [ REPO_TRACE, GIT_DIR, 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_OBJECT_DIRECTORY', 'GIT_WORK_TREE', 'GIT_GRAFT_FILE', 'GIT_INDEX_FILE' ]: if key in env: del env[key] if disable_editor: _setenv(env, 'GIT_EDITOR', ':') if ssh_proxy: _setenv(env, 'REPO_SSH_SOCK', ssh_sock()) _setenv(env, 'GIT_SSH', _ssh_proxy()) if 'http_proxy' in env and 'darwin' == sys.platform: s = "'http.proxy=%s'" % (env['http_proxy'], ) p = env.get('GIT_CONFIG_PARAMETERS') if p is not None: s = p + ' ' + s _setenv(env, 'GIT_CONFIG_PARAMETERS', s) if project: if not cwd: cwd = project.worktree if not gitdir: gitdir = project.gitdir command = [GIT] if bare: if gitdir: env[GIT_DIR] = gitdir cwd = None command.extend(cmdv) if provide_stdin: stdin = subprocess.PIPE else: stdin = None if capture_stdout: stdout = subprocess.PIPE else: stdout = None if capture_stderr: stderr = subprocess.PIPE else: stderr = None if IsTrace(): global LAST_CWD global LAST_GITDIR dbg = '' if cwd and LAST_CWD != cwd: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': cd %s\n' % cwd LAST_CWD = cwd if GIT_DIR in env and LAST_GITDIR != env[GIT_DIR]: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': export GIT_DIR=%s\n' % env[GIT_DIR] LAST_GITDIR = env[GIT_DIR] dbg += ': ' dbg += ' '.join(command) if stdin == subprocess.PIPE: dbg += ' 0<|' if stdout == subprocess.PIPE: dbg += ' 1>|' if stderr == subprocess.PIPE: dbg += ' 2>|' Trace('%s', dbg) try: p = subprocess.Popen(command, cwd=cwd, env=env, stdin=stdin, stdout=stdout, stderr=stderr) except Exception as e: raise GitError('%s: %s' % (command[1], e)) if ssh_proxy: _add_ssh_client(p) portable.SUBPROCESSES.append(p) self.process = p self.stdin = p.stdin
def __init__(self, project, cmdv, bare = False, provide_stdin = False, capture_stdout = False, capture_stderr = False, disable_editor = False, ssh_proxy = False, cwd = None, gitdir = None): env = os.environ.copy() for e in [REPO_TRACE, GIT_DIR, 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_OBJECT_DIRECTORY', 'GIT_WORK_TREE', 'GIT_GRAFT_FILE', 'GIT_INDEX_FILE']: if e in env: del env[e] if disable_editor: _setenv(env, 'GIT_EDITOR', ':') if ssh_proxy: _setenv(env, 'REPO_SSH_SOCK', ssh_sock()) _setenv(env, 'GIT_SSH', _ssh_proxy()) if project: if not cwd: cwd = project.worktree if not gitdir: gitdir = project.gitdir command = [GIT] if bare: if gitdir: _setenv(env, GIT_DIR, gitdir) cwd = None command.extend(cmdv) if provide_stdin: stdin = subprocess.PIPE else: stdin = None if capture_stdout: stdout = subprocess.PIPE else: stdout = None if capture_stderr: stderr = subprocess.PIPE else: stderr = None if IsTrace(): global LAST_CWD global LAST_GITDIR dbg = '' if cwd and LAST_CWD != cwd: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': cd %s\n' % cwd LAST_CWD = cwd if GIT_DIR in env and LAST_GITDIR != env[GIT_DIR]: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': export GIT_DIR=%s\n' % env[GIT_DIR] LAST_GITDIR = env[GIT_DIR] dbg += ': ' dbg += ' '.join(command) if stdin == subprocess.PIPE: dbg += ' 0<|' if stdout == subprocess.PIPE: dbg += ' 1>|' if stderr == subprocess.PIPE: dbg += ' 2>|' Trace('%s', dbg) try: p = subprocess.Popen(command, cwd = cwd, env = env, stdin = stdin, stdout = stdout, stderr = stderr) except Exception, e: raise GitError('%s: %s' % (command[1], e))
def __init__(self, project, cmdv, bare=False, provide_stdin=False, capture_stdout=False, capture_stderr=False, merge_output=False, disable_editor=False, ssh_proxy=False, cwd=None, gitdir=None): env = self._GetBasicEnv() # If we are not capturing std* then need to print it. self.tee = {'stdout': not capture_stdout, 'stderr': not capture_stderr} if disable_editor: env['GIT_EDITOR'] = ':' if ssh_proxy: env['REPO_SSH_SOCK'] = ssh_sock() env['GIT_SSH'] = _ssh_proxy() env['GIT_SSH_VARIANT'] = 'ssh' if 'http_proxy' in env and 'darwin' == sys.platform: s = "'http.proxy=%s'" % (env['http_proxy'],) p = env.get('GIT_CONFIG_PARAMETERS') if p is not None: s = p + ' ' + s env['GIT_CONFIG_PARAMETERS'] = s if 'GIT_ALLOW_PROTOCOL' not in env: env['GIT_ALLOW_PROTOCOL'] = ( 'file:git:http:https:ssh:persistent-http:persistent-https:sso:rpc') env['GIT_HTTP_USER_AGENT'] = user_agent.git if project: if not cwd: cwd = project.worktree if not gitdir: gitdir = project.gitdir command = [GIT] if bare: if gitdir: env[GIT_DIR] = gitdir cwd = None command.append(cmdv[0]) # Need to use the --progress flag for fetch/clone so output will be # displayed as by default git only does progress output if stderr is a TTY. if sys.stderr.isatty() and cmdv[0] in ('fetch', 'clone'): if '--progress' not in cmdv and '--quiet' not in cmdv: command.append('--progress') command.extend(cmdv[1:]) if provide_stdin: stdin = subprocess.PIPE else: stdin = None stdout = subprocess.PIPE stderr = subprocess.STDOUT if merge_output else subprocess.PIPE if IsTrace(): global LAST_CWD global LAST_GITDIR dbg = '' if cwd and LAST_CWD != cwd: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': cd %s\n' % cwd LAST_CWD = cwd if GIT_DIR in env and LAST_GITDIR != env[GIT_DIR]: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': export GIT_DIR=%s\n' % env[GIT_DIR] LAST_GITDIR = env[GIT_DIR] dbg += ': ' dbg += ' '.join(command) if stdin == subprocess.PIPE: dbg += ' 0<|' if stdout == subprocess.PIPE: dbg += ' 1>|' if stderr == subprocess.PIPE: dbg += ' 2>|' elif stderr == subprocess.STDOUT: dbg += ' 2>&1' Trace('%s', dbg) try: p = subprocess.Popen(command, cwd=cwd, env=env, stdin=stdin, stdout=stdout, stderr=stderr) except Exception as e: raise GitError('%s: %s' % (command[1], e)) if ssh_proxy: _add_ssh_client(p) self.process = p self.stdin = p.stdin
def __init__(self, project, cmdv, bare=False, input=None, capture_stdout=False, capture_stderr=False, merge_output=False, disable_editor=False, ssh_proxy=None, cwd=None, gitdir=None): env = self._GetBasicEnv() if disable_editor: env['GIT_EDITOR'] = ':' if ssh_proxy: env['REPO_SSH_SOCK'] = ssh_proxy.sock() env['GIT_SSH'] = ssh_proxy.proxy env['GIT_SSH_VARIANT'] = 'ssh' if 'http_proxy' in env and 'darwin' == sys.platform: s = "'http.proxy=%s'" % (env['http_proxy'], ) p = env.get('GIT_CONFIG_PARAMETERS') if p is not None: s = p + ' ' + s env['GIT_CONFIG_PARAMETERS'] = s if 'GIT_ALLOW_PROTOCOL' not in env: env['GIT_ALLOW_PROTOCOL'] = ( 'file:git:http:https:ssh:persistent-http:persistent-https:sso:rpc' ) env['GIT_HTTP_USER_AGENT'] = user_agent.git if project: if not cwd: cwd = project.worktree if not gitdir: gitdir = project.gitdir 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]) # Need to use the --progress flag for fetch/clone so output will be # displayed as by default git only does progress output if stderr is a TTY. if sys.stderr.isatty() and cmdv[0] in ('fetch', 'clone'): if '--progress' not in cmdv and '--quiet' not in cmdv: command.append('--progress') command.extend(cmdv[1:]) stdin = subprocess.PIPE if input else None stdout = subprocess.PIPE if capture_stdout else None stderr = (subprocess.STDOUT if merge_output else (subprocess.PIPE if capture_stderr else None)) if IsTrace(): global LAST_CWD global LAST_GITDIR dbg = '' if cwd and LAST_CWD != cwd: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': cd %s\n' % cwd LAST_CWD = cwd if GIT_DIR in env and LAST_GITDIR != env[GIT_DIR]: if LAST_GITDIR or LAST_CWD: dbg += '\n' dbg += ': export GIT_DIR=%s\n' % env[GIT_DIR] LAST_GITDIR = env[GIT_DIR] dbg += ': ' dbg += ' '.join(command) if stdin == subprocess.PIPE: dbg += ' 0<|' if stdout == subprocess.PIPE: dbg += ' 1>|' if stderr == subprocess.PIPE: dbg += ' 2>|' elif stderr == subprocess.STDOUT: dbg += ' 2>&1' Trace('%s', dbg) try: p = subprocess.Popen(command, cwd=cwd, env=env, encoding='utf-8', errors='backslashreplace', stdin=stdin, stdout=stdout, stderr=stderr) except Exception as e: raise GitError('%s: %s' % (command[1], e)) if ssh_proxy: ssh_proxy.add_client(p) self.process = p if input: if isinstance(input, str): input = input.encode('utf-8') p.stdin.write(input) p.stdin.close() try: self.stdout, self.stderr = p.communicate() finally: if ssh_proxy: ssh_proxy.remove_client(p) self.rc = p.wait()
def __init__( self, project, cmdv, bare=False, provide_stdin=False, capture_stdout=False, capture_stderr=False, merge_output=False, disable_editor=False, ssh_proxy=False, cwd=None, gitdir=None, ): env = self._GetBasicEnv() # If we are not capturing std* then need to print it. self.tee = {"stdout": not capture_stdout, "stderr": not capture_stderr} if disable_editor: env["GIT_EDITOR"] = ":" if ssh_proxy: env["REPO_SSH_SOCK"] = ssh_sock() env["GIT_SSH"] = _ssh_proxy() env["GIT_SSH_VARIANT"] = "ssh" if "http_proxy" in env and "darwin" == sys.platform: s = "'http.proxy=%s'" % (env["http_proxy"], ) p = env.get("GIT_CONFIG_PARAMETERS") if p is not None: s = p + " " + s env["GIT_CONFIG_PARAMETERS"] = s if "GIT_ALLOW_PROTOCOL" not in env: env["GIT_ALLOW_PROTOCOL"] = "file:git:http:https:ssh:persistent-http:persistent-https:sso:rpc" env["GIT_HTTP_USER_AGENT"] = user_agent.git if project: if not cwd: cwd = project.worktree if not gitdir: gitdir = project.gitdir command = [GIT] if bare: if gitdir: env[GIT_DIR] = gitdir cwd = None command.append(cmdv[0]) # Need to use the --progress flag for fetch/clone so output will be # displayed as by default git only does progress output if stderr is a TTY. if sys.stderr.isatty() and cmdv[0] in ("fetch", "clone"): if "--progress" not in cmdv and "--quiet" not in cmdv: command.append("--progress") command.extend(cmdv[1:]) if provide_stdin: stdin = subprocess.PIPE else: stdin = None stdout = subprocess.PIPE stderr = subprocess.STDOUT if merge_output else subprocess.PIPE if IsTrace(): global LAST_CWD global LAST_GITDIR dbg = "" if cwd and LAST_CWD != cwd: if LAST_GITDIR or LAST_CWD: dbg += "\n" dbg += ": cd %s\n" % cwd LAST_CWD = cwd if GIT_DIR in env and LAST_GITDIR != env[GIT_DIR]: if LAST_GITDIR or LAST_CWD: dbg += "\n" dbg += ": export GIT_DIR=%s\n" % env[GIT_DIR] LAST_GITDIR = env[GIT_DIR] dbg += ": " dbg += " ".join(command) if stdin == subprocess.PIPE: dbg += " 0<|" if stdout == subprocess.PIPE: dbg += " 1>|" if stderr == subprocess.PIPE: dbg += " 2>|" elif stderr == subprocess.STDOUT: dbg += " 2>&1" Trace("%s", dbg) try: p = subprocess.Popen(command, cwd=cwd, env=env, stdin=stdin, stdout=stdout, stderr=stderr) except Exception as e: raise GitError("%s: %s" % (command[1], e)) if ssh_proxy: _add_ssh_client(p) self.process = p self.stdin = p.stdin
def _FastForward(self, head): cmd = ['merge', head] if GitCommand(self, cmd).Wait() != 0: raise GitError('%s merge %s ' % (self.name, head))