Repository: iterative/dvc

Issue:
exp: Not able to run with pre-commit
# Bug Report

## Description


Hello, when running `dvc exp run --set-param debug=true`, I got the following error:
```
WARNING: Your workspace contains staged Git changes which will be unstaged before running this experiment.
An error has occurred: FatalError: git toplevel unexpectedly empty! make sure you are not inside the `.git` directory of your repository.
Check the log at /Users/***/.cache/pre-commit/pre-commit.log
ERROR: unexpected error - Hook pre-commit exited with non-zero status 1
```


### Environment information

<!--
This is required to ensure that we can reproduce the bug.
-->

**Output of `dvc doctor`:**

```console
DVC version: 2.0.3 (pip)
---------------------------------
Platform: Python 3.7.4 on Darwin-20.2.0-x86_64-i386-64bit
Supports: http, https, s3
Cache types: reflink, hardlink, symlink
Cache directory: apfs on /dev/disk1s2s1
Caches: local
Remotes: s3
Workspace directory: apfs on /dev/disk1s2s1
Repo: dvc, git
```

**Additional Information (if any):**

<details>
<summary>Here is the full log in /Users/***/.cache/pre-commit/pre-commit.log</summary>

### version information

```
pre-commit version: 2.11.0
sys.version:
    3.7.4 (default, Sep 11 2020, 15:33:25)
    [Clang 11.0.3 (clang-1103.0.32.62)]
sys.executable: /Users/***/projects/speech/.venv/bin/python
os.name: posix
sys.platform: darwin
```

### error information

```
An error has occurred: FatalError: git toplevel unexpectedly empty! make sure you are not inside the `.git` directory of your repository.
```

```
Traceback (most recent call last):
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/pre_commit/error_handler.py", line 65, in error_handler
    yield
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/pre_commit/main.py", line 340, in main
    _adjust_args_and_chdir(args)
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/pre_commit/main.py", line 157, in _adjust_args_and_chdir
    toplevel = git.get_root()
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/pre_commit/git.py", line 66, in get_root
    'git toplevel unexpectedly empty! make sure you are not '
pre_commit.errors.FatalError: git toplevel unexpectedly empty! make sure you are not inside the `.git` directory of your repository.
```

</details>

<details>
<summary>Verbose output</summary>


