mirror of
				https://git.proxmox.com/git/libgit2
				synced 2025-11-04 14:08:17 +00:00 
			
		
		
		
	index: validate mode of new conflicts
This commit is contained in:
		
							parent
							
								
									3ab5a65967
								
							
						
					
					
						commit
						d67f270e58
					
				@ -1317,6 +1317,15 @@ int git_index_conflict_add(git_index *index,
 | 
			
		||||
		(ret = index_entry_dup(&entries[2], INDEX_OWNER(index), their_entry)) < 0)
 | 
			
		||||
		goto on_error;
 | 
			
		||||
 | 
			
		||||
	/* Validate entries */
 | 
			
		||||
	for (i = 0; i < 3; i++) {
 | 
			
		||||
		if (entries[i] && !valid_filemode(entries[i]->mode)) {
 | 
			
		||||
			giterr_set(GITERR_INDEX, "invalid filemode for stage %d entry",
 | 
			
		||||
				i);
 | 
			
		||||
			return -1;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* Remove existing index entries for each path */
 | 
			
		||||
	for (i = 0; i < 3; i++) {
 | 
			
		||||
		if (entries[i] == NULL)
 | 
			
		||||
 | 
			
		||||
@ -47,14 +47,17 @@ void test_index_conflicts__add(void)
 | 
			
		||||
	memset(&their_entry, 0x0, sizeof(git_index_entry));
 | 
			
		||||
 | 
			
		||||
	ancestor_entry.path = "test-one.txt";
 | 
			
		||||
	ancestor_entry.mode = 0100644;
 | 
			
		||||
	ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
 | 
			
		||||
	git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID);
 | 
			
		||||
 | 
			
		||||
	our_entry.path = "test-one.txt";
 | 
			
		||||
	our_entry.mode = 0100644;
 | 
			
		||||
	ancestor_entry.flags |= (2 << GIT_IDXENTRY_STAGESHIFT);
 | 
			
		||||
	git_oid_fromstr(&our_entry.id, TEST_OUR_OID);
 | 
			
		||||
 | 
			
		||||
	their_entry.path = "test-one.txt";
 | 
			
		||||
	their_entry.mode = 0100644;
 | 
			
		||||
	ancestor_entry.flags |= (3 << GIT_IDXENTRY_STAGESHIFT);
 | 
			
		||||
	git_oid_fromstr(&their_entry.id, TEST_THEIR_OID);
 | 
			
		||||
 | 
			
		||||
@ -75,14 +78,17 @@ void test_index_conflicts__add_fixes_incorrect_stage(void)
 | 
			
		||||
	memset(&their_entry, 0x0, sizeof(git_index_entry));
 | 
			
		||||
 | 
			
		||||
	ancestor_entry.path = "test-one.txt";
 | 
			
		||||
	ancestor_entry.mode = 0100644;
 | 
			
		||||
	ancestor_entry.flags |= (3 << GIT_IDXENTRY_STAGESHIFT);
 | 
			
		||||
	git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID);
 | 
			
		||||
 | 
			
		||||
	our_entry.path = "test-one.txt";
 | 
			
		||||
	our_entry.mode = 0100644;
 | 
			
		||||
	ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
 | 
			
		||||
	git_oid_fromstr(&our_entry.id, TEST_OUR_OID);
 | 
			
		||||
 | 
			
		||||
	their_entry.path = "test-one.txt";
 | 
			
		||||
	their_entry.mode = 0100644;
 | 
			
		||||
	ancestor_entry.flags |= (2 << GIT_IDXENTRY_STAGESHIFT);
 | 
			
		||||
	git_oid_fromstr(&their_entry.id, TEST_THEIR_OID);
 | 
			
		||||
 | 
			
		||||
@ -109,8 +115,8 @@ void test_index_conflicts__add_removes_stage_zero(void)
 | 
			
		||||
	memset(&our_entry, 0x0, sizeof(git_index_entry));
 | 
			
		||||
	memset(&their_entry, 0x0, sizeof(git_index_entry));
 | 
			
		||||
 | 
			
		||||
	staged.mode = 0100644;
 | 
			
		||||
	staged.path = "test-one.txt";
 | 
			
		||||
	staged.mode = 0100644;
 | 
			
		||||
	git_oid_fromstr(&staged.id, TEST_STAGED_OID);
 | 
			
		||||
	cl_git_pass(git_index_add(repo_index, &staged));
 | 
			
		||||
	cl_assert(git_index_entrycount(repo_index) == 9);
 | 
			
		||||
@ -322,6 +328,7 @@ void test_index_conflicts__partial(void)
 | 
			
		||||
	memset(&their_entry, 0x0, sizeof(git_index_entry));
 | 
			
		||||
 | 
			
		||||
	ancestor_entry.path = "test-one.txt";
 | 
			
		||||
	ancestor_entry.mode = 0100644;
 | 
			
		||||
	ancestor_entry.flags |= (1 << GIT_IDXENTRY_STAGESHIFT);
 | 
			
		||||
	git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -461,14 +461,17 @@ void test_status_worktree__conflict_with_diff3(void)
 | 
			
		||||
	memset(&their_entry, 0x0, sizeof(git_index_entry));
 | 
			
		||||
 | 
			
		||||
	ancestor_entry.path = "modified_file";
 | 
			
		||||
	ancestor_entry.mode = 0100644;
 | 
			
		||||
	git_oid_fromstr(&ancestor_entry.id,
 | 
			
		||||
		"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
 | 
			
		||||
 | 
			
		||||
	our_entry.path = "modified_file";
 | 
			
		||||
	our_entry.mode = 0100644;
 | 
			
		||||
	git_oid_fromstr(&our_entry.id,
 | 
			
		||||
		"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
 | 
			
		||||
 | 
			
		||||
	their_entry.path = "modified_file";
 | 
			
		||||
	their_entry.mode = 0100644;
 | 
			
		||||
	git_oid_fromstr(&their_entry.id,
 | 
			
		||||
		"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
 | 
			
		||||
 | 
			
		||||
@ -614,14 +617,17 @@ void test_status_worktree__conflicted_item(void)
 | 
			
		||||
	memset(&our_entry, 0x0, sizeof(git_index_entry));
 | 
			
		||||
	memset(&their_entry, 0x0, sizeof(git_index_entry));
 | 
			
		||||
 | 
			
		||||
	ancestor_entry.mode = 0100644;
 | 
			
		||||
	ancestor_entry.path = "modified_file";
 | 
			
		||||
	git_oid_fromstr(&ancestor_entry.id,
 | 
			
		||||
		"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
 | 
			
		||||
 | 
			
		||||
	our_entry.mode = 0100644;
 | 
			
		||||
	our_entry.path = "modified_file";
 | 
			
		||||
	git_oid_fromstr(&our_entry.id,
 | 
			
		||||
		"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
 | 
			
		||||
 | 
			
		||||
	their_entry.mode = 0100644;
 | 
			
		||||
	their_entry.path = "modified_file";
 | 
			
		||||
	git_oid_fromstr(&their_entry.id,
 | 
			
		||||
		"452e4244b5d083ddf0460acf1ecc74db9dcfa11a");
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user