anon-iclr-submission/benchname-bug-localization huggingface dataset:
Repository: pre-commit/pre-commit
Issue: cygwin python checking should happen after setup code

Regressed as part of #436

Before:

```
$ ./pre-commit/venv_cygwin_python/bin/pre-commit clean
An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?
Check the log at ~/.pre-commit/pre-commit.log
```

Current master:

```
$ ./pre-commit/venv_cygwin_python/bin/pre-commit clean
An unexpected error has occurred: CalledProcessError: Command: ('/usr/bin/git', 'rev-parse', '--show-toplevel')
Return code: 128
Expected return code: 0
Output: (none)
Errors:
    fatal: Not a git repository (or any of the parent directories): .git


Check the log at ~/.pre-commit/pre-commit.log
```

Changed files:
pre_commit/main.py, tests/main_test.py

diff --git a/pre_commit/main.py b/pre_commit/main.py
index 4bcd153..9d9329a 100644
--- a/pre_commit/main.py
+++ b/pre_commit/main.py
@@ -152,8 +152,8 @@ def main(argv=None):
 
     with error_handler():
         add_logging_handler(args.color)
-        git.check_for_cygwin_mismatch()
         runner = Runner.create()
+        git.check_for_cygwin_mismatch()
 
         if args.command == 'install':
             return install(
diff --git a/tests/main_test.py b/tests/main_test.py
index 537ff23..86b6dcd 100644
--- a/tests/main_test.py
+++ b/tests/main_test.py
@@ -7,6 +7,7 @@ import mock
 import pytest
 
 from pre_commit import main
+from pre_commit.error_handler import PreCommitSystemExit
 from pre_commit.util import cwd
 from testing.auto_namedtuple import auto_namedtuple
 
@@ -142,3 +143,16 @@ def test_help_cmd_in_empty_directory(
         mock.call(['help', 'run']),
         mock.call(['run', '--help']),
     ])
+
+
+def test_expected_fatal_error_no_git_repo(
+        tempdir_factory, cap_out, mock_out_store_directory,
+):
+    with cwd(tempdir_factory.get()):
+        with pytest.raises(PreCommitSystemExit):
+            main.main([])
+    assert cap_out.get() == (
+        'An error has occurred: FatalError: git failed. '
+        'Is it installed, and are you in a Git repository directory?\\n'
+        'Check the log at ~/.pre-commit/pre-commit.log\\n'
+    )
Repository: pre-commit/pre-commit
Issue: `docker build` argument order is invalid on old versions of Docker

We do: `docker build . --tag thing --label thing`

But this produces an error on Docker 1.11.2:
```
ckuehl@dev4-uswest1cdevc:~/proj/pre-commit$ docker build . --tag thing --label thing
docker: "build" requires 1 argument.
See 'docker build --help'.

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile
```

The path needs to go at the end on 1.11.2, but it works on 1.13.0 as-is. We should probably just change the order of the arguments to make every version happy.

Changed files:
pre_commit/languages/docker.py

diff --git a/pre_commit/languages/docker.py b/pre_commit/languages/docker.py
index fd24995..7d3f8d0 100644
--- a/pre_commit/languages/docker.py
+++ b/pre_commit/languages/docker.py
@@ -43,12 +43,14 @@ def build_docker_image(repo_cmd_runner, **kwargs):  # pragma: windows no cover
     pull = kwargs.pop('pull')
     assert not kwargs, kwargs
     cmd = (
-        'docker', 'build', '.',
+        'docker', 'build',
         '--tag', docker_tag(repo_cmd_runner),
         '--label', PRE_COMMIT_LABEL,
     )
     if pull:
         cmd += ('--pull',)
+    # This must come last for old versions of docker.  See #477
+    cmd += ('.',)
     helpers.run_setup_cmd(repo_cmd_runner, cmd)
Repository: pre-commit/pre-commit
Issue: git.get_git_dir() appears to break with older versions of git

