We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
gh_deploy doesn't work when a config file is supplied
```
$ mkdocs gh-deploy --force --config-file mkdocs-editable.yml
...
Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/__main__.py", line 205, in gh_deploy_command
    gh_deploy.gh_deploy(cfg, message=message, force=force, ignore_version=ignore_version, shell=shell)
  File "/usr/local/lib/python3.9/site-packages/mkdocs/commands/gh_deploy.py", line 102, in gh_deploy
    sha = _get_current_sha(os.path.dirname(config.config_file_path))
  File "/usr/local/lib/python3.9/site-packages/mkdocs/commands/gh_deploy.py", line 32, in _get_current_sha
    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], cwd=repo_path,
  File "/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: ''
```

The issue is that `sha = _get_current_sha(os.path.dirname(config.config_file_path))` from `gh_deploy.py` returns an empty string for `dirname` if a relative config file path is passed in.

Workaround: `--config-file $(pwd)/mkdocs-editable.yml`


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mkdocs/commands/gh_deploy.py`
Content:
```
1 import logging
2 import subprocess
3 import os
4 import re
5 from packaging import version
6 
7 import mkdocs
8 import ghp_import
9 from mkdocs.exceptions import Abort
10 
11 log = logging.getLogger(__name__)
12 
13 default_message = """Deployed {sha} with MkDocs version: {version}"""
14 
15 
16 def _is_cwd_git_repo():
17     try:
18         proc = subprocess.Popen(
19             ['git', 'rev-parse', '--is-inside-work-tree'],
20             stdout=subprocess.PIPE,
21             stderr=subprocess.PIPE
22         )
23     except FileNotFoundError:
24         log.error("Could not find git - is it installed and on your path?")
25         raise Abort('Deployment Aborted!')
26     proc.communicate()
27     return proc.wait() == 0
28 
29 
30 def _get_current_sha(repo_path):
31 
32     proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], cwd=repo_path,
33                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
34 
35     stdout, _ = proc.communicate()
36     sha = stdout.decode('utf-8').strip()
37     return sha
38 
39 
40 def _get_remote_url(remote_name):
41 
42     # No CNAME found.  We will use the origin URL to determine the GitHub
43     # pages location.
44     remote = f"remote.{remote_name}.url"
45     proc = subprocess.Popen(["git", "config", "--get", remote],
46                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
47 
48     stdout, _ = proc.communicate()
49     url = stdout.decode('utf-8').strip()
50 
51     host = None
52     path = None
53     if 'github.com/' in url:
54         host, path = url.split('github.com/', 1)
55     elif 'github.com:' in url:
56         host, path = url.split('github.com:', 1)
57 
58     return host, path
59 
60 
61 def _check_version(branch):
62 
63     proc = subprocess.Popen(['git', 'show', '-s', '--format=%s', f'refs/heads/{branch}'],
64                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
65 
66     stdout, _ = proc.communicate()
67     msg = stdout.decode('utf-8').strip()
68     m = re.search(r'\d+(\.\d+)+((a|b|rc)\d+)?(\.post\d+)?(\.dev\d+)?', msg, re.X | re.I)
69     previousv = version.parse(m.group()) if m else None
70     currentv = version.parse(mkdocs.__version__)
71     if not previousv:
72         log.warning('Version check skipped: No version specified in previous deployment.')
73     elif currentv > previousv:
74         log.info(
75             f'Previous deployment was done with MkDocs version {previousv}; '
76             f'you are deploying with a newer version ({currentv})'
77         )
78     elif currentv < previousv:
79         log.error(
80             f'Deployment terminated: Previous deployment was made with MkDocs version {previousv}; '
81             f'you are attempting to deploy with an older version ({currentv}). Use --ignore-version '
82             'to deploy anyway.'
83         )
84         raise Abort('Deployment Aborted!')
85 
86 
87 def gh_deploy(config, message=None, force=False, ignore_version=False, shell=False):
88 
89     if not _is_cwd_git_repo():
90         log.error('Cannot deploy - this directory does not appear to be a git '
91                   'repository')
92 
93     remote_branch = config['remote_branch']
94     remote_name = config['remote_name']
95 
96     if not ignore_version:
97         _check_version(remote_branch)
98 
99     if message is None:
100         message = default_message
101     sha = _get_current_sha(os.path.dirname(config.config_file_path))
102     message = message.format(version=mkdocs.__version__, sha=sha)
103 
104     log.info("Copying '%s' to '%s' branch and pushing to GitHub.",
105              config['site_dir'], config['remote_branch'])
106 
107     try:
108         ghp_import.ghp_import(
109             config['site_dir'],
110             mesg=message,
111             remote=remote_name,
112             branch=remote_branch,
113             push=True,
114             force=force,
115             use_shell=shell,
116             nojekyll=True
117         )
118     except ghp_import.GhpError as e:
119         log.error("Failed to deploy to GitHub with error: \n{}".format(e.message))
120         raise Abort('Deployment Aborted!')
121 
122     cname_file = os.path.join(config['site_dir'], 'CNAME')
123     # Does this repository have a CNAME set for GitHub pages?
124     if os.path.isfile(cname_file):
125         # This GitHub pages repository has a CNAME configured.
126         with(open(cname_file, 'r')) as f:
127             cname_host = f.read().strip()
128         log.info(f'Based on your CNAME file, your documentation should be '
129                  f'available shortly at: http://{cname_host}')
130         log.info('NOTE: Your DNS records must be configured appropriately for '
131                  'your CNAME URL to work.')
132         return
133 
134     host, path = _get_remote_url(remote_name)
135 
136     if host is None:
137         # This could be a GitHub Enterprise deployment.
138         log.info('Your documentation should be available shortly.')
139     else:
140         username, repo = path.split('/', 1)
141         if repo.endswith('.git'):
142             repo = repo[:-len('.git')]
143         url = f'https://{username}.github.io/{repo}/'
144         log.info(f"Your documentation should shortly be available at: {url}")
145
```
--- 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/mkdocs/commands/gh_deploy.py b/mkdocs/commands/gh_deploy.py
--- a/mkdocs/commands/gh_deploy.py
+++ b/mkdocs/commands/gh_deploy.py
@@ -29,7 +29,7 @@
 
 def _get_current_sha(repo_path):
 
-    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], cwd=repo_path,
+    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], cwd=repo_path or None,
                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
     stdout, _ = proc.communicate()

{"golden_diff": "diff --git a/mkdocs/commands/gh_deploy.py b/mkdocs/commands/gh_deploy.py\n--- a/mkdocs/commands/gh_deploy.py\n+++ b/mkdocs/commands/gh_deploy.py\n@@ -29,7 +29,7 @@\n \n def _get_current_sha(repo_path):\n \n-    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], cwd=repo_path,\n+    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], cwd=repo_path or None,\n                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n \n     stdout, _ = proc.communicate()\n", "issue": "gh_deploy doesn't work when a config file is supplied\n```\r\n$ mkdocs gh-deploy --force --config-file mkdocs-editable.yml\r\n...\r\nTraceback (most recent call last):\r\n  File \"/usr/local/bin/mkdocs\", line 8, in <module>\r\n    sys.exit(cli())\r\n  File \"/usr/local/lib/python3.9/site-packages/click/core.py\", line 1137, in __call__\r\n    return self.main(*args, **kwargs)\r\n  File \"/usr/local/lib/python3.9/site-packages/click/core.py\", line 1062, in main\r\n    rv = self.invoke(ctx)\r\n  File \"/usr/local/lib/python3.9/site-packages/click/core.py\", line 1668, in invoke\r\n    return _process_result(sub_ctx.command.invoke(sub_ctx))\r\n  File \"/usr/local/lib/python3.9/site-packages/click/core.py\", line 1404, in invoke\r\n    return ctx.invoke(self.callback, **ctx.params)\r\n  File \"/usr/local/lib/python3.9/site-packages/click/core.py\", line 763, in invoke\r\n    return __callback(*args, **kwargs)\r\n  File \"/usr/local/lib/python3.9/site-packages/mkdocs/__main__.py\", line 205, in gh_deploy_command\r\n    gh_deploy.gh_deploy(cfg, message=message, force=force, ignore_version=ignore_version, shell=shell)\r\n  File \"/usr/local/lib/python3.9/site-packages/mkdocs/commands/gh_deploy.py\", line 102, in gh_deploy\r\n    sha = _get_current_sha(os.path.dirname(config.config_file_path))\r\n  File \"/usr/local/lib/python3.9/site-packages/mkdocs/commands/gh_deploy.py\", line 32, in _get_current_sha\r\n    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], cwd=repo_path,\r\n  File \"/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py\", line 951, in __init__\r\n    self._execute_child(args, executable, preexec_fn, close_fds,\r\n  File \"/usr/local/Cellar/python@3.9/3.9.4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py\", line 1821, in _execute_child\r\n    raise child_exception_type(errno_num, err_msg, err_filename)\r\nFileNotFoundError: [Errno 2] No such file or directory: ''\r\n```\r\n\r\nThe issue is that `sha = _get_current_sha(os.path.dirname(config.config_file_path))` from `gh_deploy.py` returns an empty string for `dirname` if a relative config file path is passed in.\r\n\r\nWorkaround: `--config-file $(pwd)/mkdocs-editable.yml`\r\n\n", "before_files": [{"content": "import logging\nimport subprocess\nimport os\nimport re\nfrom packaging import version\n\nimport mkdocs\nimport ghp_import\nfrom mkdocs.exceptions import Abort\n\nlog = logging.getLogger(__name__)\n\ndefault_message = \"\"\"Deployed {sha} with MkDocs version: {version}\"\"\"\n\n\ndef _is_cwd_git_repo():\n    try:\n        proc = subprocess.Popen(\n            ['git', 'rev-parse', '--is-inside-work-tree'],\n            stdout=subprocess.PIPE,\n            stderr=subprocess.PIPE\n        )\n    except FileNotFoundError:\n        log.error(\"Could not find git - is it installed and on your path?\")\n        raise Abort('Deployment Aborted!')\n    proc.communicate()\n    return proc.wait() == 0\n\n\ndef _get_current_sha(repo_path):\n\n    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], cwd=repo_path,\n                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n    stdout, _ = proc.communicate()\n    sha = stdout.decode('utf-8').strip()\n    return sha\n\n\ndef _get_remote_url(remote_name):\n\n    # No CNAME found.  We will use the origin URL to determine the GitHub\n    # pages location.\n    remote = f\"remote.{remote_name}.url\"\n    proc = subprocess.Popen([\"git\", \"config\", \"--get\", remote],\n                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n    stdout, _ = proc.communicate()\n    url = stdout.decode('utf-8').strip()\n\n    host = None\n    path = None\n    if 'github.com/' in url:\n        host, path = url.split('github.com/', 1)\n    elif 'github.com:' in url:\n        host, path = url.split('github.com:', 1)\n\n    return host, path\n\n\ndef _check_version(branch):\n\n    proc = subprocess.Popen(['git', 'show', '-s', '--format=%s', f'refs/heads/{branch}'],\n                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n    stdout, _ = proc.communicate()\n    msg = stdout.decode('utf-8').strip()\n    m = re.search(r'\\d+(\\.\\d+)+((a|b|rc)\\d+)?(\\.post\\d+)?(\\.dev\\d+)?', msg, re.X | re.I)\n    previousv = version.parse(m.group()) if m else None\n    currentv = version.parse(mkdocs.__version__)\n    if not previousv:\n        log.warning('Version check skipped: No version specified in previous deployment.')\n    elif currentv > previousv:\n        log.info(\n            f'Previous deployment was done with MkDocs version {previousv}; '\n            f'you are deploying with a newer version ({currentv})'\n        )\n    elif currentv < previousv:\n        log.error(\n            f'Deployment terminated: Previous deployment was made with MkDocs version {previousv}; '\n            f'you are attempting to deploy with an older version ({currentv}). Use --ignore-version '\n            'to deploy anyway.'\n        )\n        raise Abort('Deployment Aborted!')\n\n\ndef gh_deploy(config, message=None, force=False, ignore_version=False, shell=False):\n\n    if not _is_cwd_git_repo():\n        log.error('Cannot deploy - this directory does not appear to be a git '\n                  'repository')\n\n    remote_branch = config['remote_branch']\n    remote_name = config['remote_name']\n\n    if not ignore_version:\n        _check_version(remote_branch)\n\n    if message is None:\n        message = default_message\n    sha = _get_current_sha(os.path.dirname(config.config_file_path))\n    message = message.format(version=mkdocs.__version__, sha=sha)\n\n    log.info(\"Copying '%s' to '%s' branch and pushing to GitHub.\",\n             config['site_dir'], config['remote_branch'])\n\n    try:\n        ghp_import.ghp_import(\n            config['site_dir'],\n            mesg=message,\n            remote=remote_name,\n            branch=remote_branch,\n            push=True,\n            force=force,\n            use_shell=shell,\n            nojekyll=True\n        )\n    except ghp_import.GhpError as e:\n        log.error(\"Failed to deploy to GitHub with error: \\n{}\".format(e.message))\n        raise Abort('Deployment Aborted!')\n\n    cname_file = os.path.join(config['site_dir'], 'CNAME')\n    # Does this repository have a CNAME set for GitHub pages?\n    if os.path.isfile(cname_file):\n        # This GitHub pages repository has a CNAME configured.\n        with(open(cname_file, 'r')) as f:\n            cname_host = f.read().strip()\n        log.info(f'Based on your CNAME file, your documentation should be '\n                 f'available shortly at: http://{cname_host}')\n        log.info('NOTE: Your DNS records must be configured appropriately for '\n                 'your CNAME URL to work.')\n        return\n\n    host, path = _get_remote_url(remote_name)\n\n    if host is None:\n        # This could be a GitHub Enterprise deployment.\n        log.info('Your documentation should be available shortly.')\n    else:\n        username, repo = path.split('/', 1)\n        if repo.endswith('.git'):\n            repo = repo[:-len('.git')]\n        url = f'https://{username}.github.io/{repo}/'\n        log.info(f\"Your documentation should shortly be available at: {url}\")\n", "path": "mkdocs/commands/gh_deploy.py"}], "after_files": [{"content": "import logging\nimport subprocess\nimport os\nimport re\nfrom packaging import version\n\nimport mkdocs\nimport ghp_import\nfrom mkdocs.exceptions import Abort\n\nlog = logging.getLogger(__name__)\n\ndefault_message = \"\"\"Deployed {sha} with MkDocs version: {version}\"\"\"\n\n\ndef _is_cwd_git_repo():\n    try:\n        proc = subprocess.Popen(\n            ['git', 'rev-parse', '--is-inside-work-tree'],\n            stdout=subprocess.PIPE,\n            stderr=subprocess.PIPE\n        )\n    except FileNotFoundError:\n        log.error(\"Could not find git - is it installed and on your path?\")\n        raise Abort('Deployment Aborted!')\n    proc.communicate()\n    return proc.wait() == 0\n\n\ndef _get_current_sha(repo_path):\n\n    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], cwd=repo_path or None,\n                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n    stdout, _ = proc.communicate()\n    sha = stdout.decode('utf-8').strip()\n    return sha\n\n\ndef _get_remote_url(remote_name):\n\n    # No CNAME found.  We will use the origin URL to determine the GitHub\n    # pages location.\n    remote = f\"remote.{remote_name}.url\"\n    proc = subprocess.Popen([\"git\", \"config\", \"--get\", remote],\n                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n    stdout, _ = proc.communicate()\n    url = stdout.decode('utf-8').strip()\n\n    host = None\n    path = None\n    if 'github.com/' in url:\n        host, path = url.split('github.com/', 1)\n    elif 'github.com:' in url:\n        host, path = url.split('github.com:', 1)\n\n    return host, path\n\n\ndef _check_version(branch):\n\n    proc = subprocess.Popen(['git', 'show', '-s', '--format=%s', f'refs/heads/{branch}'],\n                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n\n    stdout, _ = proc.communicate()\n    msg = stdout.decode('utf-8').strip()\n    m = re.search(r'\\d+(\\.\\d+)+((a|b|rc)\\d+)?(\\.post\\d+)?(\\.dev\\d+)?', msg, re.X | re.I)\n    previousv = version.parse(m.group()) if m else None\n    currentv = version.parse(mkdocs.__version__)\n    if not previousv:\n        log.warning('Version check skipped: No version specified in previous deployment.')\n    elif currentv > previousv:\n        log.info(\n            f'Previous deployment was done with MkDocs version {previousv}; '\n            f'you are deploying with a newer version ({currentv})'\n        )\n    elif currentv < previousv:\n        log.error(\n            f'Deployment terminated: Previous deployment was made with MkDocs version {previousv}; '\n            f'you are attempting to deploy with an older version ({currentv}). Use --ignore-version '\n            'to deploy anyway.'\n        )\n        raise Abort('Deployment Aborted!')\n\n\ndef gh_deploy(config, message=None, force=False, ignore_version=False, shell=False):\n\n    if not _is_cwd_git_repo():\n        log.error('Cannot deploy - this directory does not appear to be a git '\n                  'repository')\n\n    remote_branch = config['remote_branch']\n    remote_name = config['remote_name']\n\n    if not ignore_version:\n        _check_version(remote_branch)\n\n    if message is None:\n        message = default_message\n    sha = _get_current_sha(os.path.dirname(config.config_file_path))\n    message = message.format(version=mkdocs.__version__, sha=sha)\n\n    log.info(\"Copying '%s' to '%s' branch and pushing to GitHub.\",\n             config['site_dir'], config['remote_branch'])\n\n    try:\n        ghp_import.ghp_import(\n            config['site_dir'],\n            mesg=message,\n            remote=remote_name,\n            branch=remote_branch,\n            push=True,\n            force=force,\n            use_shell=shell,\n            nojekyll=True\n        )\n    except ghp_import.GhpError as e:\n        log.error(\"Failed to deploy to GitHub with error: \\n{}\".format(e.message))\n        raise Abort('Deployment Aborted!')\n\n    cname_file = os.path.join(config['site_dir'], 'CNAME')\n    # Does this repository have a CNAME set for GitHub pages?\n    if os.path.isfile(cname_file):\n        # This GitHub pages repository has a CNAME configured.\n        with(open(cname_file, 'r')) as f:\n            cname_host = f.read().strip()\n        log.info(f'Based on your CNAME file, your documentation should be '\n                 f'available shortly at: http://{cname_host}')\n        log.info('NOTE: Your DNS records must be configured appropriately for '\n                 'your CNAME URL to work.')\n        return\n\n    host, path = _get_remote_url(remote_name)\n\n    if host is None:\n        # This could be a GitHub Enterprise deployment.\n        log.info('Your documentation should be available shortly.')\n    else:\n        username, repo = path.split('/', 1)\n        if repo.endswith('.git'):\n            repo = repo[:-len('.git')]\n        url = f'https://{username}.github.io/{repo}/'\n        log.info(f\"Your documentation should shortly be available at: {url}\")\n", "path": "mkdocs/commands/gh_deploy.py"}]}