11
11
12
12
# options and validation
13
13
class Options
14
- attr_writer :git_dir , :branch , :token , :org , :repo , :dry_run , :checklist
14
+ attr_writer :git_dir , :branch , :head_commit , : token, :org , :repo , :dry_run , :checklist
15
15
16
16
# Use the supplied git dir, GIT_DIR from environment, find the .git directory
17
17
# in a parent directory recursively or fail out by using the current
@@ -35,6 +35,11 @@ def branch
35
35
b
36
36
end
37
37
38
+ def head_commit
39
+ # Fall back to 'HEAD' unless specified
40
+ @head_commit || 'HEAD'
41
+ end
42
+
38
43
def token
39
44
t = @token || ENV [ 'GITHUB_TOKEN' ]
40
45
raise "--token or GITHUB_TOKEN must be set" unless t
@@ -72,6 +77,11 @@ def checklist
72
77
"Which branch should we examine?"
73
78
) { |branch | options . branch = branch }
74
79
80
+ opts . on (
81
+ "-hc" , "--head-commit HEAD" , String ,
82
+ "Use a custom head commit. Useful if you merge other stuff in before running this check."
83
+ ) { |head_commit | options . head_commit = head_commit }
84
+
75
85
opts . on (
76
86
"-t" , "--token token" , String ,
77
87
"Github access token (default: ENV['GITHUB_TOKEN'])"
@@ -120,7 +130,10 @@ def checklist
120
130
# 3. We ask for `pr.head`, which is newer than `git.object('HEAD')`
121
131
#
122
132
# This race condition breaks commands that rely on `head` below
123
- head = git . object ( 'HEAD' ) . sha
133
+ #
134
+ # We also allow overriding the HEAD, since CI might change HEAD in a way that
135
+ # interferes with checks here. (e.g. merging in master before running CI)
136
+ head = git . object ( options . head_commit ) . sha
124
137
125
138
# Calculate the common ancestor where head diverged from pr.base, so the diff
126
139
# is of the unique changes in head and not the changes that have since merged
0 commit comments