Skip to content

Commit

Permalink
Add Repo.get_shallow.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Apr 16, 2018
1 parent c2da1ee commit 31e6508
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* Add `checkout` argument to `Repo.clone`.
(Jelmer Vernooij, #503)

* Add `Repo.get_shallow` method. (Jelmer Vernooij)

BUG FIXES

* Fix handling of encoding for tags. (Jelmer Vernooij, #608)
Expand Down
14 changes: 14 additions & 0 deletions dulwich/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,13 @@ def get_config_stack(self):
backends = [self.get_config()] + StackedConfig.default_backends()
return StackedConfig(backends, writable=backends[0])

def get_shallow(self):
"""Get the set of shallow commits.
:return: Set of shallow commits.
"""
return set()

def get_peeled(self, ref):
"""Get the peeled value of a ref.
Expand Down Expand Up @@ -907,6 +914,13 @@ def get_named_file(self, path, basedir=None):
return None
raise

def get_shallow(self):
f = self.get_named_file('shallow')
if f is None:
return set()
with f:
return set(l.strip() for l in f)

def index_path(self):
"""Return path to the index file."""
return os.path.join(self.controldir(), INDEX_FILENAME)
Expand Down
7 changes: 7 additions & 0 deletions dulwich/tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,13 @@ def setUp(self):
self.assertEqual([], r[commit_sha].parents)
self._root_commit = commit_sha

def test_shallow(self):
self.assertEqual(set(), self._repo.get_shallow())
with open(os.path.join(self._repo.path, '.git', 'shallow'), 'wb') as f:
f.write('a90fa2d900a17e99b433217e988c4eb4a2e9a097\n')
self.assertEqual({'a90fa2d900a17e99b433217e988c4eb4a2e9a097'},
self._repo.get_shallow())

def test_build_repo(self):
r = self._repo
self.assertEqual(b'ref: refs/heads/master', r.refs.read_ref(b'HEAD'))
Expand Down

0 comments on commit 31e6508

Please sign in to comment.