def branch_exists(branch):
"""Existence check for the named branch
"""
- for line in _output_lines(['git-rev-parse', '--symbolic', '--all']):
+ for line in _output_lines('git-rev-parse --symbolic --all 2>&1'):
if line.strip() == branch:
return True
+ if re.compile('[ |/]'+branch+' ').search(line):
+ raise GitException, 'Bogus branch: %s' % line
return False
def create_branch(new_branch, tree_id = None):
if not files:
files = []
- if tree_id and __run('git-read-tree -m', [tree_id]) != 0:
- raise GitException, 'Failed git-read-tree -m %s' % tree_id
+ if tree_id and __run('git-read-tree --reset', [tree_id]) != 0:
+ raise GitException, 'Failed git-read-tree --reset %s' % tree_id
checkout_cmd = 'git-checkout-index -q -u'
if force:
tree_id = get_head()
if check_out:
+ cache_files = __tree_status(files, tree_id)
+ # files which were added but need to be removed
+ rm_files = [x[1] for x in cache_files if x[0] in ['A']]
+
checkout(files, tree_id, True)
+ # checkout doesn't remove files
+ map(os.remove, rm_files)
# if the reset refers to the whole tree, switch the HEAD as well
if not files: