git-remote-testgit: fix error handling
If fast-export did not complete successfully the error handling code
itself would error out.
This was broken in commit 23b093ee0
(Brandon Casey, Wed Jun 9 2010,
Remove python 2.5'isms). Revert that commit an introduce our own copy
of check_call in util.py instead.
Tested by changing 'if retcode' to 'if not retcode' temporarily.
Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
0fb56ce716
commit
460d10262d
@ -2,6 +2,8 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from git_remote_helpers.util import check_call
|
||||||
|
|
||||||
|
|
||||||
class GitExporter(object):
|
class GitExporter(object):
|
||||||
"""An exporter for testgit repositories.
|
"""An exporter for testgit repositories.
|
||||||
@ -53,6 +55,4 @@ class GitExporter(object):
|
|||||||
|
|
||||||
args = ["sed", "s_refs/heads/_" + self.repo.prefix + "_g"]
|
args = ["sed", "s_refs/heads/_" + self.repo.prefix + "_g"]
|
||||||
|
|
||||||
child = subprocess.Popen(args, stdin=p1.stdout)
|
check_call(args, stdin=p1.stdout)
|
||||||
if child.wait() != 0:
|
|
||||||
raise CalledProcessError
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from git_remote_helpers.util import check_call
|
||||||
|
|
||||||
|
|
||||||
class GitImporter(object):
|
class GitImporter(object):
|
||||||
"""An importer for testgit repositories.
|
"""An importer for testgit repositories.
|
||||||
@ -35,6 +37,4 @@ class GitImporter(object):
|
|||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
args.append("--import-marks=" + path)
|
args.append("--import-marks=" + path)
|
||||||
|
|
||||||
child = subprocess.Popen(args)
|
check_call(args)
|
||||||
if child.wait() != 0:
|
|
||||||
raise CalledProcessError
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from git_remote_helpers.util import die, warn
|
from git_remote_helpers.util import check_call, die, warn
|
||||||
|
|
||||||
|
|
||||||
class NonLocalGit(object):
|
class NonLocalGit(object):
|
||||||
@ -29,9 +29,7 @@ class NonLocalGit(object):
|
|||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
args = ["git", "clone", "--bare", "--quiet", self.repo.gitpath, path]
|
args = ["git", "clone", "--bare", "--quiet", self.repo.gitpath, path]
|
||||||
|
|
||||||
child = subprocess.Popen(args)
|
check_call(args)
|
||||||
if child.wait() != 0:
|
|
||||||
raise CalledProcessError
|
|
||||||
|
|
||||||
return path
|
return path
|
||||||
|
|
||||||
@ -45,14 +43,10 @@ class NonLocalGit(object):
|
|||||||
die("could not find repo at %s", path)
|
die("could not find repo at %s", path)
|
||||||
|
|
||||||
args = ["git", "--git-dir=" + path, "fetch", "--quiet", self.repo.gitpath]
|
args = ["git", "--git-dir=" + path, "fetch", "--quiet", self.repo.gitpath]
|
||||||
child = subprocess.Popen(args)
|
check_call(args)
|
||||||
if child.wait() != 0:
|
|
||||||
raise CalledProcessError
|
|
||||||
|
|
||||||
args = ["git", "--git-dir=" + path, "update-ref", "refs/heads/master", "FETCH_HEAD"]
|
args = ["git", "--git-dir=" + path, "update-ref", "refs/heads/master", "FETCH_HEAD"]
|
||||||
child = subprocess.Popen(args)
|
child = check_call(args)
|
||||||
if child.wait() != 0:
|
|
||||||
raise CalledProcessError
|
|
||||||
|
|
||||||
def push(self, base):
|
def push(self, base):
|
||||||
"""Pushes from the non-local repo to base.
|
"""Pushes from the non-local repo to base.
|
||||||
@ -64,6 +58,4 @@ class NonLocalGit(object):
|
|||||||
die("could not find repo at %s", path)
|
die("could not find repo at %s", path)
|
||||||
|
|
||||||
args = ["git", "--git-dir=" + path, "push", "--quiet", self.repo.gitpath, "--all"]
|
args = ["git", "--git-dir=" + path, "push", "--quiet", self.repo.gitpath, "--all"]
|
||||||
child = subprocess.Popen(args)
|
child = check_call(args)
|
||||||
if child.wait() != 0:
|
|
||||||
raise CalledProcessError
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from git_remote_helpers.util import check_call
|
||||||
|
|
||||||
|
|
||||||
def sanitize(rev, sep='\t'):
|
def sanitize(rev, sep='\t'):
|
||||||
"""Converts a for-each-ref line to a name/value pair.
|
"""Converts a for-each-ref line to a name/value pair.
|
||||||
"""
|
"""
|
||||||
@ -53,9 +56,7 @@ class GitRepo(object):
|
|||||||
path = ".cached_revs"
|
path = ".cached_revs"
|
||||||
ofile = open(path, "w")
|
ofile = open(path, "w")
|
||||||
|
|
||||||
child = subprocess.Popen(args, stdout=ofile)
|
check_call(args, stdout=ofile)
|
||||||
if child.wait() != 0:
|
|
||||||
raise CalledProcessError
|
|
||||||
output = open(path).readlines()
|
output = open(path).readlines()
|
||||||
self.revmap = dict(sanitize(i) for i in output)
|
self.revmap = dict(sanitize(i) for i in output)
|
||||||
if "HEAD" in self.revmap:
|
if "HEAD" in self.revmap:
|
||||||
|
@ -11,6 +11,21 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
try:
|
||||||
|
from subprocess import CalledProcessError
|
||||||
|
except ImportError:
|
||||||
|
# from python2.7:subprocess.py
|
||||||
|
# Exception classes used by this module.
|
||||||
|
class CalledProcessError(Exception):
|
||||||
|
"""This exception is raised when a process run by check_call() returns
|
||||||
|
a non-zero exit status. The exit status will be stored in the
|
||||||
|
returncode attribute."""
|
||||||
|
def __init__(self, returncode, cmd):
|
||||||
|
self.returncode = returncode
|
||||||
|
self.cmd = cmd
|
||||||
|
def __str__(self):
|
||||||
|
return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
|
||||||
|
|
||||||
|
|
||||||
# Whether or not to show debug messages
|
# Whether or not to show debug messages
|
||||||
DEBUG = False
|
DEBUG = False
|
||||||
@ -128,6 +143,38 @@ def run_command (args, cwd = None, shell = False, add_env = None,
|
|||||||
return (exit_code, output, errors)
|
return (exit_code, output, errors)
|
||||||
|
|
||||||
|
|
||||||
|
# from python2.7:subprocess.py
|
||||||
|
def call(*popenargs, **kwargs):
|
||||||
|
"""Run command with arguments. Wait for command to complete, then
|
||||||
|
return the returncode attribute.
|
||||||
|
|
||||||
|
The arguments are the same as for the Popen constructor. Example:
|
||||||
|
|
||||||
|
retcode = call(["ls", "-l"])
|
||||||
|
"""
|
||||||
|
return subprocess.Popen(*popenargs, **kwargs).wait()
|
||||||
|
|
||||||
|
|
||||||
|
# from python2.7:subprocess.py
|
||||||
|
def check_call(*popenargs, **kwargs):
|
||||||
|
"""Run command with arguments. Wait for command to complete. If
|
||||||
|
the exit code was zero then return, otherwise raise
|
||||||
|
CalledProcessError. The CalledProcessError object will have the
|
||||||
|
return code in the returncode attribute.
|
||||||
|
|
||||||
|
The arguments are the same as for the Popen constructor. Example:
|
||||||
|
|
||||||
|
check_call(["ls", "-l"])
|
||||||
|
"""
|
||||||
|
retcode = call(*popenargs, **kwargs)
|
||||||
|
if retcode:
|
||||||
|
cmd = kwargs.get("args")
|
||||||
|
if cmd is None:
|
||||||
|
cmd = popenargs[0]
|
||||||
|
raise CalledProcessError(retcode, cmd)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def file_reader_method (missing_ok = False):
|
def file_reader_method (missing_ok = False):
|
||||||
"""Decorator for simplifying reading of files.
|
"""Decorator for simplifying reading of files.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user