diff options
| author | Patrick Steinhardt <ps@pks.im> | 2015-10-27 14:17:52 +0100 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2017-02-13 11:06:52 +0100 |
| commit | 384518d09dc16b8a7dae22069e0c612e4b65c5e8 (patch) | |
| tree | d7ca75438b77086f902a4f60abb0d578666984a3 /src | |
| parent | 143e539fd0e9b83c6a3a369d5baf508ccb51697b (diff) | |
| download | libgit2-384518d09dc16b8a7dae22069e0c612e4b65c5e8.tar.gz | |
repository: restrict checking out checked out branches
If a branch is already checked out in a working tree we are not
allowed to check out that branch in another repository. Introduce
this restriction when setting a repository's HEAD.
Diffstat (limited to 'src')
| -rw-r--r-- | src/repository.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/repository.c b/src/repository.c index 445005e96..8753636cb 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2529,6 +2529,12 @@ int git_repository_set_head( if (error < 0 && error != GIT_ENOTFOUND) goto cleanup; + if (ref && current->type == GIT_REF_SYMBOLIC && git__strcmp(current->target.symbolic, ref->name) && + git_reference_is_branch(ref) && git_branch_is_checked_out(ref)) { + error = -1; + goto cleanup; + } + if (!error) { if (git_reference_is_branch(ref)) { error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, |
