Commits

Victor Garcia committed 44d3257

Fix broken no-common-prefix detection.

Comments (0)

Files changed (2)

bitbucket_hook/hook.py

 """
 
 def getpaths(files, listfiles=False):
+
+    # Handle empty input
     if not files:
         return '', ''
+    files = [f['file'] for f in files]
+    if not any(files):
+        return '', ''
 
     dirname = os.path.dirname
     basename = os.path.basename
-    files = [f['file'] for f in files]
-
-    if not any(files):
-        return '', ''
 
     common_prefix = [dirname(f) for f in files]
 
         common_prefix = files[0]
         listfiles = False
 
-    elif not common_prefix or len(common_prefix) == len(set(common_prefix)):
-        common_prefix = ''
-
     else:
-        common_prefix = os.path.commonprefix(common_prefix)
+        common_prefix = [path.split(os.sep) for path in common_prefix]
+        common_prefix = os.sep.join(os.path.commonprefix(common_prefix))
         if common_prefix and not common_prefix.endswith('/'):
             common_prefix += '/'
 

bitbucket_hook/test/test_hook.py

     pypydoubleslash = [d(file='pypy/jit/metainterp/opt/u.py'),
                        d(file='pypy/jit/metainterp/test/test_c.py'),
                        d(file='pypy/jit/metainterp/test/test_o.py')]
+
+    pypyempty = [d(file='pypy/rlib/rdtoa.py'),
+                 d(file='pypy/rlib/test/test_rdtoa.py')]
+
     nothing = ('', '')
+
+    # (input, expected output) for listfiles=False
     files_expected = [([], nothing),
                       ([empty], nothing),
                       ([empty, empty], nothing),
                       (nocommonplusslash, nothing),
                       (commonplusslash, ('path/', '')),
                       (pypydoubleslash, ('pypy/jit/metainterp/', '')),
+                      (pypyempty, ('pypy/rlib/', '')),
                       ]
 
     for f, wanted in files_expected:
         assert getpaths(f) == wanted
 
+    # (input, expected output) for listfiles=True
     files_expected = [([], nothing),
                       ([empty], nothing),
                       ([empty, empty], nothing),
                       (commonplusslash, ('path/',' M(file1, file2, file)')),
                       (pypydoubleslash, ('pypy/jit/metainterp/',
                                          ' M(u.py, test_c.py, test_o.py)')),
+                      (pypyempty, ('pypy/rlib/',
+                                   ' M(rdtoa.py, test_rdtoa.py)')),
                       ]
 
     for f, wanted in files_expected: