Description
When the verify-copy
right hook is not provided a target branch via command-line flags or environment variables, and when it finds a branch-{YY}.{MM}
one locally, it currently applies the following procedure to find the commit to compare to:
- determine the upstream branch the local
branch-{YY}.{MM}
is tracking
- target_commit = HEAD of that upstream branch
It should instead do this:
- determine the upstream branch the local
branch-{YY}.{MM}
is tracking
- determine the HEAD of that upstream branch
- determine the HEAD of the local branch
- target_commit = whichever of those commits is newest
Benefits of this work
- reduces the risk of CI and local
pre-commit
disagreeing as a result of your fork being out of date with the upstream repo
Acceptance Criteria
- when the target branch is not supplied via command line args or environment variables, and when the commit ID on the local copy of the target branch is different from the one on the upstream branch it's tracking, the newer of the 2 commits should be used as the reference to decide what files have changed
Approach
Modify the implementation of get_target_branch_upstream_commit()
to accomplish this:
|
def get_target_branch_upstream_commit(repo, args): |
Notes
The verify-copyright
hook only modifies copyright headers for files that it considers to have "changed".
"changed" in that hooks definition means "the file content is different between HEAD wherever the hook is being run and the latest commit on the target branch".
"target branch" can be passed to the hook via environment variables or command-line flags, as described here:
|
The target branch is determined in the following order: |
When none of those methods are used, the hook tries to determine the target branch and its latest commit by inspecting the git
repo it's being run from and looking for branches that follow the RAPIDS conventions like branch-{YY}.{MM}
.
This logic says "take the latest branch-{YY}.{MM}
locally, and get the commit ID of the the latest commit on the upstream branch it's tracking".
|
if target_branch: |
|
target_branch_upstream = target_branch.tracking_branch() |
|
if target_branch_upstream: |
|
return target_branch_upstream.commit |
References
Created based on discussions about this: rapidsai/rmm#1564 (comment)