summaryrefslogtreecommitdiff
path: root/src/branch.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2015-11-06 12:33:59 +0100
committerPatrick Steinhardt <ps@pks.im>2017-02-13 11:05:57 +0100
commit143e539fd0e9b83c6a3a369d5baf508ccb51697b (patch)
treef38a69f6e65cfdfd4c37d543cd6f18330c2b602d /src/branch.c
parente3acd37b70dc6d8f1ff256b99a26b4e0f13701ef (diff)
downloadlibgit2-143e539fd0e9b83c6a3a369d5baf508ccb51697b.tar.gz
branch: restrict branch deletion for worktrees
Restrict the ability to delete branches that are checked out in any linked repository.
Diffstat (limited to 'src/branch.c')
-rw-r--r--src/branch.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/branch.c b/src/branch.c
index e48cb1f68..7d5e9cb7f 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -206,6 +206,12 @@ int git_branch_delete(git_reference *branch)
return -1;
}
+ if (git_reference_is_branch(branch) && git_branch_is_checked_out(branch)) {
+ giterr_set(GITERR_REFERENCE, "Cannot delete branch '%s' as it is "
+ "the current HEAD of a linked repository.", git_reference_name(branch));
+ return -1;
+ }
+
if (git_buf_join(&config_section, '.', "branch",
git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR)) < 0)
goto on_error;