mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-22 01:59:26 +00:00
Improve determining the lines added by a branch
Since the list of lines added to Git-tracked text files in a given branch is not part of the Danger DSL [1], it is determined using custom code in dangerfile.py. The current implementation of that logic is less than perfect as it examines the diff between the current tip of the target branch and the source branch rather than the diff between the merge base of the two branches and the source branch. Consider a Git history like this: * F (target) ... * E * D * C | * B (source) |/ * A (merge base) If danger-python or Hazard are run for commit B, the current logic for determining the list of added lines in dangerfile.py examines the diff between commits F and B rather than between commits A and B. Therefore, the added_lines() function returns not just the lines added by commit B on top of commit A, but also the list of lines that were removed between commits A and F, which leads to confusing results. Fix by using the triple-dot diff operator in the Git invocation whose output is used as the source of information for determining the list of lines added by a given branch. Since Hazard fetches the target branch itself when it is run, remove the explicit "git fetch" invocation that fetches the target branch from GitLab (shortening its local history to a single commit in the process) before "git diff" is invoked. [1] https://danger.systems/js/reference.html#GitDSL
This commit is contained in:
parent
08ce1bc45f
commit
43126e81e6
@ -23,11 +23,13 @@ import gitlab
|
||||
def added_lines(target_branch, paths):
|
||||
import subprocess
|
||||
|
||||
subprocess.check_output(
|
||||
["/usr/bin/git", "fetch", "--depth", "1", "origin", target_branch]
|
||||
)
|
||||
# Hazard fetches the target branch itself, so there is no need to fetch it
|
||||
# explicitly using `git fetch --depth 1000 origin <target_branch>`. The
|
||||
# refs/remotes/origin/<target_branch> ref is also expected to be readily
|
||||
# usable by the time this file is executed.
|
||||
|
||||
diff = subprocess.check_output(
|
||||
["/usr/bin/git", "diff", "FETCH_HEAD..", "--"] + paths
|
||||
["/usr/bin/git", "diff", f"origin/{target_branch}...", "--"] + paths
|
||||
)
|
||||
added_lines = []
|
||||
for line in diff.splitlines():
|
||||
|
Loading…
x
Reference in New Issue
Block a user