Repository: scipy/scipy
Pull request: BUG: forward port lint_diff shims
Fixes #13030

* forward port the Travis CI shallow clone-related
fixes required for `lint_diff.py` to run properly
on backport PRs from gh-13028

* a better fix might happen with the Python module
itself so that the module may be used within any
CI service (or at least provide some kind of warning
in the presence of a shallow clone); that said,
if such a fix is pursued, please do test with a "dummy
PR" against a maintenance branch as well

Problem statement:
BUG: lint_diff.py still fails for backport PRs
Despite including gh-12974; see gh-13028: 

```
$ if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
   python tools/lint_diff.py --branch $TRAVIS_BRANCH
fi
fatal: ambiguous argument 'maintenance/1.5.x': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Traceback (most recent call last):
  File "tools/lint_diff.py", line 92, in <module>
    main()
  File "tools/lint_diff.py", line 83, in main
    branch_point = find_branch_point(args.branch)
  File "tools/lint_diff.py", line 44, in find_branch_point
    master_commits = set(rev_list(branch, 1000))
  File "tools/lint_diff.py", line 31, in rev_list
    res.check_returncode()
  File "/opt/python/3.6.7/lib/python3.6/subprocess.py", line 369, in check_returncode
    self.stderr)
subprocess.CalledProcessError: Command '['git', 'rev-list', '--max-count', '1000', '--first-parent', 'maintenance/1.5.x']' returned non-zero exit status 128.
The command "if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
   python tools/lint_diff.py --branch $TRAVIS_BRANCH
fi
" exited with 1.
```

cc @peterbell10

Hints from issue discussion:
I've pushed a small attempted fix into the backport PR for now; this almost certainly looks like an issue with Travis CI using shallow clones. If it works in the backport PR then I'll forward port the 1-liner.

Commit message: BUG: forward port lint_diff shims

* forward port the Travis CI shallow clone-related
fixes required for `lint_diff.py` to run properly
on backport PRs from gh-13028

* a better fix might happen with the Python module
itself so that the module may be used within any
CI service (or at least provide some kind of warning
in the presence of a shallow clone); that said,
if such a fix is pursued, please do test with a "dummy
PR" against a maintenance branch as well

Patch to review:
diff --git a/.travis.yml b/.travis.yml
index bab8f7edc604..456a092bd83e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -40,7 +40,10 @@ matrix:
         - pycodestyle scipy benchmarks/benchmarks
         - |
           if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
-             python tools/lint_diff.py --branch $TRAVIS_BRANCH
+             git fetch --unshallow
+             git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
+             git fetch origin
+             python tools/lint_diff.py --branch origin/$TRAVIS_BRANCH
           fi
         - tools/unicode-check.py
     - python: 3.7


Code review comments:
diff_hunk: @@ -40,7 +40,10 @@ matrix:
         - pycodestyle scipy benchmarks/benchmarks
         - |
           if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
-             python tools/lint_diff.py --branch $TRAVIS_BRANCH
+             git fetch --unshallow
+             git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
+             git fetch origin
path: .travis.yml
text: @user1:
Could you add `--no-tags` to save about 90 lines of output for tags that will not be needed?

@author:
done

diff_hunk: @@ -40,7 +40,10 @@ matrix:
         - pycodestyle scipy benchmarks/benchmarks
         - |
           if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
-             python tools/lint_diff.py --branch $TRAVIS_BRANCH
+             git fetch --unshallow
+             git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
path: .travis.yml
text: @user1:
Not sure if this works, but `origin/maintenance/1.*` is worth a try here. This step takes ~17 sec (rather than ~0 sec) to download a lot of data that's mostly not needed.

@author:
It seems that [partial globbing is not supported](https://stackoverflow.com/a/15508750/2942522), so I just used `maintenance/*`; not sure that helps much but I did it.