Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent clean files from showing up as untracked #601

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"path" will be relative to os.getcwd(), so I think we should unconditionally call relpath since path_to_tree_path should return the relative path to the repository.

Copy link
Contributor Author

@alistair-broomhead alistair-broomhead Jun 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it's been a few months so I can't quite remember, but when I was testing this it seemed like in some cases this function receives an absolute path. This was in fact responsible for #598 as it was seeing these clean files from the repo as not being the same as the files from the listing, and so did not think they were tracked. I'd need to look at what's happened in the code since January, but this was definitely a false assumption back then, and so needed testing in the code. It's also possible that the calling code is what's at fault, and that the fix belongs elsewhere. I have to admit I was somewhat surprised to see #600 accepted so quickly but this not, given the comparative levels of complexity and scope,

It looks like there may need to be some communication with @r0mainK from #635 as there are some functional changes here and some ruggedisation there, and it would be good to make sure that both of these are done without losing one or the other.

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