summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormefyl <quentin.hocquet@docker.com>2018-02-16 11:22:29 +0100
committermefyl <quentin.hocquet@docker.com>2018-02-21 17:05:26 +0100
commitc8f5a5ad4040560ce62d53002ecec12485b531f7 (patch)
tree64507677c089ab457ac326158ab327e455930eec
parent181c1c8eb970ae11a707b6b6c3d1e4d546504ccf (diff)
downloaddocker-py-c8f5a5ad4040560ce62d53002ecec12485b531f7.tar.gz
Fix dockerignore handling of absolute path exceptions.
Signed-off-by: mefyl <quentin.hocquet@docker.com>
-rw-r--r--docker/utils/build.py6
-rw-r--r--tests/unit/utils_test.py7
2 files changed, 10 insertions, 3 deletions
diff --git a/docker/utils/build.py b/docker/utils/build.py
index d4223e7..e86a04e 100644
--- a/docker/utils/build.py
+++ b/docker/utils/build.py
@@ -26,13 +26,13 @@ def exclude_paths(root, patterns, dockerfile=None):
if dockerfile is None:
dockerfile = 'Dockerfile'
- patterns = [p.lstrip('/') for p in patterns]
exceptions = [p for p in patterns if p.startswith('!')]
- include_patterns = [p[1:] for p in exceptions]
+ include_patterns = [p[1:].lstrip('/') for p in exceptions]
include_patterns += [dockerfile, '.dockerignore']
- exclude_patterns = list(set(patterns) - set(exceptions))
+ exclude_patterns = [
+ p.lstrip('/') for p in list(set(patterns) - set(exceptions))]
paths = get_paths(root, exclude_patterns, include_patterns,
has_exceptions=len(exceptions) > 0)
diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py
index eedcf71..0ee041a 100644
--- a/tests/unit/utils_test.py
+++ b/tests/unit/utils_test.py
@@ -758,6 +758,13 @@ class ExcludePathsTest(unittest.TestCase):
self.all_paths - set(['foo/a.py'])
)
+ def test_exclude_include_absolute_path(self):
+ base = make_tree([], ['a.py', 'b.py'])
+ assert exclude_paths(
+ base,
+ ['/*', '!/*.py']
+ ) == set(['a.py', 'b.py'])
+
def test_single_subdir_with_path_traversal(self):
assert self.exclude(['foo/whoops/../a.py']) == convert_paths(
self.all_paths - set(['foo/a.py'])