Skip to content

Commit c8f5a5a

Browse files
committed
Fix dockerignore handling of absolute path exceptions.
Signed-off-by: mefyl <[email protected]>
1 parent 181c1c8 commit c8f5a5a

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

docker/utils/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def exclude_paths(root, patterns, dockerfile=None):
2626
if dockerfile is None:
2727
dockerfile = 'Dockerfile'
2828

29-
patterns = [p.lstrip('/') for p in patterns]
3029
exceptions = [p for p in patterns if p.startswith('!')]
3130

32-
include_patterns = [p[1:] for p in exceptions]
31+
include_patterns = [p[1:].lstrip('/') for p in exceptions]
3332
include_patterns += [dockerfile, '.dockerignore']
3433

35-
exclude_patterns = list(set(patterns) - set(exceptions))
34+
exclude_patterns = [
35+
p.lstrip('/') for p in list(set(patterns) - set(exceptions))]
3636

3737
paths = get_paths(root, exclude_patterns, include_patterns,
3838
has_exceptions=len(exceptions) > 0)

tests/unit/utils_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,13 @@ def test_single_subdir_single_filename_leading_slash(self):
758758
self.all_paths - set(['foo/a.py'])
759759
)
760760

761+
def test_exclude_include_absolute_path(self):
762+
base = make_tree([], ['a.py', 'b.py'])
763+
assert exclude_paths(
764+
base,
765+
['/*', '!/*.py']
766+
) == set(['a.py', 'b.py'])
767+
761768
def test_single_subdir_with_path_traversal(self):
762769
assert self.exclude(['foo/whoops/../a.py']) == convert_paths(
763770
self.all_paths - set(['foo/a.py'])

0 commit comments

Comments
 (0)