|
@@ -130,17 +130,13 @@ class CommitTests(PorcelainTestCase):
|
|
|
|
|
|
|
|
|
class CleanTests(PorcelainTestCase):
|
|
|
- def path_in_wd(self, name):
|
|
|
- """Get path of file in wd
|
|
|
- """
|
|
|
- return os.path.join(self.repo.path, name)
|
|
|
|
|
|
def put_files(self, tracked, ignored, untracked, empty_dirs):
|
|
|
"""Put the described files in the wd
|
|
|
"""
|
|
|
all_files = tracked | ignored | untracked
|
|
|
for file_path in all_files:
|
|
|
- abs_path = self.path_in_wd(file_path)
|
|
|
+ abs_path = os.path.join(self.repo.path, file_path)
|
|
|
# File may need to be written in a dir that doesn't exist yet, so
|
|
|
# create the parent dir(s) as necessary
|
|
|
parent_dir = os.path.dirname(abs_path)
|
|
@@ -152,40 +148,28 @@ class CleanTests(PorcelainTestCase):
|
|
|
with open(abs_path, 'w') as f:
|
|
|
f.write('')
|
|
|
|
|
|
- with open(self.path_in_wd('.gitignore'), 'w') as f:
|
|
|
+ with open(os.path.join(self.repo.path, '.gitignore'), 'w') as f:
|
|
|
f.writelines(ignored)
|
|
|
|
|
|
for dir_path in empty_dirs:
|
|
|
- os.mkdir(self.path_in_wd('empty_dir'))
|
|
|
+ os.mkdir(os.path.join(self.repo.path, 'empty_dir'))
|
|
|
|
|
|
- files_to_add = [self.path_in_wd(t) for t in tracked]
|
|
|
+ files_to_add = [os.path.join(self.repo.path, t) for t in tracked]
|
|
|
porcelain.add(repo=self.repo.path, paths=files_to_add)
|
|
|
porcelain.commit(repo=self.repo.path, message="init commit")
|
|
|
|
|
|
- def clean(self, target_dir):
|
|
|
- """Clean the target_dir and assert control dir unchanged
|
|
|
- """
|
|
|
- controldir = self.repo._controldir
|
|
|
-
|
|
|
- controldir_before = set(flat_walk_dir(controldir))
|
|
|
- porcelain.clean(repo=self.repo.path, target_dir=target_dir)
|
|
|
- controldir_after = set(flat_walk_dir(controldir))
|
|
|
-
|
|
|
- self.assertEqual(controldir_after, controldir_before)
|
|
|
-
|
|
|
def assert_wd(self, expected_paths):
|
|
|
"""Assert paths of files and dirs in wd are same as expected_paths
|
|
|
"""
|
|
|
- control_dir = self.repo._controldir
|
|
|
- control_dir_rel = os.path.relpath(control_dir, self.repo.path)
|
|
|
+ control_dir_rel = os.path.relpath(
|
|
|
+ self.repo._controldir, self.repo.path)
|
|
|
|
|
|
# normalize paths to simplify comparison across platforms
|
|
|
- from os.path import normpath
|
|
|
found_paths = {
|
|
|
- normpath(p)
|
|
|
+ os.path.normpath(p)
|
|
|
for p in flat_walk_dir(self.repo.path)
|
|
|
if not p.split(os.sep)[0] == control_dir_rel}
|
|
|
- norm_expected_paths = {normpath(p) for p in expected_paths}
|
|
|
+ norm_expected_paths = {os.path.normpath(p) for p in expected_paths}
|
|
|
self.assertEqual(found_paths, norm_expected_paths)
|
|
|
|
|
|
def test_from_root(self):
|
|
@@ -203,7 +187,7 @@ class CleanTests(PorcelainTestCase):
|
|
|
empty_dirs={
|
|
|
'empty_dir'})
|
|
|
|
|
|
- self.clean(self.repo.path)
|
|
|
+ porcelain.clean(repo=self.repo.path, target_dir=self.repo.path)
|
|
|
|
|
|
self.assert_wd({
|
|
|
'tracked_file',
|
|
@@ -227,8 +211,9 @@ class CleanTests(PorcelainTestCase):
|
|
|
empty_dirs={
|
|
|
'empty_dir'})
|
|
|
|
|
|
- target_dir = self.path_in_wd('untracked_dir')
|
|
|
- self.clean(target_dir)
|
|
|
+ porcelain.clean(
|
|
|
+ repo=self.repo,
|
|
|
+ target_dir=os.path.join(self.repo.path, 'untracked_dir'))
|
|
|
|
|
|
self.assert_wd({
|
|
|
'tracked_file',
|