aboutsummaryrefslogtreecommitdiffstats
path: root/python/tidy
diff options
context:
space:
mode:
authorSadman Kazi <sadman@sadmansk.com>2017-04-12 00:57:34 -0400
committerSadman Kazi <sadman@sadmansk.com>2017-04-13 15:57:36 -0400
commitcca3343c2e518f84e3d8b4e030af669367ab5e03 (patch)
treeefefc4d4af2f1a87f21e02970c378f33ced049bf /python/tidy
parentebc61bb2c3ac682ca366019b21160819ec3c7882 (diff)
downloadservo-cca3343c2e518f84e3d8b4e030af669367ab5e03.tar.gz
servo-cca3343c2e518f84e3d8b4e030af669367ab5e03.zip
Check for merge commits with tidy
Increase merge commit check range under travis Add comment on why travis workaround is necessary
Diffstat (limited to 'python/tidy')
-rw-r--r--python/tidy/servo_tidy/tidy.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/python/tidy/servo_tidy/tidy.py b/python/tidy/servo_tidy/tidy.py
index 36679cf9b1f..1468d00bf42 100644
--- a/python/tidy/servo_tidy/tidy.py
+++ b/python/tidy/servo_tidy/tidy.py
@@ -1052,16 +1052,29 @@ def run_lint_scripts(only_changed_files=False, progress=True, stylo=False):
def check_commits(path='.'):
+ """ Checks if the test is being run under Travis CI environment
+ This is necessary since, after travis clones the branch for a PR, it merges
+ the branch against master, creating a merge commit. Hence, as a workaround,
+ we have to check if the second last merge commit is done by the author of
+ the pull request.
+ """
+ is_travis = os.environ.get('TRAVIS') == 'true'
+ number_commits = '-n2' if is_travis else '-n1'
+
"""Gets all commits since the last merge."""
- args = ['git', 'log', '-n1', '--merges', '--format=%H']
- last_merge = subprocess.check_output(args, cwd=path).strip()
- args = ['git', 'log', '{}..HEAD'.format(last_merge), '--format=%s']
+ args = ['git', 'log', number_commits, '--merges', '--format=%H:%an']
+ # last_merge stores both the commit hash and the author name of the last merge in the output
+ last_merge_hash, last_merge_author = subprocess.check_output(args, cwd=path).strip().splitlines()[-1].split(':')
+ args = ['git', 'log', '{}..HEAD'.format(last_merge_hash), '--format=%s']
commits = subprocess.check_output(args, cwd=path).lower().splitlines()
for commit in commits:
# .split() to only match entire words
if 'wip' in commit.split():
- yield ('.', 0, 'no commits should contain WIP')
+ yield (':', ':', 'no commits should contain WIP')
+
+ if last_merge_author != 'bors-servo':
+ yield (':', ':', 'no merge commits allowed, please rebase your commits over the upstream master branch')
raise StopIteration