@@ -4,13 +4,12 @@ git_repository *_repo;
44
55void test_object_shortid__initialize (void )
66{
7- cl_git_pass ( git_repository_open ( & _repo , cl_fixture ("duplicate.git" )) );
7+ _repo = cl_git_sandbox_init ("duplicate.git" );
88}
99
1010void test_object_shortid__cleanup (void )
1111{
12- git_repository_free (_repo );
13- _repo = NULL ;
12+ cl_git_sandbox_cleanup ();
1413}
1514
1615void test_object_shortid__select (void )
@@ -49,3 +48,53 @@ void test_object_shortid__select(void)
4948
5049 git_buf_dispose (& shorty );
5150}
51+
52+ void test_object_shortid__core_abbrev (void )
53+ {
54+ git_oid full ;
55+ git_object * obj ;
56+ git_buf shorty = {0 };
57+ git_config * cfg ;
58+
59+ cl_git_pass (git_repository_config (& cfg , _repo ));
60+ git_oid__fromstr (& full , "ce013625030ba8dba906f756967f9e9ca394464a" , GIT_OID_SHA1 );
61+ cl_git_pass (git_object_lookup (& obj , _repo , & full , GIT_OBJECT_ANY ));
62+
63+ cl_git_pass (git_config_set_string (cfg , "core.abbrev" , "auto" ));
64+ cl_git_pass (git_object_short_id (& shorty , obj ));
65+ cl_assert_equal_i (7 , shorty .size );
66+ cl_assert_equal_s ("ce01362" , shorty .ptr );
67+
68+ cl_git_pass (git_config_set_string (cfg , "core.abbrev" , "off" ));
69+ cl_git_pass (git_object_short_id (& shorty , obj ));
70+ cl_assert_equal_i (40 , shorty .size );
71+ cl_assert_equal_s ("ce013625030ba8dba906f756967f9e9ca394464a" , shorty .ptr );
72+
73+ cl_git_pass (git_config_set_string (cfg , "core.abbrev" , "false" ));
74+ cl_git_pass (git_object_short_id (& shorty , obj ));
75+ cl_assert_equal_i (40 , shorty .size );
76+ cl_assert_equal_s ("ce013625030ba8dba906f756967f9e9ca394464a" , shorty .ptr );
77+
78+ cl_git_pass (git_config_set_string (cfg , "core.abbrev" , "99" ));
79+ cl_git_pass (git_object_short_id (& shorty , obj ));
80+ cl_assert_equal_i (40 , shorty .size );
81+ cl_assert_equal_s ("ce013625030ba8dba906f756967f9e9ca394464a" , shorty .ptr );
82+
83+ cl_git_pass (git_config_set_string (cfg , "core.abbrev" , "4" ));
84+ cl_git_pass (git_object_short_id (& shorty , obj ));
85+ cl_assert_equal_i (4 , shorty .size );
86+ cl_assert_equal_s ("ce01" , shorty .ptr );
87+
88+ cl_git_pass (git_config_set_string (cfg , "core.abbrev" , "0" ));
89+ cl_git_fail (git_object_short_id (& shorty , obj ));
90+ cl_git_pass (git_config_set_string (cfg , "core.abbrev" , "3" ));
91+ cl_git_fail (git_object_short_id (& shorty , obj ));
92+ cl_git_pass (git_config_set_string (cfg , "core.abbrev" , "invalid" ));
93+ cl_git_fail (git_object_short_id (& shorty , obj ));
94+ cl_git_pass (git_config_set_string (cfg , "core.abbrev" , "true" ));
95+ cl_git_fail (git_object_short_id (& shorty , obj ));
96+
97+ git_object_free (obj );
98+ git_buf_dispose (& shorty );
99+ git_config_free (cfg );
100+ }
0 commit comments