Skip to content

Commit

Permalink
Merge pull request #205 from AKSW/feature/stayOnCurrentBranchAfterCommit
Browse files Browse the repository at this point in the history
Stay on current branch after commit
  • Loading branch information
splattater authored Nov 26, 2018
2 parents 8adb1df + 71f3a24 commit 6259bfc
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
3 changes: 0 additions & 3 deletions quit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,6 @@ def commit(self, graph, delta, message, parent_commit_ref, target_ref, query=Non
if oid:
self._commits.set(oid.hex, blobs_new)
commit = self.repository.revision(oid.hex)
if not self.repository.is_bare:
self.repository._repository.checkout(
target_ref, strategy=pygit2.GIT_CHECKOUT_FORCE)
self.syncSingle(commit)

return oid.hex
Expand Down
11 changes: 11 additions & 0 deletions quit/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,17 @@ def commit(self, message, author_name, author_email, **kwargs):
oid = tree.write()
self.dirty = True

branch = re.sub("refs/heads/", "", ref)
if not self.repository.is_bare and (branch == self.repository.current_head or
self.repository.current_head is None):
try:
tree = self.repository._repository.get(oid)
self.repository._repository.checkout_tree(tree)
except pygit2.GitError as e:
logger.info("Local changes in working directory of currently checked out branch: "
"{}, {}".format(branch, e))
pass

return self.repository._repository.create_commit(
ref, author, commiter, message, oid, parents
)
Expand Down
1 change: 1 addition & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def _addAll(index, path, dir=''):
index = repository.index
index.read()
_addAll(index, repository.workdir)
index.write()

# Create commit
tree = index.write_tree()
Expand Down
47 changes: 47 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,53 @@ def testInsertDataAndSelectFromNonEmptyGraph(self):
"p": {'type': 'uri', 'value': 'http://ex.org/b'},
"o": {'type': 'uri', 'value': 'http://ex.org/c'}})

def testInsertDataIntoRepositoryDontOverwriteLocalFile(self):
"""Test inserting data wile locally changing the graph file.
1. Prepare a repository
2. Start Quit
3. execute INSERT DATA query
4. change file in filesystem
"""
# Prepate a git Repository
graphContent = '<http://ex.org/x> <http://ex.org/y> <http://ex.org/z> .\n'
with TemporaryRepositoryFactory().withGraph("http://example.org/", graphContent) as repo:

# Start Quit
args = quitApp.parseArgs(['-t', repo.workdir])
objects = quitApp.initialize(args)
config = objects['config']
app = create_app(config).test_client()

with open(path.join(repo.workdir, "graph.nt"), "w") as graphFile:
graphContent += '<http://ex.org/z> <http://ex.org/z> <http://ex.org/z> .\n'
graphFile.write(graphContent)

# execute INSERT DATA query
update = "INSERT DATA {graph <http://example.org/> {<http://ex.org/a> <http://ex.org/b> <http://ex.org/c> .}}"
app.post('/sparql', data=dict(update=update))

# execute SELECT query
select = "SELECT * WHERE {graph <http://example.org/> {?s ?p ?o .}} ORDER BY ?s ?p ?o"
select_resp = app.post('/sparql', data=dict(query=select), headers=dict(accept="application/sparql-results+json"))

obj = json.loads(select_resp.data.decode("utf-8"))

self.assertEqual(len(obj["results"]["bindings"]), 2)

self.assertDictEqual(obj["results"]["bindings"][0], {
"s": {'type': 'uri', 'value': 'http://ex.org/a'},
"p": {'type': 'uri', 'value': 'http://ex.org/b'},
"o": {'type': 'uri', 'value': 'http://ex.org/c'}})

self.assertDictEqual(obj["results"]["bindings"][1], {
"s": {'type': 'uri', 'value': 'http://ex.org/x'},
"p": {'type': 'uri', 'value': 'http://ex.org/y'},
"o": {'type': 'uri', 'value': 'http://ex.org/z'}})

with open(path.join(repo.workdir, "graph.nt"), "r") as graphFile:
self.assertEqual(graphFile.read(), graphContent)

def testInsertDeleteFromEmptyGraph(self):
"""Test inserting and deleting data and selecting it, starting with an empty graph.
Expand Down

0 comments on commit 6259bfc

Please sign in to comment.