mirror of
				https://git.proxmox.com/git/libgit2
				synced 2025-11-04 07:09:14 +00:00 
			
		
		
		
	This adds giterr_user_cancel to return GIT_EUSER and clear any error message that is sitting around. As a result of using that in places, we need to be more thorough with capturing errors that happen inside a callback when used internally. To help with that, this also adds giterr_capture and giterr_restore so that when we internally use a foreach-type function that clears errors and converts them to GIT_EUSER, it is easier to restore not just the return value, but the actual error message text.
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include "clar_libgit2.h"
 | 
						|
 | 
						|
#include "config.h"
 | 
						|
 | 
						|
static git_config *cfg;
 | 
						|
static const char *value;
 | 
						|
 | 
						|
void test_config_validkeyname__initialize(void)
 | 
						|
{
 | 
						|
	cl_fixture_sandbox("config/config10");
 | 
						|
 | 
						|
	cl_git_pass(git_config_open_ondisk(&cfg, "config10"));
 | 
						|
}
 | 
						|
 | 
						|
void test_config_validkeyname__cleanup(void)
 | 
						|
{
 | 
						|
	git_config_free(cfg);
 | 
						|
	cfg = NULL;
 | 
						|
 | 
						|
	cl_fixture_cleanup("config10");
 | 
						|
}
 | 
						|
 | 
						|
static void assert_invalid_config_key_name(const char *name)
 | 
						|
{
 | 
						|
	cl_git_fail_with(git_config_get_string(&value, cfg, name),
 | 
						|
		GIT_EINVALIDSPEC);
 | 
						|
	cl_git_fail_with(git_config_set_string(cfg, name, "42"),
 | 
						|
		GIT_EINVALIDSPEC);
 | 
						|
	cl_git_fail_with(git_config_delete_entry(cfg, name),
 | 
						|
		GIT_EINVALIDSPEC);
 | 
						|
	cl_git_fail_with(git_config_get_multivar_foreach(cfg, name, "*", NULL, NULL),
 | 
						|
		GIT_EINVALIDSPEC);
 | 
						|
	cl_git_fail_with(git_config_set_multivar(cfg, name, "*", "42"),
 | 
						|
		GIT_EINVALIDSPEC);
 | 
						|
}
 | 
						|
 | 
						|
void test_config_validkeyname__accessing_requires_a_valid_name(void)
 | 
						|
{
 | 
						|
	assert_invalid_config_key_name("");
 | 
						|
	assert_invalid_config_key_name(".");
 | 
						|
	assert_invalid_config_key_name("..");
 | 
						|
	assert_invalid_config_key_name("core.");
 | 
						|
	assert_invalid_config_key_name("d#ff.dirstat.lines");
 | 
						|
	assert_invalid_config_key_name("diff.dirstat.lines#");
 | 
						|
	assert_invalid_config_key_name("dif\nf.dirstat.lines");
 | 
						|
	assert_invalid_config_key_name("dif.dir\nstat.lines");
 | 
						|
	assert_invalid_config_key_name("dif.dirstat.li\nes");
 | 
						|
}
 |