]> 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:52:18 +0000 (17:52 +0100)
commitc2d041f1fdd03adc92f27f1de9e857e080fc1950
tree28f9a80ae21626bcfed0208a6956bbc497ad563c
parentf9115f00bc5221e1260591362c3d458bcf0234d1
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

(cherry picked from commit 43126e81e620deb63889d0812b2186af22da82bd)
dangerfile.py