We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pre_prompt bug when generating from current folder
* Cookiecutter version: 2.4.0
* Template project url: N/A
* Python version: 3.10
* Operating System: Linux

### Description:

I just learned about the new pre_prompt in 2.4.0. It's exactly what I wanted. Thanks for the new feature. When I develop the templates sometimes I will just run the cookiecutter in the same directory: `cookiecutter .`. With pre_prompt defined it will crash with an error saying the temporary directory already exists:
```
Traceback (most recent call last):
  File "/envs/cookiecutter/bin/cookiecutter", line 10, in <module>
    sys.exit(main())
  File "/envs/cookiecutter/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/envs/cookiecutter/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/envs/cookiecutter/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/envs/cookiecutter/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/envs/cookiecutter/lib/python3.10/site-packages/cookiecutter/cli.py", line 202, in main
    cookiecutter(
  File "/envs/cookiecutter/lib/python3.10/site-packages/cookiecutter/main.py", line 91, in cookiecutter
    repo_dir = run_pre_prompt_hook(base_repo_dir) if accept_hooks else repo_dir
  File "/envs/cookiecutter/lib/python3.10/site-packages/cookiecutter/hooks.py", line 179, in run_pre_prompt_hook
    repo_dir = create_tmp_repo_dir(repo_dir)
  File "/envs/cookiecutter/lib/python3.10/site-packages/cookiecutter/utils.py", line 128, in create_tmp_repo_dir
    shutil.copytree(repo_dir, new_dir)
  File "/envs/cookiecutter/lib/python3.10/shutil.py", line 559, in copytree
    return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
  File "/envs/cookiecutter/lib/python3.10/shutil.py", line 457, in _copytree
    os.makedirs(dst, exist_ok=dirs_exist_ok)
  File "/envs/cookiecutter/lib/python3.10/os.py", line 225, in makedirs
    mkdir(name, mode)
FileExistsError: [Errno 17] File exists: '/tmp/cookiecutter7yw9w4f5/'
```

It seems the temporary sub-directory name depends on the directory name of the repository, "." probably resolves to nothing and it will try to create the parent directory instead, so if I use the absolute path of the current directory it works: `cookiecutter $(pwd)`. It feels like a possible fix is just to compute the absolute path of the input path first. Thanks.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cookiecutter/utils.py`
Content:
```
1 """Helper functions used throughout Cookiecutter."""
2 import contextlib
3 import logging
4 import os
5 import shutil
6 import stat
7 import sys
8 import tempfile
9 from pathlib import Path
10 
11 from jinja2.ext import Extension
12 
13 from cookiecutter.prompt import read_user_yes_no
14 
15 logger = logging.getLogger(__name__)
16 
17 
18 def force_delete(func, path, exc_info):
19     """Error handler for `shutil.rmtree()` equivalent to `rm -rf`.
20 
21     Usage: `shutil.rmtree(path, onerror=force_delete)`
22     From https://docs.python.org/3/library/shutil.html#rmtree-example
23     """
24     os.chmod(path, stat.S_IWRITE)
25     func(path)
26 
27 
28 def rmtree(path):
29     """Remove a directory and all its contents. Like rm -rf on Unix.
30 
31     :param path: A directory path.
32     """
33     shutil.rmtree(path, onerror=force_delete)
34 
35 
36 def make_sure_path_exists(path: "os.PathLike[str]") -> None:
37     """Ensure that a directory exists.
38 
39     :param path: A directory tree path for creation.
40     """
41     logger.debug('Making sure path exists (creates tree if not exist): %s', path)
42     try:
43         Path(path).mkdir(parents=True, exist_ok=True)
44     except OSError as error:
45         raise OSError(f'Unable to create directory at {path}') from error
46 
47 
48 @contextlib.contextmanager
49 def work_in(dirname=None):
50     """Context manager version of os.chdir.
51 
52     When exited, returns to the working directory prior to entering.
53     """
54     curdir = os.getcwd()
55     try:
56         if dirname is not None:
57             os.chdir(dirname)
58         yield
59     finally:
60         os.chdir(curdir)
61 
62 
63 def make_executable(script_path):
64     """Make `script_path` executable.
65 
66     :param script_path: The file to change
67     """
68     status = os.stat(script_path)
69     os.chmod(script_path, status.st_mode | stat.S_IEXEC)
70 
71 
72 def prompt_and_delete(path, no_input=False):
73     """
74     Ask user if it's okay to delete the previously-downloaded file/directory.
75 
76     If yes, delete it. If no, checks to see if the old version should be
77     reused. If yes, it's reused; otherwise, Cookiecutter exits.
78 
79     :param path: Previously downloaded zipfile.
80     :param no_input: Suppress prompt to delete repo and just delete it.
81     :return: True if the content was deleted
82     """
83     # Suppress prompt if called via API
84     if no_input:
85         ok_to_delete = True
86     else:
87         question = (
88             f"You've downloaded {path} before. Is it okay to delete and re-download it?"
89         )
90 
91         ok_to_delete = read_user_yes_no(question, 'yes')
92 
93     if ok_to_delete:
94         if os.path.isdir(path):
95             rmtree(path)
96         else:
97             os.remove(path)
98         return True
99     else:
100         ok_to_reuse = read_user_yes_no(
101             "Do you want to re-use the existing version?", 'yes'
102         )
103 
104         if ok_to_reuse:
105             return False
106 
107         sys.exit()
108 
109 
110 def simple_filter(filter_function):
111     """Decorate a function to wrap it in a simplified jinja2 extension."""
112 
113     class SimpleFilterExtension(Extension):
114         def __init__(self, environment):
115             super().__init__(environment)
116             environment.filters[filter_function.__name__] = filter_function
117 
118     SimpleFilterExtension.__name__ = filter_function.__name__
119     return SimpleFilterExtension
120 
121 
122 def create_tmp_repo_dir(repo_dir: "os.PathLike[str]") -> Path:
123     """Create a temporary dir with a copy of the contents of repo_dir."""
124     repo_dir = Path(repo_dir) if isinstance(repo_dir, str) else repo_dir
125     base_dir = tempfile.mkdtemp(prefix='cookiecutter')
126     new_dir = f"{base_dir}/{repo_dir.name}"
127     logger.debug(f'Copying repo_dir from {repo_dir} to {new_dir}')
128     shutil.copytree(repo_dir, new_dir)
129     return Path(new_dir)
130
```
--- 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/cookiecutter/utils.py b/cookiecutter/utils.py
--- a/cookiecutter/utils.py
+++ b/cookiecutter/utils.py
@@ -121,7 +121,7 @@
 
 def create_tmp_repo_dir(repo_dir: "os.PathLike[str]") -> Path:
     """Create a temporary dir with a copy of the contents of repo_dir."""
-    repo_dir = Path(repo_dir) if isinstance(repo_dir, str) else repo_dir
+    repo_dir = Path(repo_dir).resolve()
     base_dir = tempfile.mkdtemp(prefix='cookiecutter')
     new_dir = f"{base_dir}/{repo_dir.name}"
     logger.debug(f'Copying repo_dir from {repo_dir} to {new_dir}')

{"golden_diff": "diff --git a/cookiecutter/utils.py b/cookiecutter/utils.py\n--- a/cookiecutter/utils.py\n+++ b/cookiecutter/utils.py\n@@ -121,7 +121,7 @@\n \n def create_tmp_repo_dir(repo_dir: \"os.PathLike[str]\") -> Path:\n     \"\"\"Create a temporary dir with a copy of the contents of repo_dir.\"\"\"\n-    repo_dir = Path(repo_dir) if isinstance(repo_dir, str) else repo_dir\n+    repo_dir = Path(repo_dir).resolve()\n     base_dir = tempfile.mkdtemp(prefix='cookiecutter')\n     new_dir = f\"{base_dir}/{repo_dir.name}\"\n     logger.debug(f'Copying repo_dir from {repo_dir} to {new_dir}')\n", "issue": "pre_prompt bug when generating from current folder\n* Cookiecutter version: 2.4.0\r\n* Template project url: N/A\r\n* Python version: 3.10\r\n* Operating System: Linux\r\n\r\n### Description:\r\n\r\nI just learned about the new pre_prompt in 2.4.0. It's exactly what I wanted. Thanks for the new feature. When I develop the templates sometimes I will just run the cookiecutter in the same directory: `cookiecutter .`. With pre_prompt defined it will crash with an error saying the temporary directory already exists:\r\n```\r\nTraceback (most recent call last):\r\n  File \"/envs/cookiecutter/bin/cookiecutter\", line 10, in <module>\r\n    sys.exit(main())\r\n  File \"/envs/cookiecutter/lib/python3.10/site-packages/click/core.py\", line 1157, in __call__\r\n    return self.main(*args, **kwargs)\r\n  File \"/envs/cookiecutter/lib/python3.10/site-packages/click/core.py\", line 1078, in main\r\n    rv = self.invoke(ctx)\r\n  File \"/envs/cookiecutter/lib/python3.10/site-packages/click/core.py\", line 1434, in invoke\r\n    return ctx.invoke(self.callback, **ctx.params)\r\n  File \"/envs/cookiecutter/lib/python3.10/site-packages/click/core.py\", line 783, in invoke\r\n    return __callback(*args, **kwargs)\r\n  File \"/envs/cookiecutter/lib/python3.10/site-packages/cookiecutter/cli.py\", line 202, in main\r\n    cookiecutter(\r\n  File \"/envs/cookiecutter/lib/python3.10/site-packages/cookiecutter/main.py\", line 91, in cookiecutter\r\n    repo_dir = run_pre_prompt_hook(base_repo_dir) if accept_hooks else repo_dir\r\n  File \"/envs/cookiecutter/lib/python3.10/site-packages/cookiecutter/hooks.py\", line 179, in run_pre_prompt_hook\r\n    repo_dir = create_tmp_repo_dir(repo_dir)\r\n  File \"/envs/cookiecutter/lib/python3.10/site-packages/cookiecutter/utils.py\", line 128, in create_tmp_repo_dir\r\n    shutil.copytree(repo_dir, new_dir)\r\n  File \"/envs/cookiecutter/lib/python3.10/shutil.py\", line 559, in copytree\r\n    return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,\r\n  File \"/envs/cookiecutter/lib/python3.10/shutil.py\", line 457, in _copytree\r\n    os.makedirs(dst, exist_ok=dirs_exist_ok)\r\n  File \"/envs/cookiecutter/lib/python3.10/os.py\", line 225, in makedirs\r\n    mkdir(name, mode)\r\nFileExistsError: [Errno 17] File exists: '/tmp/cookiecutter7yw9w4f5/'\r\n```\r\n\r\nIt seems the temporary sub-directory name depends on the directory name of the repository, \".\" probably resolves to nothing and it will try to create the parent directory instead, so if I use the absolute path of the current directory it works: `cookiecutter $(pwd)`. It feels like a possible fix is just to compute the absolute path of the input path first. Thanks.\r\n\n", "before_files": [{"content": "\"\"\"Helper functions used throughout Cookiecutter.\"\"\"\nimport contextlib\nimport logging\nimport os\nimport shutil\nimport stat\nimport sys\nimport tempfile\nfrom pathlib import Path\n\nfrom jinja2.ext import Extension\n\nfrom cookiecutter.prompt import read_user_yes_no\n\nlogger = logging.getLogger(__name__)\n\n\ndef force_delete(func, path, exc_info):\n    \"\"\"Error handler for `shutil.rmtree()` equivalent to `rm -rf`.\n\n    Usage: `shutil.rmtree(path, onerror=force_delete)`\n    From https://docs.python.org/3/library/shutil.html#rmtree-example\n    \"\"\"\n    os.chmod(path, stat.S_IWRITE)\n    func(path)\n\n\ndef rmtree(path):\n    \"\"\"Remove a directory and all its contents. Like rm -rf on Unix.\n\n    :param path: A directory path.\n    \"\"\"\n    shutil.rmtree(path, onerror=force_delete)\n\n\ndef make_sure_path_exists(path: \"os.PathLike[str]\") -> None:\n    \"\"\"Ensure that a directory exists.\n\n    :param path: A directory tree path for creation.\n    \"\"\"\n    logger.debug('Making sure path exists (creates tree if not exist): %s', path)\n    try:\n        Path(path).mkdir(parents=True, exist_ok=True)\n    except OSError as error:\n        raise OSError(f'Unable to create directory at {path}') from error\n\n\n@contextlib.contextmanager\ndef work_in(dirname=None):\n    \"\"\"Context manager version of os.chdir.\n\n    When exited, returns to the working directory prior to entering.\n    \"\"\"\n    curdir = os.getcwd()\n    try:\n        if dirname is not None:\n            os.chdir(dirname)\n        yield\n    finally:\n        os.chdir(curdir)\n\n\ndef make_executable(script_path):\n    \"\"\"Make `script_path` executable.\n\n    :param script_path: The file to change\n    \"\"\"\n    status = os.stat(script_path)\n    os.chmod(script_path, status.st_mode | stat.S_IEXEC)\n\n\ndef prompt_and_delete(path, no_input=False):\n    \"\"\"\n    Ask user if it's okay to delete the previously-downloaded file/directory.\n\n    If yes, delete it. If no, checks to see if the old version should be\n    reused. If yes, it's reused; otherwise, Cookiecutter exits.\n\n    :param path: Previously downloaded zipfile.\n    :param no_input: Suppress prompt to delete repo and just delete it.\n    :return: True if the content was deleted\n    \"\"\"\n    # Suppress prompt if called via API\n    if no_input:\n        ok_to_delete = True\n    else:\n        question = (\n            f\"You've downloaded {path} before. Is it okay to delete and re-download it?\"\n        )\n\n        ok_to_delete = read_user_yes_no(question, 'yes')\n\n    if ok_to_delete:\n        if os.path.isdir(path):\n            rmtree(path)\n        else:\n            os.remove(path)\n        return True\n    else:\n        ok_to_reuse = read_user_yes_no(\n            \"Do you want to re-use the existing version?\", 'yes'\n        )\n\n        if ok_to_reuse:\n            return False\n\n        sys.exit()\n\n\ndef simple_filter(filter_function):\n    \"\"\"Decorate a function to wrap it in a simplified jinja2 extension.\"\"\"\n\n    class SimpleFilterExtension(Extension):\n        def __init__(self, environment):\n            super().__init__(environment)\n            environment.filters[filter_function.__name__] = filter_function\n\n    SimpleFilterExtension.__name__ = filter_function.__name__\n    return SimpleFilterExtension\n\n\ndef create_tmp_repo_dir(repo_dir: \"os.PathLike[str]\") -> Path:\n    \"\"\"Create a temporary dir with a copy of the contents of repo_dir.\"\"\"\n    repo_dir = Path(repo_dir) if isinstance(repo_dir, str) else repo_dir\n    base_dir = tempfile.mkdtemp(prefix='cookiecutter')\n    new_dir = f\"{base_dir}/{repo_dir.name}\"\n    logger.debug(f'Copying repo_dir from {repo_dir} to {new_dir}')\n    shutil.copytree(repo_dir, new_dir)\n    return Path(new_dir)\n", "path": "cookiecutter/utils.py"}], "after_files": [{"content": "\"\"\"Helper functions used throughout Cookiecutter.\"\"\"\nimport contextlib\nimport logging\nimport os\nimport shutil\nimport stat\nimport sys\nimport tempfile\nfrom pathlib import Path\n\nfrom jinja2.ext import Extension\n\nfrom cookiecutter.prompt import read_user_yes_no\n\nlogger = logging.getLogger(__name__)\n\n\ndef force_delete(func, path, exc_info):\n    \"\"\"Error handler for `shutil.rmtree()` equivalent to `rm -rf`.\n\n    Usage: `shutil.rmtree(path, onerror=force_delete)`\n    From https://docs.python.org/3/library/shutil.html#rmtree-example\n    \"\"\"\n    os.chmod(path, stat.S_IWRITE)\n    func(path)\n\n\ndef rmtree(path):\n    \"\"\"Remove a directory and all its contents. Like rm -rf on Unix.\n\n    :param path: A directory path.\n    \"\"\"\n    shutil.rmtree(path, onerror=force_delete)\n\n\ndef make_sure_path_exists(path: \"os.PathLike[str]\") -> None:\n    \"\"\"Ensure that a directory exists.\n\n    :param path: A directory tree path for creation.\n    \"\"\"\n    logger.debug('Making sure path exists (creates tree if not exist): %s', path)\n    try:\n        Path(path).mkdir(parents=True, exist_ok=True)\n    except OSError as error:\n        raise OSError(f'Unable to create directory at {path}') from error\n\n\n@contextlib.contextmanager\ndef work_in(dirname=None):\n    \"\"\"Context manager version of os.chdir.\n\n    When exited, returns to the working directory prior to entering.\n    \"\"\"\n    curdir = os.getcwd()\n    try:\n        if dirname is not None:\n            os.chdir(dirname)\n        yield\n    finally:\n        os.chdir(curdir)\n\n\ndef make_executable(script_path):\n    \"\"\"Make `script_path` executable.\n\n    :param script_path: The file to change\n    \"\"\"\n    status = os.stat(script_path)\n    os.chmod(script_path, status.st_mode | stat.S_IEXEC)\n\n\ndef prompt_and_delete(path, no_input=False):\n    \"\"\"\n    Ask user if it's okay to delete the previously-downloaded file/directory.\n\n    If yes, delete it. If no, checks to see if the old version should be\n    reused. If yes, it's reused; otherwise, Cookiecutter exits.\n\n    :param path: Previously downloaded zipfile.\n    :param no_input: Suppress prompt to delete repo and just delete it.\n    :return: True if the content was deleted\n    \"\"\"\n    # Suppress prompt if called via API\n    if no_input:\n        ok_to_delete = True\n    else:\n        question = (\n            f\"You've downloaded {path} before. Is it okay to delete and re-download it?\"\n        )\n\n        ok_to_delete = read_user_yes_no(question, 'yes')\n\n    if ok_to_delete:\n        if os.path.isdir(path):\n            rmtree(path)\n        else:\n            os.remove(path)\n        return True\n    else:\n        ok_to_reuse = read_user_yes_no(\n            \"Do you want to re-use the existing version?\", 'yes'\n        )\n\n        if ok_to_reuse:\n            return False\n\n        sys.exit()\n\n\ndef simple_filter(filter_function):\n    \"\"\"Decorate a function to wrap it in a simplified jinja2 extension.\"\"\"\n\n    class SimpleFilterExtension(Extension):\n        def __init__(self, environment):\n            super().__init__(environment)\n            environment.filters[filter_function.__name__] = filter_function\n\n    SimpleFilterExtension.__name__ = filter_function.__name__\n    return SimpleFilterExtension\n\n\ndef create_tmp_repo_dir(repo_dir: \"os.PathLike[str]\") -> Path:\n    \"\"\"Create a temporary dir with a copy of the contents of repo_dir.\"\"\"\n    repo_dir = Path(repo_dir).resolve()\n    base_dir = tempfile.mkdtemp(prefix='cookiecutter')\n    new_dir = f\"{base_dir}/{repo_dir.name}\"\n    logger.debug(f'Copying repo_dir from {repo_dir} to {new_dir}')\n    shutil.copytree(repo_dir, new_dir)\n    return Path(new_dir)\n", "path": "cookiecutter/utils.py"}]}