Skip to content

Commit 181c1c8

Browse files
committed
Revert "Correctly support absolute paths in .dockerignore"
This reverts commit 34d5048. Signed-off-by: mefyl <[email protected]>
1 parent ba0e533 commit 181c1c8

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

docker/utils/build.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def exclude_paths(root, patterns, dockerfile=None):
4646
)
4747

4848

49-
def should_include(path, exclude_patterns, include_patterns, root):
49+
def should_include(path, exclude_patterns, include_patterns):
5050
"""
5151
Given a path, a list of exclude patterns, and a list of inclusion patterns:
5252
@@ -61,15 +61,11 @@ def should_include(path, exclude_patterns, include_patterns, root):
6161
for pattern in include_patterns:
6262
if match_path(path, pattern):
6363
return True
64-
if os.path.isabs(pattern) and match_path(
65-
os.path.join(root, path), pattern):
66-
return True
6764
return False
6865
return True
6966

7067

71-
def should_check_directory(directory_path, exclude_patterns, include_patterns,
72-
root):
68+
def should_check_directory(directory_path, exclude_patterns, include_patterns):
7369
"""
7470
Given a directory path, a list of exclude patterns, and a list of inclusion
7571
patterns:
@@ -95,7 +91,7 @@ def normalize_path(path):
9591
if (pattern + '/').startswith(path_with_slash)
9692
]
9793
directory_included = should_include(
98-
directory_path, exclude_patterns, include_patterns, root
94+
directory_path, exclude_patterns, include_patterns
9995
)
10096
return directory_included or len(possible_child_patterns) > 0
10197

@@ -114,28 +110,26 @@ def get_paths(root, exclude_patterns, include_patterns, has_exceptions=False):
114110
# traversal. See https://docs.python.org/2/library/os.html#os.walk
115111
dirs[:] = [
116112
d for d in dirs if should_check_directory(
117-
os.path.join(parent, d), exclude_patterns, include_patterns,
118-
root
113+
os.path.join(parent, d), exclude_patterns, include_patterns
119114
)
120115
]
121116

122117
for path in dirs:
123118
if should_include(os.path.join(parent, path),
124-
exclude_patterns, include_patterns, root):
119+
exclude_patterns, include_patterns):
125120
paths.append(os.path.join(parent, path))
126121

127122
for path in files:
128123
if should_include(os.path.join(parent, path),
129-
exclude_patterns, include_patterns, root):
124+
exclude_patterns, include_patterns):
130125
paths.append(os.path.join(parent, path))
131126

132127
return paths
133128

134129

135130
def match_path(path, pattern):
136-
137131
pattern = pattern.rstrip('/' + os.path.sep)
138-
if pattern and not os.path.isabs(pattern):
132+
if pattern:
139133
pattern = os.path.relpath(pattern)
140134

141135
pattern_components = pattern.split(os.path.sep)

tests/unit/utils_test.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -876,13 +876,6 @@ def test_trailing_double_wildcard(self):
876876
)
877877
)
878878

879-
def test_exclude_include_absolute_path(self):
880-
base = make_tree([], ['a.py', 'b.py'])
881-
assert exclude_paths(
882-
base,
883-
['/*', '!' + os.path.join(base, '*.py')]
884-
) == set(['a.py', 'b.py'])
885-
886879

887880
class TarTest(unittest.TestCase):
888881
def test_tar_with_excludes(self):
@@ -1033,52 +1026,52 @@ class ShouldCheckDirectoryTest(unittest.TestCase):
10331026

10341027
def test_should_check_directory_not_excluded(self):
10351028
assert should_check_directory(
1036-
'not_excluded', self.exclude_patterns, self.include_patterns, '.'
1029+
'not_excluded', self.exclude_patterns, self.include_patterns
10371030
)
10381031
assert should_check_directory(
10391032
convert_path('dir/with'), self.exclude_patterns,
1040-
self.include_patterns, '.'
1033+
self.include_patterns
10411034
)
10421035

10431036
def test_shoud_check_parent_directories_of_excluded(self):
10441037
assert should_check_directory(
1045-
'dir', self.exclude_patterns, self.include_patterns, '.'
1038+
'dir', self.exclude_patterns, self.include_patterns
10461039
)
10471040
assert should_check_directory(
10481041
convert_path('dir/with'), self.exclude_patterns,
1049-
self.include_patterns, '.'
1042+
self.include_patterns
10501043
)
10511044

10521045
def test_should_not_check_excluded_directories_with_no_exceptions(self):
10531046
assert not should_check_directory(
10541047
'exclude_rather_large_directory', self.exclude_patterns,
1055-
self.include_patterns, '.'
1048+
self.include_patterns
10561049
)
10571050
assert not should_check_directory(
10581051
convert_path('dir/with/subdir_excluded'), self.exclude_patterns,
1059-
self.include_patterns, '.'
1052+
self.include_patterns
10601053
)
10611054

10621055
def test_should_check_excluded_directory_with_exceptions(self):
10631056
assert should_check_directory(
10641057
convert_path('dir/with/exceptions'), self.exclude_patterns,
1065-
self.include_patterns, '.'
1058+
self.include_patterns
10661059
)
10671060
assert should_check_directory(
10681061
convert_path('dir/with/exceptions/in'), self.exclude_patterns,
1069-
self.include_patterns, '.'
1062+
self.include_patterns
10701063
)
10711064

10721065
def test_should_not_check_siblings_of_exceptions(self):
10731066
assert not should_check_directory(
10741067
convert_path('dir/with/exceptions/but_not_here'),
1075-
self.exclude_patterns, self.include_patterns, '.'
1068+
self.exclude_patterns, self.include_patterns
10761069
)
10771070

10781071
def test_should_check_subdirectories_of_exceptions(self):
10791072
assert should_check_directory(
10801073
convert_path('dir/with/exceptions/like_this_one/subdir'),
1081-
self.exclude_patterns, self.include_patterns, '.'
1074+
self.exclude_patterns, self.include_patterns
10821075
)
10831076

10841077

0 commit comments

Comments
 (0)