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():