@@ -40,3 +40,55 @@ func TestCreateCommitFromIds(t *testing.T) {
4040 t .Errorf ("mismatched commit ids, expected %v, got %v" , expectedCommitId .String (), commitId .String ())
4141 }
4242}
43+
44+ func TestRepositorySetConfig (t * testing.T ) {
45+ repo := createTestRepo (t )
46+ defer cleanupTestRepo (t , repo )
47+
48+ loc , err := time .LoadLocation ("Europe/Berlin" )
49+ checkFatal (t , err )
50+ sig := & Signature {
51+ Name : "Rand Om Hacker" ,
52+ Email : "random@hacker.com" ,
53+ When : time .Date (2013 , 03 , 06 , 14 , 30 , 0 , 0 , loc ),
54+ }
55+
56+ idx , err := repo .Index ()
57+ checkFatal (t , err )
58+ err = idx .AddByPath ("README" )
59+
60+ treeId , err := idx .WriteTree ()
61+ checkFatal (t , err )
62+
63+ message := "This is a commit\n "
64+ tree , err := repo .LookupTree (treeId )
65+ checkFatal (t , err )
66+ _ , err = repo .CreateCommit ("HEAD" , sig , sig , message , tree )
67+ checkFatal (t , err )
68+
69+ repoConfig , err := repo .Config ()
70+ checkFatal (t , err )
71+
72+ temp := Config {}
73+ localConfig , err := temp .OpenLevel (repoConfig , ConfigLevelLocal )
74+ checkFatal (t , err )
75+ repoConfig = nil
76+
77+ err = repo .SetConfig (localConfig )
78+ checkFatal (t , err )
79+
80+ configFieldName := "core.filemode"
81+ err = localConfig .SetBool (configFieldName , true )
82+ checkFatal (t , err )
83+
84+ localConfig = nil
85+
86+ repoConfig , err = repo .Config ()
87+ checkFatal (t , err )
88+
89+ result , err := repoConfig .LookupBool (configFieldName )
90+ checkFatal (t , err )
91+ if result != true {
92+ t .Fatal ("result must be true" )
93+ }
94+ }
0 commit comments