Skip to content

Commit 8242cc1

Browse files
committed
repository: set error message if trying to set HEAD to a checked out one
If trying to set the HEAD of a repository to another reference, we have to check whether this reference is already checked out in another linked work tree. If it is, we will refuse setting the HEAD and return an error, but do not set a meaningful error message. Add one.
1 parent 5b65ac2 commit 8242cc1

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/repository.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,6 +2562,8 @@ int git_repository_set_head(
25622562

25632563
if (ref && current->type == GIT_REF_SYMBOLIC && git__strcmp(current->target.symbolic, ref->name) &&
25642564
git_reference_is_branch(ref) && git_branch_is_checked_out(ref)) {
2565+
giterr_set(GITERR_REPOSITORY, "cannot set HEAD to reference '%s' as it is the current HEAD "
2566+
"of a linked repository.", git_reference_name(ref));
25652567
error = -1;
25662568
goto cleanup;
25672569
}

0 commit comments

Comments
 (0)