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

[FEATURE] Add walks from cwd and not repo root #638

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

[FEATURE] Add walks from cwd and not repo root #638

wants to merge 1 commit into from

Conversation

r0mainK
Copy link
Contributor

@r0mainK r0mainK commented Jun 25, 2018

This might not be a fix but an implementation choice, but given the change is simple I thought I'd open a PR and see what happens.

CONTEXT
Currently when using add and not passing any paths to add, we walk though the current working directory instead of the repo root. This means that we are basically doing a git add ., assuming that the current working directory is in the repo, thus requiring to change the working directory if we are not located in it. It also means if we are using dulwich as an API in another git repo, let's say A, to modify B, then we will walk through A instead of our target B, even if the repo argu point to B.

CHANGES

I think one of three two can and should be done:

  1. If you think it is best to keep this behavior, I think adding an optional all argument to walk through the repo root would be useful, and better then forcing the user to switch working directory.
  2. If you think that the logical thing would be to default to all, as the current doc implies, then switching os.getcwd() to r.path like I did does the trick.

@r0mainK r0mainK changed the title [FEATURE] Add walks from cwd and not repo root [FIX] Add walks from cwd and not repo root Jun 25, 2018
@jelmer
Copy link
Owner

jelmer commented Jun 25, 2018

In general, "dulwich.porcelain.X" should work like the "git X" command, including behaviour around os.getcwd(). Users that don't want to change the cwd can specify absolute paths.

Obviously there are some exceptions to this, e.g. allowing richer data types for inputs/outputs.

Adding an "all" argument and not defaulting to adding everything seems reasonable to me.

@r0mainK r0mainK changed the title [FIX] Add walks from cwd and not repo root [FEATURE] Add walks from cwd and not repo root Jun 26, 2018
@r0mainK
Copy link
Contributor Author

r0mainK commented Jun 26, 2018

Okay, so gonna add this functionality. Now if paths is not specified add will act like git add . whereas if all is specified it will act as git add --all. Tests are still pending bbut this should be ready for review by noon.

@@ -57,7 +57,8 @@ class PorcelainTestCase(TestCase):

def setUp(self):
super(PorcelainTestCase, self).setUp()
self.test_dir = tempfile.mkdtemp()
self.test_dir = "/Users/romain/tests_dulwich"
Copy link
Owner

Choose a reason for hiding this comment

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

This is what's breaking the tests on travis. It doesn't have a directory called /Users/romain ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aha my bad, i got my tmp dir symlinked to /private/tmp so I switched to this, or tests failed :p but wan't talking about that, before there was a bug were python2.7 and pypy failed but other succeeded

Copy link
Contributor Author

Choose a reason for hiding this comment

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

get_untracked_paths(os.getcwd(), r.path, r.open_index()))
relpaths = []
if not isinstance(paths, list):
paths = [paths]
for p in paths:
relpath = os.path.relpath(p, r.path)
if all:
Copy link
Owner

Choose a reason for hiding this comment

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

What is this trying to do? I don't understand why further manipulation is needed if all is set here.

@@ -58,6 +58,7 @@ class PorcelainTestCase(TestCase):
def setUp(self):
super(PorcelainTestCase, self).setUp()
self.test_dir = tempfile.mkdtemp()
os.mkdir(self.test_dir)
Copy link
Owner

Choose a reason for hiding this comment

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

This is unnecessary, tempfile.mkdtemp already creates the directory.

porcelain.commit(repo=self.repo.path, message=b'test',
author=b'test <email>',
committer=b'test <email>')
finally:
Copy link
Owner

Choose a reason for hiding this comment

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

Verify that the right files were added to the index?

with open(os.path.join(self.repo.path, 'foo', 'blie'), 'w') as f:
f.write("\n")

porcelain.add(repo=self.repo.path, all=True,
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't this verify that the changes to a file are also added if one of the files existed before?

@r0mainK r0mainK closed this Jul 3, 2018
Signed-off-by: Romain Keramitas <r.keramitas@gmail.com>
@r0mainK r0mainK reopened this Jul 3, 2018
@vmarkovtsev
Copy link

@r0mainK ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants