:raises: BranchNotFoundError if the branch is not found;
RuntimeError for other errors
"""
+ validate_branch(branch)
try:
if not os.path.isdir(dest_path):
clone_repo(repo_url, dest_path, branch)
:raises: BranchNotFoundError if the branch is not found;
RuntimeError for other errors
"""
+ validate_branch(branch)
log.info("Cloning %s %s from upstream", repo_url, branch)
proc = subprocess.Popen(
('git', 'clone', '--branch', branch, repo_url, dest_path),
:raises: BranchNotFoundError if the branch is not found;
RuntimeError for other errors
"""
+ validate_branch(branch)
log.info("Fetching %s from upstream", branch)
proc = subprocess.Popen(
('git', 'fetch', '-p', 'origin', branch),
:raises: BranchNotFoundError if the branch is not found;
RuntimeError for other errors
"""
+ validate_branch(branch)
# This try/except block will notice if the requested branch doesn't
# exist, whether it was cloned or fetched.
try:
repo_str = ""
return "Branch {branch} not found{repo_str}!".format(
branch=self.branch, repo_str=repo_str)
+
+
+def validate_branch(branch):
+ if ' ' in branch:
+ raise ValueError("Illegal branch name: '%s'" % branch)
repo_url = 'file://' + src_path
dest_path = '/tmp/empty_dest'
- def setup(self):
+ def setup_method(self, method):
assert not os.path.exists(self.dest_path)
proc = subprocess.Popen(
('git', 'init', self.src_path),
+ stdout=subprocess.PIPE,
)
assert proc.wait() == 0
proc = subprocess.Popen(
('git', 'commit', '--allow-empty', '--allow-empty-message',
'--no-edit'),
cwd=self.src_path,
+ stdout=subprocess.PIPE,
)
assert proc.wait() == 0
- def teardown(self):
+ def teardown_method(self, method):
shutil.rmtree(self.dest_path, ignore_errors=True)
def test_existing_branch(self):
repo_utils.enforce_repo_state(self.repo_url, self.dest_path,
'master')
assert os.path.exists(self.dest_path)
+
+ def test_invalid_branch(self):
+ with raises(ValueError):
+ repo_utils.enforce_repo_state(self.repo_url, self.dest_path, 'a b')