@@ -70,12 +70,12 @@ def main():
7070 logging .debug ("TRAVIS_PULL_REQUEST_SHA: %s" , TRAVIS_PULL_REQUEST_SHA )
7171 logging .debug ("TRAVIS_BRANCH: %s" , TRAVIS_BRANCH )
7272 logging .debug ("TRAVIS_REPO_SLUG: %s" , TRAVIS_REPO_SLUG )
73-
7473 changed = {}
7574 if args .diff :
7675 if TRAVIS and not TRAVIS_PULL_REQUEST :
7776 # FIXME: This shouldn't be needed, but not sure why TRAVIS is so special
7877 return
78+ check_depth ()
7979 changed = get_changed_lines ()
8080
8181 paths = filter_paths (args .path , changed , pwd )
@@ -376,5 +376,15 @@ def system(cmd):
376376 else :
377377 return subprocess .check_output (cmd , shell = True )
378378
379+ def check_depth ():
380+ if TRAVIS and TRAVIS_PULL_REQUEST_SHA :
381+ with open (os .devnull , 'w' ) as devnull :
382+ if subprocess .call (["git" , "merge-base" , TRAVIS_PULL_REQUEST_SHA , TRAVIS_BRANCH ], stdout = devnull ):
383+ # Current depth is not deep enough
384+ logging .debug (system (["git" , "fetch" , "--deepen" , "100" ]))
385+ if subprocess .call (["git" , "merge-base" , TRAVIS_PULL_REQUEST_SHA , TRAVIS_BRANCH ], stdout = devnull ):
386+ logging .error ("Can't find common base for comparison. Aborting" )
387+ sys .exit (1 )
388+
379389
380390main ()
0 commit comments