```
2021-03-09 14:35:15,711 TRACE: Namespace(all_pipelines=False, cd='.', checkpoint_resume=None, cmd='run', cprofile=False, cprofile_dump=None, downstream=False, dry=False, force=False, force_downstream=False, func=<class 'dvc.command.experiments.CmdExperimentsRun'>, glob=False, instrument=False, instrument_open=False, interactive=False, jobs=None, metrics=False, name=None, no_commit=False, no_run_cache=False, pdb=False, pipeline=False, pull=False, queue=False, quiet=0, recursive=False, reset=False, run_all=False, set_param=['debug=true'], single_item=False, targets=[], tmp_dir=False, verbose=3, version=None)
2021-03-09 14:35:15,884 DEBUG: Check for update is enabled.
2021-03-09 14:36:24,443 DEBUG: Detaching HEAD at 'HEAD'
2021-03-09 14:36:24,584 DEBUG: Stashing workspace
2021-03-09 14:36:24,710 DEBUG: Stashing changes in 'refs/stash'
2021-03-09 14:36:24,802 DEBUG: Applying stash commit 'f64fa6a3c06bf6780bbc848d0706a901ace1c295'
2021-03-09 14:36:30,382 DEBUG: Using experiment params 'defaultdict(<class 'dict'>, {'params.yaml': {'debug': True}})'
2021-03-09 14:36:30,517 DEBUG: Stashing changes in 'refs/exps/stash'
An error has occurred: FatalError: git toplevel unexpectedly empty! make sure you are not inside the `.git` directory of your repository.
Check the log at /Users/corentinhembise/.cache/pre-commit/pre-commit.log
2021-03-09 14:36:31,003 DEBUG: Restoring stashed workspace
2021-03-09 14:36:31,003 DEBUG: Popping from stash 'refs/stash'
2021-03-09 14:36:31,004 DEBUG: Applying stash commit 'f64fa6a3c06bf6780bbc848d0706a901ace1c295'
2021-03-09 14:36:31,074 DEBUG: Dropping 'refs/stash@{0}'
2021-03-09 14:36:31,098 DEBUG: Restore HEAD to 'update-dvc-2.0'
2021-03-09 14:36:31,121 ERROR: unexpected error - Hook pre-commit exited with non-zero status 1
------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dulwich/repo.py", line 905, in do_commit
    self.hooks["pre-commit"].execute()
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dulwich/hooks.py", line 108, in execute
    "Hook %s exited with non-zero status %d" % (self.name, ret)
dulwich.errors.HookError: Hook pre-commit exited with non-zero status 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dvc/main.py", line 50, in main
    ret = cmd.run()
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dvc/command/experiments.py", line 529, in run
    **self._repro_kwargs,
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dvc/repo/experiments/__init__.py", line 831, in run
    return run(self.repo, *args, **kwargs)
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dvc/repo/__init__.py", line 49, in wrapper
    return f(repo, *args, **kwargs)
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dvc/repo/experiments/run.py", line 38, in run
    targets=targets, params=params, tmp_dir=tmp_dir, **kwargs
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dvc/repo/experiments/__init__.py", line 373, in reproduce_one
    stash_rev = self.new(checkpoint_resume=checkpoint_resume, **kwargs)
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dvc/repo/experiments/__init__.py", line 46, in wrapper
    return f(exp, *args, **kwargs)
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dvc/repo/experiments/__init__.py", line 436, in new
    return self._stash_exp(*args, **kwargs)
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dvc/repo/experiments/__init__.py", line 228, in _stash_exp
    stash_rev = self.stash.push(message=msg)
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dvc/scm/git/stash.py", line 43, in push
    self.ref, message=message, include_untracked=include_untracked
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dvc/scm/git/__init__.py", line 344, in _backend_func
    return func(*args, **kwargs)
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dvc/scm/git/backend/dulwich.py", line 532, in _stash_push
    rev = stash.push(message=message_b)
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dulwich/stash.py", line 102, in push
    **commit_kwargs
  File "/Users/***/projects/speech/.venv/lib/python3.7/site-packages/dulwich/repo.py", line 907, in do_commit
    raise CommitError(e)
dulwich.errors.CommitError: Hook pre-commit exited with non-zero status 1
------------------------------------------------------------
2021-03-09 14:36:31,325 DEBUG: Version info for developers:
DVC version: 2.0.3 (pip)
---------------------------------
Platform: Python 3.7.4 on Darwin-20.2.0-x86_64-i386-64bit
Supports: http, https, s3
Cache types: reflink, hardlink, symlink
Cache directory: apfs on /dev/disk1s2s1
Caches: local
Remotes: s3
Workspace directory: apfs on /dev/disk1s2s1
Repo: dvc, git

Having any troubles? Hit us up at https://dvc.org/support, we are always happy to help!
2021-03-09 14:36:31,328 DEBUG: Analytics is enabled.
2021-03-09 14:36:31,508 DEBUG: Trying to spawn '['daemon', '-q', 'analytics', '/var/folders/0p/bt3j1r7s6fb5f6wyd436tmnc0000gn/T/tmp2b5cnk5z']'
2021-03-09 14:36:31,510 DEBUG: Spawned '['daemon', '-q', 'analytics', '/var/folders/0p/bt3j1r7s6fb5f6wyd436tmnc0000gn/T/tmp2b5cnk5z']'
```

</details>



Discussion:
Looks like an upstream dulwich issue, it should not be running hooks when generating stash commits
will be fixed by https://github.com/dulwich/dulwich/pull/849

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -51,7 +51,7 @@ def run(self):
     "colorama>=0.3.9",
     "configobj>=5.0.6",
     "gitpython>3",
-    "dulwich>=0.20.20",
+    "dulwich>=0.20.21",
     "pygit2>=1.5.0",
     "setuptools>=34.0.0",
     "nanotime>=0.5.2",


Test patch: