mirror of
				https://git.proxmox.com/git/libgit2
				synced 2025-11-04 14:08:17 +00:00 
			
		
		
		
	refs: propagate EEXISTS
Indicate whether the error comes from the ref already existing or elsewhere. We always perform the check and this lets the user write more concise code.
This commit is contained in:
		
							parent
							
								
									3665ba8eeb
								
							
						
					
					
						commit
						c128149315
					
				
							
								
								
									
										10
									
								
								src/refs.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/refs.c
									
									
									
									
									
								
							@ -1199,6 +1199,7 @@ int git_reference_create_symbolic(
 | 
			
		||||
{
 | 
			
		||||
	char normalized[GIT_REFNAME_MAX];
 | 
			
		||||
	git_reference *ref = NULL;
 | 
			
		||||
	int error;
 | 
			
		||||
 | 
			
		||||
	if (git_reference__normalize_name_lax(
 | 
			
		||||
		normalized,
 | 
			
		||||
@ -1206,8 +1207,8 @@ int git_reference_create_symbolic(
 | 
			
		||||
		name) < 0)
 | 
			
		||||
			return -1;
 | 
			
		||||
 | 
			
		||||
	if (reference_can_write(repo, normalized, NULL, force) < 0)
 | 
			
		||||
		return -1;
 | 
			
		||||
	if ((error = reference_can_write(repo, normalized, NULL, force)) < 0)
 | 
			
		||||
		return error;
 | 
			
		||||
 | 
			
		||||
	if (reference_alloc(&ref, repo, normalized) < 0)
 | 
			
		||||
		return -1;
 | 
			
		||||
@ -1236,6 +1237,7 @@ int git_reference_create_oid(
 | 
			
		||||
	const git_oid *id,
 | 
			
		||||
	int force)
 | 
			
		||||
{
 | 
			
		||||
	int error;
 | 
			
		||||
	git_reference *ref = NULL;
 | 
			
		||||
	char normalized[GIT_REFNAME_MAX];
 | 
			
		||||
 | 
			
		||||
@ -1245,8 +1247,8 @@ int git_reference_create_oid(
 | 
			
		||||
		name) < 0)
 | 
			
		||||
			return -1;
 | 
			
		||||
 | 
			
		||||
	if (reference_can_write(repo, normalized, NULL, force) < 0)
 | 
			
		||||
		return -1;
 | 
			
		||||
	if ((error = reference_can_write(repo, normalized, NULL, force)) < 0)
 | 
			
		||||
		return error;
 | 
			
		||||
 | 
			
		||||
	if (reference_alloc(&ref, repo, name) < 0)
 | 
			
		||||
		return -1;
 | 
			
		||||
 | 
			
		||||
@ -147,3 +147,18 @@ void test_refs_create__oid_unknown(void)
 | 
			
		||||
	/* Ensure the reference can't be looked-up... */
 | 
			
		||||
	cl_git_fail(git_reference_lookup(&looked_up_ref, g_repo, new_head));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void test_refs_create__propagate_eexists(void)
 | 
			
		||||
{
 | 
			
		||||
	int error;
 | 
			
		||||
	git_oid oid;
 | 
			
		||||
	git_reference *ref;
 | 
			
		||||
 | 
			
		||||
	/* Make sure it works for oid and for symbolic both */
 | 
			
		||||
	git_oid_fromstr(&oid, current_master_tip);
 | 
			
		||||
	error = git_reference_create_oid(&ref, g_repo, current_head_target, &oid, false);
 | 
			
		||||
	cl_assert(error == GIT_EEXISTS);
 | 
			
		||||
 | 
			
		||||
	error = git_reference_create_symbolic(&ref, g_repo, "HEAD", current_head_target, false);
 | 
			
		||||
	cl_assert(error == GIT_EEXISTS);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user