def _run(self): returncode = 0 date = self.commit_date(self.commit) head = self.git.rev_parse('--short', 'HEAD') command = ['cvs', '-Q', '-d', self.cvsroot, 'checkout', '-P', '-D', date, '-d', self.tempdir, self.module] if not self.options.quiet: print "(%s) '%s'" % (head, "' '".join(command)) # At least with OpenBSD's version of GNU CVS it is not # possible to run "cvs checkout" from a directory that's # inside the CVS repository. This should avoid the # issue... *grrrr* The error is: cvs [checkout aborted]: # Cannot check out files into the repository itself try: owd = os.getcwd() os.chdir('/') subprocess.check_call(command) finally: os.chdir(owd) command = ['diff', '-r', self.tempdir, self.git.git_work_tree] pipe = subprocess.Popen(command, stdout=PIPE, stderr=PIPE) stdout, dummy = pipe.communicate() for line in stripnl(stdout).split('\n'): if re.match('^Only in .+: \.git$', line): continue if re.match('^Only in .+: CVS$', line): continue if not self.options.quiet: sys.stdout.write(line + '\n') returncode = 1 return returncode
def expand_log_keyword(self, change, rcsfile, revision, prefix): timestamp = time.gmtime(change.timestamp) timestamp = time.strftime('%Y/%m/%d %H:%M:%S', timestamp) s = prefix + ('Revision %s %s %s\n' % (revision, timestamp, change.author)) log = stripnl(rcsfile.rcsfile.getlog(revision)) for line in log.split('\n'): s += (prefix + line).rstrip() + '\n' s += prefix.rstrip() return s
def __init__(self, command, returncode, stderr=None): self.command = command self.returncode = returncode self.stderr = stderr msg = "'%s' exited with code %d" % \ (' '.join(command), returncode) if stderr: stderr = '\n '.join(stripnl(stderr).split('\n')) msg += '\n\nError output of %s command:\n %s' % \ (command[0], stderr) super(GitCommandError, self).__init__(msg)
def config_get(self, varname, default=None): """Retrieve the value of a config variable. This method may be called before the repository exists. In that case it will always return the default value. """ if not os.path.isdir(self.directory): return default command = ['git', 'config', '--get', varname] pipe = self._popen(command, stdout=PIPE, stderr=PIPE) stdout, stderr = pipe.communicate() if pipe.returncode == 0: return stripnl(stdout) elif pipe.returncode == 1: return default else: raise GitCommandError(command, pipe.returncode, stderr)
def check_command(self, command, *args, **kwargs): """Run a "git" subcommand with given arguments. Raises a GitCommandError if the subcommand does not return a zero exit code. The stdout keyword argument can take any value that subprocess.Popen would accept. If it is subprocess.PIPE, then the output of the command is returned as a string. """ stdout = None for kw in kwargs.keys(): if kw == 'stdout': stdout = kwargs[kw] else: raise ArgumentError, 'Invalid keyword: %s' % kw command = ['git', command] + list(args) pipe = self._popen(command, stdout=stdout, stderr=PIPE) out, err = pipe.communicate() if pipe.returncode != 0: raise GitCommandError(command, pipe.returncode, err) if stdout == PIPE: return stripnl(out)