Skip to content

Commit 6259bfc

Browse files
authored
Merge pull request #205 from AKSW/feature/stayOnCurrentBranchAfterCommit
Stay on current branch after commit
2 parents 8adb1df + 71f3a24 commit 6259bfc

File tree

4 files changed

+59
-3
lines changed

4 files changed

+59
-3
lines changed

quit/core.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,6 @@ def commit(self, graph, delta, message, parent_commit_ref, target_ref, query=Non
490490
if oid:
491491
self._commits.set(oid.hex, blobs_new)
492492
commit = self.repository.revision(oid.hex)
493-
if not self.repository.is_bare:
494-
self.repository._repository.checkout(
495-
target_ref, strategy=pygit2.GIT_CHECKOUT_FORCE)
496493
self.syncSingle(commit)
497494

498495
return oid.hex

quit/git.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,17 @@ def commit(self, message, author_name, author_email, **kwargs):
667667
oid = tree.write()
668668
self.dirty = True
669669

670+
branch = re.sub("refs/heads/", "", ref)
671+
if not self.repository.is_bare and (branch == self.repository.current_head or
672+
self.repository.current_head is None):
673+
try:
674+
tree = self.repository._repository.get(oid)
675+
self.repository._repository.checkout_tree(tree)
676+
except pygit2.GitError as e:
677+
logger.info("Local changes in working directory of currently checked out branch: "
678+
"{}, {}".format(branch, e))
679+
pass
680+
670681
return self.repository._repository.create_commit(
671682
ref, author, commiter, message, oid, parents
672683
)

tests/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def _addAll(index, path, dir=''):
2222
index = repository.index
2323
index.read()
2424
_addAll(index, repository.workdir)
25+
index.write()
2526

2627
# Create commit
2728
tree = index.write_tree()

tests/test_app.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,53 @@ def testInsertDataAndSelectFromNonEmptyGraph(self):
19301930
"p": {'type': 'uri', 'value': 'http://ex.org/b'},
19311931
"o": {'type': 'uri', 'value': 'http://ex.org/c'}})
19321932

1933+
def testInsertDataIntoRepositoryDontOverwriteLocalFile(self):
1934+
"""Test inserting data wile locally changing the graph file.
1935+
1936+
1. Prepare a repository
1937+
2. Start Quit
1938+
3. execute INSERT DATA query
1939+
4. change file in filesystem
1940+
"""
1941+
# Prepate a git Repository
1942+
graphContent = '<http://ex.org/x> <http://ex.org/y> <http://ex.org/z> .\n'
1943+
with TemporaryRepositoryFactory().withGraph("http://example.org/", graphContent) as repo:
1944+
1945+
# Start Quit
1946+
args = quitApp.parseArgs(['-t', repo.workdir])
1947+
objects = quitApp.initialize(args)
1948+
config = objects['config']
1949+
app = create_app(config).test_client()
1950+
1951+
with open(path.join(repo.workdir, "graph.nt"), "w") as graphFile:
1952+
graphContent += '<http://ex.org/z> <http://ex.org/z> <http://ex.org/z> .\n'
1953+
graphFile.write(graphContent)
1954+
1955+
# execute INSERT DATA query
1956+
update = "INSERT DATA {graph <http://example.org/> {<http://ex.org/a> <http://ex.org/b> <http://ex.org/c> .}}"
1957+
app.post('/sparql', data=dict(update=update))
1958+
1959+
# execute SELECT query
1960+
select = "SELECT * WHERE {graph <http://example.org/> {?s ?p ?o .}} ORDER BY ?s ?p ?o"
1961+
select_resp = app.post('/sparql', data=dict(query=select), headers=dict(accept="application/sparql-results+json"))
1962+
1963+
obj = json.loads(select_resp.data.decode("utf-8"))
1964+
1965+
self.assertEqual(len(obj["results"]["bindings"]), 2)
1966+
1967+
self.assertDictEqual(obj["results"]["bindings"][0], {
1968+
"s": {'type': 'uri', 'value': 'http://ex.org/a'},
1969+
"p": {'type': 'uri', 'value': 'http://ex.org/b'},
1970+
"o": {'type': 'uri', 'value': 'http://ex.org/c'}})
1971+
1972+
self.assertDictEqual(obj["results"]["bindings"][1], {
1973+
"s": {'type': 'uri', 'value': 'http://ex.org/x'},
1974+
"p": {'type': 'uri', 'value': 'http://ex.org/y'},
1975+
"o": {'type': 'uri', 'value': 'http://ex.org/z'}})
1976+
1977+
with open(path.join(repo.workdir, "graph.nt"), "r") as graphFile:
1978+
self.assertEqual(graphFile.read(), graphContent)
1979+
19331980
def testInsertDeleteFromEmptyGraph(self):
19341981
"""Test inserting and deleting data and selecting it, starting with an empty graph.
19351982

0 commit comments

Comments
 (0)