When you install the current pre-commit (v1.11.0) on a system using an older git, eg 2.1.4, the `git rev-parse --git-common-dir` ultimately issued by `git.get_git_dir()` yields the result `--git-common-dir` instead of `.git` like you'd expect. This causes pre-commit to get installed in a directory literally named "--git-common-dir", and thus not work.

Happened to encounter using a docker image for an older version of python, which used an older git. Examples to demo the issue:

```
$ docker run python:2.7.9 sh -c "git init foo && cd foo && git rev-parse --git-common-dir && git --version"
Initialized empty Git repository in /foo/.git/
--git-common-dir
git version 2.1.4
$ docker run python:2.7.15 sh -c "git init foo && cd foo && git rev-parse --git-common-dir && git --version"
Initialized empty Git repository in /foo/.git/
.git
git version 2.11.0
```

In git.get_git_dir() as it stands, it appears that the older-git behavior is anticipated. It looks like older gits are expected to throw a `CalledProcessError` when `git rev-parse --git-common-dir` is called, and fall back to `git rev-parse --git-dir`. But evidently that's not working as intended?

Changed files:
pre_commit/git.py

diff --git a/pre_commit/git.py b/pre_commit/git.py
index 9ec9c9f..a926116 100644
--- a/pre_commit/git.py
+++ b/pre_commit/git.py
@@ -31,16 +31,13 @@ def get_root():
 
 
 def get_git_dir(git_root):
-    def _git_dir(opt):
-        return os.path.normpath(os.path.join(
-            git_root,
-            cmd_output('git', 'rev-parse', opt, cwd=git_root)[1].strip(),
-        ))
-
-    try:
-        return _git_dir('--git-common-dir')
-    except CalledProcessError:  # pragma: no cover (git < 2.5)
-        return _git_dir('--git-dir')
+    opts = ('--git-common-dir', '--git-dir')
+    _, out, _ = cmd_output('git', 'rev-parse', *opts, cwd=git_root)
+    for line, opt in zip(out.splitlines(), opts):
+        if line != opt:  # pragma: no branch (git < 2.5)
+            return os.path.normpath(os.path.join(git_root, line))
+    else:
+        raise AssertionError('unreachable: no git dir')
 
 
 def get_remote_url(git_root):
Repository: pre-commit/pre-commit
Issue: `stages: [commit]` hooks will run with `pre-commit run otherhookid`

minor logic bug, good new-contributor ticket

Easy to reproduce on pre-commit itself:

```diff
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index a146bd2..7bb382d 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -3,6 +3,7 @@ repos:
     rev: v1.2.3
     hooks:
     -   id: trailing-whitespace
+        stages: [commit]
     -   id: end-of-file-fixer
     -   id: autopep8-wrapper
     -   id: check-docstring-first
```

```console
$ pre-commit run end-of-file-fixer --all-files
Trim Trailing Whitespace.................................................Passed
Fix End of Files.........................................................Passed
```

(it should have only run `end-of-file-fixer` but also run `trailing-whitespace` due to a logic error).

Changed files:
tests/commands/run_test.py, pre_commit/commands/run.py

diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py
index b1549d4..dbf5641 100644
--- a/pre_commit/commands/run.py
+++ b/pre_commit/commands/run.py
@@ -256,7 +256,7 @@ def run(runner, store, args, environ=os.environ):
             for _, hook in repo.hooks:
                 if (
                     (not args.hook or hook['id'] == args.hook) and
-                    not hook['stages'] or args.hook_stage in hook['stages']
+                    (not hook['stages'] or args.hook_stage in hook['stages'])
                 ):
                     repo_hooks.append((repo, hook))
 
diff --git a/tests/commands/run_test.py b/tests/commands/run_test.py
index 70a6b6e..e6258d3 100644
--- a/tests/commands/run_test.py
+++ b/tests/commands/run_test.py
@@ -762,3 +762,34 @@ def test_include_exclude_does_search_instead_of_match(some_filenames):
 def test_include_exclude_exclude_removes_files(some_filenames):
     ret = _filter_by_include_exclude(some_filenames, '', r'\\.py$')
     assert ret == ['.pre-commit-hooks.yaml']
