We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Alternative to stashing files for testing
Are there any plans to implement alternatives to stashing the worktree?

Ideally this would be hook/scriptable, like some 'prepare-worktree' and 'restore-worktree' options (which default to the current stash behavior) but can also yield some new directory where the tests are run. The rationale here is that my editor reverts files changed on disk and I'd like to add notes to  source files while the commit is in progress.

In my own pre-commit hooks I use something like:

     git archive "$(git write-tree)" --prefix="$test_dir/" | tar xf -

To create a pristine source tree (actually, I also prime it with `cp -rl` with build artifacts from the previous build to speed up incremental builds). 'git-worktree' and other tools could be used as well...

Eventually I have the idea to run some (more expensive) pre-commit checks in the background while one types the  commit message. Then in the commit-msg hook wait for the background results and abort the commit there. This should reduce the turn around times significantly.




--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pre_commit/languages/swift.py`
Content:
```
1 from __future__ import annotations
2 
3 import contextlib
4 import os
5 from typing import Generator
6 from typing import Sequence
7 
8 from pre_commit import lang_base
9 from pre_commit.envcontext import envcontext
10 from pre_commit.envcontext import PatchesT
11 from pre_commit.envcontext import Var
12 from pre_commit.prefix import Prefix
13 from pre_commit.util import cmd_output_b
14 
15 BUILD_DIR = '.build'
16 BUILD_CONFIG = 'release'
17 
18 ENVIRONMENT_DIR = 'swift_env'
19 get_default_version = lang_base.basic_get_default_version
20 health_check = lang_base.basic_health_check
21 run_hook = lang_base.basic_run_hook
22 
23 
24 def get_env_patch(venv: str) -> PatchesT:  # pragma: win32 no cover
25     bin_path = os.path.join(venv, BUILD_DIR, BUILD_CONFIG)
26     return (('PATH', (bin_path, os.pathsep, Var('PATH'))),)
27 
28 
29 @contextlib.contextmanager  # pragma: win32 no cover
30 def in_env(prefix: Prefix, version: str) -> Generator[None, None, None]:
31     envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version)
32     with envcontext(get_env_patch(envdir)):
33         yield
34 
35 
36 def install_environment(
37         prefix: Prefix, version: str, additional_dependencies: Sequence[str],
38 ) -> None:  # pragma: win32 no cover
39     lang_base.assert_version_default('swift', version)
40     lang_base.assert_no_additional_deps('swift', additional_dependencies)
41     envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version)
42 
43     # Build the swift package
44     os.mkdir(envdir)
45     cmd_output_b(
46         'swift', 'build',
47         '-C', prefix.prefix_dir,
48         '-c', BUILD_CONFIG,
49         '--build-path', os.path.join(envdir, BUILD_DIR),
50     )
51
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pre_commit/languages/swift.py b/pre_commit/languages/swift.py
--- a/pre_commit/languages/swift.py
+++ b/pre_commit/languages/swift.py
@@ -44,7 +44,7 @@
     os.mkdir(envdir)
     cmd_output_b(
         'swift', 'build',
-        '-C', prefix.prefix_dir,
+        '--package-path', prefix.prefix_dir,
         '-c', BUILD_CONFIG,
         '--build-path', os.path.join(envdir, BUILD_DIR),
     )

{"golden_diff": "diff --git a/pre_commit/languages/swift.py b/pre_commit/languages/swift.py\n--- a/pre_commit/languages/swift.py\n+++ b/pre_commit/languages/swift.py\n@@ -44,7 +44,7 @@\n     os.mkdir(envdir)\n     cmd_output_b(\n         'swift', 'build',\n-        '-C', prefix.prefix_dir,\n+        '--package-path', prefix.prefix_dir,\n         '-c', BUILD_CONFIG,\n         '--build-path', os.path.join(envdir, BUILD_DIR),\n     )\n", "issue": "Alternative to stashing files for testing\nAre there any plans to implement alternatives to stashing the worktree?\r\n\r\nIdeally this would be hook/scriptable, like some 'prepare-worktree' and 'restore-worktree' options (which default to the current stash behavior) but can also yield some new directory where the tests are run. The rationale here is that my editor reverts files changed on disk and I'd like to add notes to  source files while the commit is in progress.\r\n\r\nIn my own pre-commit hooks I use something like:\r\n\r\n     git archive \"$(git write-tree)\" --prefix=\"$test_dir/\" | tar xf -\r\n\r\nTo create a pristine source tree (actually, I also prime it with `cp -rl` with build artifacts from the previous build to speed up incremental builds). 'git-worktree' and other tools could be used as well...\r\n\r\nEventually I have the idea to run some (more expensive) pre-commit checks in the background while one types the  commit message. Then in the commit-msg hook wait for the background results and abort the commit there. This should reduce the turn around times significantly.\r\n\r\n\r\n\n", "before_files": [{"content": "from __future__ import annotations\n\nimport contextlib\nimport os\nfrom typing import Generator\nfrom typing import Sequence\n\nfrom pre_commit import lang_base\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import PatchesT\nfrom pre_commit.envcontext import Var\nfrom pre_commit.prefix import Prefix\nfrom pre_commit.util import cmd_output_b\n\nBUILD_DIR = '.build'\nBUILD_CONFIG = 'release'\n\nENVIRONMENT_DIR = 'swift_env'\nget_default_version = lang_base.basic_get_default_version\nhealth_check = lang_base.basic_health_check\nrun_hook = lang_base.basic_run_hook\n\n\ndef get_env_patch(venv: str) -> PatchesT:  # pragma: win32 no cover\n    bin_path = os.path.join(venv, BUILD_DIR, BUILD_CONFIG)\n    return (('PATH', (bin_path, os.pathsep, Var('PATH'))),)\n\n\n@contextlib.contextmanager  # pragma: win32 no cover\ndef in_env(prefix: Prefix, version: str) -> Generator[None, None, None]:\n    envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version)\n    with envcontext(get_env_patch(envdir)):\n        yield\n\n\ndef install_environment(\n        prefix: Prefix, version: str, additional_dependencies: Sequence[str],\n) -> None:  # pragma: win32 no cover\n    lang_base.assert_version_default('swift', version)\n    lang_base.assert_no_additional_deps('swift', additional_dependencies)\n    envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version)\n\n    # Build the swift package\n    os.mkdir(envdir)\n    cmd_output_b(\n        'swift', 'build',\n        '-C', prefix.prefix_dir,\n        '-c', BUILD_CONFIG,\n        '--build-path', os.path.join(envdir, BUILD_DIR),\n    )\n", "path": "pre_commit/languages/swift.py"}], "after_files": [{"content": "from __future__ import annotations\n\nimport contextlib\nimport os\nfrom typing import Generator\nfrom typing import Sequence\n\nfrom pre_commit import lang_base\nfrom pre_commit.envcontext import envcontext\nfrom pre_commit.envcontext import PatchesT\nfrom pre_commit.envcontext import Var\nfrom pre_commit.prefix import Prefix\nfrom pre_commit.util import cmd_output_b\n\nBUILD_DIR = '.build'\nBUILD_CONFIG = 'release'\n\nENVIRONMENT_DIR = 'swift_env'\nget_default_version = lang_base.basic_get_default_version\nhealth_check = lang_base.basic_health_check\nrun_hook = lang_base.basic_run_hook\n\n\ndef get_env_patch(venv: str) -> PatchesT:  # pragma: win32 no cover\n    bin_path = os.path.join(venv, BUILD_DIR, BUILD_CONFIG)\n    return (('PATH', (bin_path, os.pathsep, Var('PATH'))),)\n\n\n@contextlib.contextmanager  # pragma: win32 no cover\ndef in_env(prefix: Prefix, version: str) -> Generator[None, None, None]:\n    envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version)\n    with envcontext(get_env_patch(envdir)):\n        yield\n\n\ndef install_environment(\n        prefix: Prefix, version: str, additional_dependencies: Sequence[str],\n) -> None:  # pragma: win32 no cover\n    lang_base.assert_version_default('swift', version)\n    lang_base.assert_no_additional_deps('swift', additional_dependencies)\n    envdir = lang_base.environment_dir(prefix, ENVIRONMENT_DIR, version)\n\n    # Build the swift package\n    os.mkdir(envdir)\n    cmd_output_b(\n        'swift', 'build',\n        '--package-path', prefix.prefix_dir,\n        '-c', BUILD_CONFIG,\n        '--build-path', os.path.join(envdir, BUILD_DIR),\n    )\n", "path": "pre_commit/languages/swift.py"}]}