44from glob import glob
55from os import remove
66from os .path import join , isdir
7+ import pygit2
78from pygit2 import init_repository , Repository , clone_repository
89from pygit2 import GIT_SORT_TOPOLOGICAL , GIT_SORT_REVERSE , Signature
910from quit .conf import QuitStoreConfiguration , QuitGraphConfiguration
1415from tempfile import TemporaryDirectory , NamedTemporaryFile
1516import rdflib
1617
18+ try :
19+ DEFAULT_BRANCH = pygit2 .Config .get_global_config ()['init.defaultBranch' ]
20+ except KeyError :
21+ DEFAULT_BRANCH = 'master'
1722
1823class TestConfiguration (unittest .TestCase ):
1924 ns = 'http://quit.instance/'
@@ -68,8 +73,9 @@ def testExistingRepoGraphFiles(self):
6873 content2 += '<urn:a> <urn:b> <urn:c> .\n '
6974 repoContent = {'http://example.org/' : content1 , 'http://aksw.org/' : content2 }
7075 with TemporaryRepositoryFactory ().withGraphs (repoContent ) as repo :
76+ current_head = repo .head .shorthand
7177 conf = QuitGraphConfiguration (repository = repo )
72- conf .initgraphconfig ('master' )
78+ conf .initgraphconfig (current_head )
7379 self .assertEqual (conf .mode , 'graphfiles' )
7480
7581 graphs = conf .getgraphs ()
@@ -103,8 +109,9 @@ def testExistingRepoWithErroneousGraphFiles(self):
103109 content3 = '<urn:a> <urn:b> <urn:c> .'
104110 repoContent = {'no uri' : content1 , 'http://aksw.org/' : content2 , '' : content3 }
105111 with TemporaryRepositoryFactory ().withGraphs (repoContent ) as repo :
112+ current_head = repo .head .shorthand
106113 conf = QuitGraphConfiguration (repository = repo )
107- conf .initgraphconfig ('master' )
114+ conf .initgraphconfig (current_head )
108115 self .assertEqual (conf .mode , 'graphfiles' )
109116
110117 graphs = conf .getgraphs ()
@@ -116,6 +123,7 @@ def testExistingRepoWithErroneousGraphFiles(self):
116123
117124 serialization = conf .getserializationoffile ('graph_1.nt' )
118125 self .assertEqual (serialization , 'nt' )
126+ current_head = repo .head .shorthand
119127
120128 gfMap = conf .getgraphurifilemap ()
121129
@@ -132,8 +140,9 @@ def testExistingRepoConfigfile(self):
132140 content2 += '<urn:a> <urn:b> <urn:c> .'
133141 repoContent = {'http://example.org/' : content1 , 'http://aksw.org/' : content2 }
134142 with TemporaryRepositoryFactory ().withGraphs (repoContent , 'configfile' ) as repo :
143+ current_head = repo .head .shorthand
135144 conf = QuitGraphConfiguration (repository = repo )
136- conf .initgraphconfig ('master' )
145+ conf .initgraphconfig (current_head )
137146 self .assertEqual (conf .mode , 'configuration' )
138147
139148 graphs = conf .getgraphs ()
@@ -164,8 +173,9 @@ def testGraphConfigurationMethods(self):
164173 content2 += '<urn:a> <urn:b> <urn:c> .'
165174 repoContent = {'http://example.org/' : content1 , 'http://aksw.org/' : content2 }
166175 with TemporaryRepositoryFactory ().withGraphs (repoContent , 'configfile' ) as repo :
176+ current_head = repo .head .shorthand
167177 conf = QuitGraphConfiguration (repository = repo )
168- conf .initgraphconfig ('master' )
178+ conf .initgraphconfig (current_head )
169179
170180 conf .removegraph ('http://aksw.org/' )
171181
@@ -186,18 +196,20 @@ def testGraphConfigurationMethods(self):
186196
187197 def testGraphConfigurationFailing (self ):
188198 with TemporaryRepositoryFactory ().withBothConfigurations () as repo :
199+ current_head = repo .head .shorthand
189200 conf = QuitGraphConfiguration (repository = repo )
190- self .assertRaises (InvalidConfigurationError , conf .initgraphconfig , 'master' )
201+ self .assertRaises (InvalidConfigurationError , conf .initgraphconfig , current_head )
191202
192203 def testWrongConfigurationFile (self ):
193204 with TemporaryRepositoryFactory ().withBothConfigurations () as repo :
205+ current_head = repo .head .shorthand
194206 conf = QuitGraphConfiguration (repository = repo )
195- self .assertRaises (InvalidConfigurationError , conf .initgraphconfig , 'master' )
207+ self .assertRaises (InvalidConfigurationError , conf .initgraphconfig , current_head )
196208
197209 def testNoConfigInformation (self ):
198210 with TemporaryRepositoryFactory ().withNoConfigInformation () as repo :
199211 conf = QuitGraphConfiguration (repository = repo )
200- conf .initgraphconfig ('master' )
212+ conf .initgraphconfig (DEFAULT_BRANCH )
201213 self .assertEqual (conf .mode , 'graphfiles' )
202214
203215
0 commit comments