+ tree_id = rev_parse(os.path.join('refs', 'heads', new_branch)
+ + '^{commit}')
+ if tree_id != get_head():
+ refresh_index()
+ if __run('git-read-tree -u -m', [get_head(), tree_id]) != 0:
+ raise GitException, 'git-read-tree failed (local changes maybe?)'
+ __head = tree_id
+ set_head_file(new_branch)
+
+ if os.path.isfile(os.path.join(basedir.get(), 'MERGE_HEAD')):
+ os.remove(os.path.join(basedir.get(), 'MERGE_HEAD'))
+
+def delete_branch(name):
+ """Delete a git branch
+ """
+ if not branch_exists(name):
+ raise GitException, 'Branch "%s" does not exist' % name
+ remove_file_and_dirs(os.path.join(basedir.get(), 'refs', 'heads'),
+ name)
+
+def rename_branch(from_name, to_name):
+ """Rename a git branch
+ """
+ if not branch_exists(from_name):
+ raise GitException, 'Branch "%s" does not exist' % from_name
+ if branch_exists(to_name):
+ raise GitException, 'Branch "%s" already exists' % to_name
+
+ if get_head_file() == from_name:
+ set_head_file(to_name)
+ rename(os.path.join(basedir.get(), 'refs', 'heads'),
+ from_name, to_name)