Add the ability to delete a branch to git.py
authorChuck Lever <cel@netapp.com>
Thu, 6 Oct 2005 10:18:18 +0000 (11:18 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Thu, 6 Oct 2005 10:18:18 +0000 (11:18 +0100)
"git branch -D" checks first to see whether all the commits in the doomed
branch are already in the branch pointed to by HEAD.  I don't think we need
that level of checking here.  We just delete "refs/heads/branchname."

Signed-off-by: Chuck Lever <cel@netapp.com>
stgit/git.py

index cc3b55b..7bb41c5 100644 (file)
@@ -307,6 +307,14 @@ def switch_branch(name):
     if os.path.isfile(os.path.join(base_dir, 'MERGE_HEAD')):
         os.remove(os.path.join(base_dir, 'MERGE_HEAD'))
 
+def delete_branch(name):
+    """Delete a git branch
+    """
+    branch_head = os.path.join('refs', 'heads', name)
+    if not branch_exists(branch_head):
+        raise GitException, 'Branch "%s" does not exist' % name
+    os.remove(os.path.join(base_dir, branch_head))
+
 def add(names):
     """Add the files or recursively add the directory contents
     """