+
+
+def test_args_hook_only(cap_out, store, repo_with_passing_hook):
+    config = OrderedDict((
+        ('repo', 'local'),
+        (
+            'hooks', (
+                OrderedDict((
+                    ('id', 'flake8'),
+                    ('name', 'flake8'),
+                    ('entry', "'{}' -m flake8".format(sys.executable)),
+                    ('language', 'system'),
+                    ('stages', ['commit']),
+                )), OrderedDict((
+                    ('id', 'do_not_commit'),
+                    ('name', 'Block if "DO NOT COMMIT" is found'),
+                    ('entry', 'DO NOT COMMIT'),
+                    ('language', 'pygrep'),
+                )),
+            ),
+        ),
+    ))
+    add_config_to_repo(repo_with_passing_hook, config)
+    stage_a_file()
+    ret, printed = _do_run(
+        cap_out,
+        store,
+        repo_with_passing_hook,
+        run_opts(hook='do_not_commit'),
+    )
+    assert b'flake8' not in printed
Repository: facebookresearch/parlai
Issue: Slow loading of image features during training

For VQA tasks, it takes massive amount of time to load the image features for training. The overhead is so much that for the same model it increases the training time by a factor of 50.

Changed files:
parlai/core/image_featurizers.py

diff --git a/parlai/core/image_featurizers.py b/parlai/core/image_featurizers.py
index 39fd5f25..ddb123d5 100644
--- a/parlai/core/image_featurizers.py
+++ b/parlai/core/image_featurizers.py
@@ -9,6 +9,7 @@ import os
 import copy
 import numpy as np
 from PIL import Image
+from functools import lru_cache
 
 _greyscale = '  .,:;crsA23hHG#98&@'
 
@@ -121,6 +122,7 @@ class ImageLoader():
             asc.append('\\n')
         return ''.join(asc)
 
+    @lru_cache(maxsize=None)
     def load(self, path):
         opt = self.opt
         mode = opt.get('image_mode', 'raw')
Repository: facebookresearch/parlai
Issue: Training hanged at loss.backward() of movie-dialog-qa

Hi, I am interested in Memory Networks and Movie Dialog QA. Although I tried below command, training stopped at first `loss.backward()` at `memnn.py`. I waited almost one day, but `loss.backward()` didn't finish. I have checked this by printing debug and `[Using Cuda]` printing. Actually my GPU was working because it used some memory. I checked this by `nvidia-smi -l 1`.

`python examples/train_model.py -m memnn -t "#moviedd-qa" -bs 32 --gpu 0 -e 10`

Then, I switched to simple task, and it finished a few minutes.
`python examples/train_model.py -m memnn -t "babi:task1k:1" -bs 32 --gpu 0 -e 10 `

I realize `#moviedd-qa` is more complicated compared to babi task. But how long does it usually take to train this model in my setting? Does anyone try to train this model via ParlAI? I am afraid this is not bug of ParlAI. Could you advise me to proceed my work?

### My Environment
- Ubunt 16.04.03 LTS, 64 bit
- python 3.6.1 (Anaconda 4.4.0 (64-bit))
- GPU: GTX 1080 ti
- CPU: Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
- torch.\\_\\_version\\_\\_: '0.2.0_3'

Changed files:
parlai/agents/memnn/memnn.py

diff --git a/parlai/agents/memnn/memnn.py b/parlai/agents/memnn/memnn.py
index 9298c281..dc503158 100644
--- a/parlai/agents/memnn/memnn.py
+++ b/parlai/agents/memnn/memnn.py
@@ -129,6 +129,8 @@ class MemnnAgent(Agent):
         return observation
 
     def predict(self, xs, cands, ys=None):
+        # Subsample to reduce training time
+        cands = [list(set(random.sample(c, min(32, len(c))) + self.labels)) for c in cands]
         is_training = ys is not None
         self.model.train(mode=is_training)
         # Organize inputs for network (see contents of xs and ys in batchify method)