]> git.ipfire.org Git - thirdparty/bind9.git/commit
Improve determining the lines added by a branch
authorMichał Kępień <michal@isc.org>
Thu, 7 Dec 2023 12:23:22 +0000 (13:23 +0100)
committerMichal Nowak <mnowak@isc.org>
Mon, 11 Dec 2023 16:22:03 +0000 (17:22 +0100)
commit43126e81e620deb63889d0812b2186af22da82bd
tree35ccc2018f7616cad50112ea9c7a2c8c4b4f8c83
parent08ce1bc45fbe00db5ac5ec77335b38c8ce7d1990
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
dangerfile.py