Skip to content

Commit

Permalink
Prevent clean files from showing up as untracked
Browse files Browse the repository at this point in the history
Looking at the code in porcelain.path_to_tree_path,
this looks like there was an attempt at this in
85b5383, however
relpath is non-destructive, and has no effect unless
the result is assigned to something. If this were
assigned when path is relative, then relpath would
assume path was at root, and so we must check that
the path is absolute before calling relpath.

Fixes jelmer#598
  • Loading branch information
alistair-broomhead committed Jan 6, 2018
1 parent 134c28a commit 5a577ec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
5 changes: 3 additions & 2 deletions dulwich/porcelain.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ def open_repo_closing(path_or_repo):
def path_to_tree_path(repopath, path):
"""Convert a path to a path usable in e.g. an index.
:param repo: Repository
:param repopath: Repository
:param path: A path
:return: A path formatted for use in e.g. an index
"""
os.path.relpath(path, repopath)
if os.path.isabs(path):
path = os.path.relpath(path, repopath)
if os.path.sep != '/':
path = path.replace(os.path.sep, '/')
return path.encode(sys.getfilesystemencoding())
Expand Down
39 changes: 32 additions & 7 deletions dulwich/tests/test_porcelain.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,17 +796,27 @@ def test_empty(self):
results.staged)
self.assertEqual([], results.unstaged)

def test_status(self):
"""Integration test for `status` functionality."""
def commit_file(self, name, content='original', author=b'', committer=b''):
fullpath = os.path.join(self.repo.path, name)

# Commit a dummy file then modify it
fullpath = os.path.join(self.repo.path, 'foo')
with open(fullpath, 'w') as f:
f.write('origstuff')
f.write(content)

porcelain.add(repo=self.repo.path, paths=[fullpath])
porcelain.commit(repo=self.repo.path, message=b'test status',
author=b'', committer=b'')
porcelain.commit(
repo=self.repo.path,
message=u'Add {}'.format(name).encode('utf-8'),
author=author,
committer=committer,
)

return fullpath

def test_status(self):
"""Integration test for `status` functionality."""

# Commit a dummy file then modify it
fullpath = self.commit_file('foo')

# modify access and modify time of path
os.utime(fullpath, (0, 0))
Expand All @@ -827,6 +837,21 @@ def test_status(self):
filename_add.encode('ascii'))
self.assertEqual(results.unstaged, [b'foo'])

def test_status_clean(self):
"""Integration test for `status` functionality."""

self.commit_file('foo')

results = porcelain.status(self.repo)

self.assertEqual(results.staged, {
'add': [],
'delete': [],
'modify': [],
})
self.assertEqual(results.unstaged, [])
self.assertEqual(results.untracked, [])

def test_get_tree_changes_add(self):
"""Unit test for get_tree_changes add."""

Expand Down

0 comments on commit 5a577ec

Please sign in to comment.