Skip to content

Commit

Permalink
In dulwich.porcelain.add, if no files are specified,
Browse files Browse the repository at this point in the history
add from current working directory rather than repository root.
Closes #521
  • Loading branch information
jelmer committed Jun 20, 2017
1 parent 2f2ae37 commit c4eaba1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions NEWS
Expand Up @@ -10,6 +10,10 @@
* Pass 'mkdir' argument onto Repo.init_bare in Repo.clone.
(Jelmer Vernooij, #504)

* In ``dulwich.porcelain.add``, if no files are specified,
add from current working directory rather than repository root.
(Jelmer Vernooij, #521)

DOCUMENTATION

* Clarified docstrings for Client.{send_pack,fetch_pack} implementations.
Expand Down
2 changes: 1 addition & 1 deletion dulwich/porcelain.py
Expand Up @@ -317,7 +317,7 @@ def add(repo=".", paths=None):
if not paths:
# If nothing is specified, add all non-ignored files.
paths = []
for dirpath, dirnames, filenames in os.walk(r.path):
for dirpath, dirnames, filenames in os.walk(os.getcwd()):
# Skip .git and below.
if '.git' in dirnames:
dirnames.remove('.git')
Expand Down
27 changes: 25 additions & 2 deletions dulwich/tests/test_porcelain.py
Expand Up @@ -224,7 +224,6 @@ def test_bare(self):
class AddTests(PorcelainTestCase):

def test_add_default_paths(self):

# create a file for initial commit
with open(os.path.join(self.repo.path, 'blah'), 'w') as f:
f.write("\n")
Expand All @@ -238,12 +237,36 @@ def test_add_default_paths(self):
os.mkdir(os.path.join(self.repo.path, 'adir'))
with open(os.path.join(self.repo.path, 'adir', 'afile'), 'w') as f:
f.write("\n")
porcelain.add(self.repo.path)
cwd = os.getcwd()
try:
os.chdir(self.repo.path)
porcelain.add(self.repo.path)
finally:
os.chdir(cwd)

# Check that foo was added and nothing in .git was modified
index = self.repo.open_index()
self.assertEqual(sorted(index), [b'adir/afile', b'blah', b'foo'])

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

cwd = os.getcwd()
try:
os.chdir(os.path.join(self.repo.path, 'foo'))
porcelain.add(repo=self.repo.path)
porcelain.commit(repo=self.repo.path, message=b'test',
author=b'test', committer=b'test')
finally:
os.chdir(cwd)

index = self.repo.open_index()
self.assertEqual(sorted(index), [b'foo/blie'])

def test_add_file(self):
with open(os.path.join(self.repo.path, 'foo'), 'w') as f:
f.write("BAR")
Expand Down

0 comments on commit c4eaba1

Please sign in to comment.