We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
gh-deploy command fails silently
If the `git push` command fails for some reason (e.g., creds access), we don't check the result and then fail the deploy.

PR with a fix coming momentarily.


--- 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/utils/ghp_import.py`
Content:
```
1 #! /usr/bin/env python
2 #
3 # This file is part of the ghp-import package released under
4 # the Tumbolia Public License.
5 
6 #                            Tumbolia Public License
7 
8 # Copyright 2013, Paul Davis <paul.joseph.davis@gmail.com>
9 
10 # Copying and distribution of this file, with or without modification, are
11 # permitted in any medium without royalty provided the copyright notice and this
12 # notice are preserved.
13 
14 # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
15 
16 #   0. opan saurce LOL
17 
18 from __future__ import unicode_literals
19 
20 import errno
21 import logging
22 import os
23 import subprocess as sp
24 import sys
25 import time
26 import unicodedata
27 
28 log = logging.getLogger(__name__)
29 
30 
31 if sys.version_info[0] == 3:
32     def enc(text):
33         if isinstance(text, bytes):
34             return text
35         return text.encode()
36 
37     def dec(text):
38         if isinstance(text, bytes):
39             return text.decode('utf-8')
40         return text
41 
42     def write(pipe, data):
43         try:
44             pipe.stdin.write(data)
45         except IOError as e:
46             if e.errno != errno.EPIPE:
47                 raise
48 else:
49     def enc(text):
50         if isinstance(text, unicode):
51             return text.encode('utf-8')
52         return text
53 
54     def dec(text):
55         if isinstance(text, unicode):
56             return text
57         return text.decode('utf-8')
58 
59     def write(pipe, data):
60         pipe.stdin.write(data)
61 
62 
63 def normalize_path(path):
64     # Fix unicode pathnames on OS X
65     # See: http://stackoverflow.com/a/5582439/44289
66     if sys.platform == "darwin":
67         return unicodedata.normalize("NFKC", dec(path))
68     return path
69 
70 
71 def try_rebase(remote, branch):
72     cmd = ['git', 'rev-list', '--max-count=1', '%s/%s' % (remote, branch)]
73     p = sp.Popen(cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)
74     (rev, _) = p.communicate()
75     if p.wait() != 0:
76         return True
77     cmd = ['git', 'update-ref', 'refs/heads/%s' % branch, dec(rev.strip())]
78     if sp.call(cmd) != 0:
79         return False
80     return True
81 
82 
83 def get_config(key):
84     p = sp.Popen(['git', 'config', key], stdin=sp.PIPE, stdout=sp.PIPE)
85     (value, _) = p.communicate()
86     return value.decode('utf-8').strip()
87 
88 
89 def get_prev_commit(branch):
90     cmd = ['git', 'rev-list', '--max-count=1', branch, '--']
91     p = sp.Popen(cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)
92     (rev, _) = p.communicate()
93     if p.wait() != 0:
94         return None
95     return rev.decode('utf-8').strip()
96 
97 
98 def mk_when(timestamp=None):
99     if timestamp is None:
100         timestamp = int(time.time())
101     currtz = "%+05d" % (-1 * time.timezone / 36)  # / 3600 * 100
102     return "%s %s" % (timestamp, currtz)
103 
104 
105 def start_commit(pipe, branch, message):
106     uname = dec(get_config("user.name"))
107     email = dec(get_config("user.email"))
108     write(pipe, enc('commit refs/heads/%s\n' % branch))
109     write(pipe, enc('committer %s <%s> %s\n' % (uname, email, mk_when())))
110     write(pipe, enc('data %d\n%s\n' % (len(message), message)))
111     head = get_prev_commit(branch)
112     if head:
113         write(pipe, enc('from %s\n' % head))
114     write(pipe, enc('deleteall\n'))
115 
116 
117 def add_file(pipe, srcpath, tgtpath):
118     with open(srcpath, "rb") as handle:
119         if os.access(srcpath, os.X_OK):
120             write(pipe, enc('M 100755 inline %s\n' % tgtpath))
121         else:
122             write(pipe, enc('M 100644 inline %s\n' % tgtpath))
123         data = handle.read()
124         write(pipe, enc('data %d\n' % len(data)))
125         write(pipe, enc(data))
126         write(pipe, enc('\n'))
127 
128 
129 def add_nojekyll(pipe):
130     write(pipe, enc('M 100644 inline .nojekyll\n'))
131     write(pipe, enc('data 0\n'))
132     write(pipe, enc('\n'))
133 
134 
135 def gitpath(fname):
136     norm = os.path.normpath(fname)
137     return "/".join(norm.split(os.path.sep))
138 
139 
140 def run_import(srcdir, branch, message, nojekyll):
141     cmd = ['git', 'fast-import', '--date-format=raw', '--quiet']
142     kwargs = {"stdin": sp.PIPE}
143     if sys.version_info >= (3, 2, 0):
144         kwargs["universal_newlines"] = False
145     pipe = sp.Popen(cmd, **kwargs)
146     start_commit(pipe, branch, message)
147     for path, _, fnames in os.walk(srcdir):
148         for fn in fnames:
149             fpath = os.path.join(path, fn)
150             fpath = normalize_path(fpath)
151             gpath = gitpath(os.path.relpath(fpath, start=srcdir))
152             add_file(pipe, fpath, gpath)
153     if nojekyll:
154         add_nojekyll(pipe)
155     write(pipe, enc('\n'))
156     pipe.stdin.close()
157     if pipe.wait() != 0:
158         sys.stdout.write(enc("Failed to process commit.\n"))
159 
160 
161 def ghp_import(directory, message, remote='origin', branch='gh-pages'):
162 
163     if not try_rebase(remote, branch):
164         log.error("Failed to rebase %s branch.", branch)
165 
166     nojekyll = True
167 
168     run_import(directory, branch, message, nojekyll)
169 
170     proc = sp.Popen(['git', 'push', remote, branch],
171                     stdout=sp.PIPE, stderr=sp.PIPE)
172     proc.communicate()
173     return proc.wait() == 0
174
```

Path: `mkdocs/commands/gh_deploy.py`
Content:
```
1 from __future__ import unicode_literals
2 import logging
3 import subprocess
4 import os
5 
6 import mkdocs
7 from mkdocs.utils import ghp_import
8 
9 log = logging.getLogger(__name__)
10 
11 default_message = """Deployed {sha} with MkDocs version: {version}"""
12 
13 
14 def _is_cwd_git_repo():
15     proc = subprocess.Popen(['git', 'rev-parse', '--is-inside-work-tree'],
16                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
17     proc.communicate()
18     return proc.wait() == 0
19 
20 
21 def _get_current_sha():
22 
23     proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'],
24                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
25 
26     stdout, _ = proc.communicate()
27     sha = stdout.decode('utf-8').strip()
28     return sha
29 
30 
31 def _get_remote_url(remote_name):
32 
33     # No CNAME found.  We will use the origin URL to determine the GitHub
34     # pages location.
35     remote = "remote.%s.url" % remote_name
36     proc = subprocess.Popen(["git", "config", "--get", remote],
37                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
38 
39     stdout, _ = proc.communicate()
40     url = stdout.decode('utf-8').strip()
41 
42     host = None
43     path = None
44     if 'github.com/' in url:
45         host, path = url.split('github.com/', 1)
46     elif 'github.com:' in url:
47         host, path = url.split('github.com:', 1)
48 
49     return host, path
50 
51 
52 def gh_deploy(config, message=None):
53 
54     if not _is_cwd_git_repo():
55         log.error('Cannot deploy - this directory does not appear to be a git '
56                   'repository')
57 
58     if message is None:
59         sha = _get_current_sha()
60         message = default_message.format(version=mkdocs.__version__, sha=sha)
61 
62     remote_branch = config['remote_branch']
63     remote_name = config['remote_name']
64 
65     log.info("Copying '%s' to '%s' branch and pushing to GitHub.",
66              config['site_dir'], config['remote_branch'])
67 
68     ghp_import.ghp_import(config['site_dir'], message, remote_name,
69                           remote_branch)
70 
71     cname_file = os.path.join(config['site_dir'], 'CNAME')
72     # Does this repository have a CNAME set for GitHub pages?
73     if os.path.isfile(cname_file):
74         # This GitHub pages repository has a CNAME configured.
75         with(open(cname_file, 'r')) as f:
76             cname_host = f.read().strip()
77         log.info('Based on your CNAME file, your documentation should be '
78                  'available shortly at: http://%s', cname_host)
79         log.info('NOTE: Your DNS records must be configured appropriately for '
80                  'your CNAME URL to work.')
81         return
82 
83     host, path = _get_remote_url(remote_name)
84 
85     if host is None:
86         # This could be a GitHub Enterprise deployment.
87         log.info('Your documentation should be available shortly.')
88     else:
89         username, repo = path.split('/', 1)
90         if repo.endswith('.git'):
91             repo = repo[:-len('.git')]
92         url = 'http://%s.github.io/%s' % (username, repo)
93         log.info('Your documentation should shortly be available at: ' + url)
94
```
--- 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
@@ -65,29 +65,32 @@
     log.info("Copying '%s' to '%s' branch and pushing to GitHub.",
              config['site_dir'], config['remote_branch'])
 
-    ghp_import.ghp_import(config['site_dir'], message, remote_name,
-                          remote_branch)
-
-    cname_file = os.path.join(config['site_dir'], 'CNAME')
-    # Does this repository have a CNAME set for GitHub pages?
-    if os.path.isfile(cname_file):
-        # This GitHub pages repository has a CNAME configured.
-        with(open(cname_file, 'r')) as f:
-            cname_host = f.read().strip()
-        log.info('Based on your CNAME file, your documentation should be '
-                 'available shortly at: http://%s', cname_host)
-        log.info('NOTE: Your DNS records must be configured appropriately for '
-                 'your CNAME URL to work.')
-        return
-
-    host, path = _get_remote_url(remote_name)
-
-    if host is None:
-        # This could be a GitHub Enterprise deployment.
-        log.info('Your documentation should be available shortly.')
+    result, error = ghp_import.ghp_import(config['site_dir'], message, remote_name,
+                                          remote_branch)
+    if not result:
+        log.error("Failed to deploy to GitHub with error: \n%s", error)
+        raise SystemExit(1)
     else:
-        username, repo = path.split('/', 1)
-        if repo.endswith('.git'):
-            repo = repo[:-len('.git')]
-        url = 'http://%s.github.io/%s' % (username, repo)
-        log.info('Your documentation should shortly be available at: ' + url)
+        cname_file = os.path.join(config['site_dir'], 'CNAME')
+        # Does this repository have a CNAME set for GitHub pages?
+        if os.path.isfile(cname_file):
+            # This GitHub pages repository has a CNAME configured.
+            with(open(cname_file, 'r')) as f:
+                cname_host = f.read().strip()
+            log.info('Based on your CNAME file, your documentation should be '
+                     'available shortly at: http://%s', cname_host)
+            log.info('NOTE: Your DNS records must be configured appropriately for '
+                     'your CNAME URL to work.')
+            return
+
+        host, path = _get_remote_url(remote_name)
+
+        if host is None:
+            # This could be a GitHub Enterprise deployment.
+            log.info('Your documentation should be available shortly.')
+        else:
+            username, repo = path.split('/', 1)
+            if repo.endswith('.git'):
+                repo = repo[:-len('.git')]
+            url = 'http://%s.github.io/%s' % (username, repo)
+            log.info('Your documentation should shortly be available at: ' + url)
diff --git a/mkdocs/utils/ghp_import.py b/mkdocs/utils/ghp_import.py
--- a/mkdocs/utils/ghp_import.py
+++ b/mkdocs/utils/ghp_import.py
@@ -169,5 +169,8 @@
 
     proc = sp.Popen(['git', 'push', remote, branch],
                     stdout=sp.PIPE, stderr=sp.PIPE)
-    proc.communicate()
-    return proc.wait() == 0
+
+    out, err = proc.communicate()
+    result = proc.wait() == 0
+
+    return result, dec(err)

{"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@@ -65,29 +65,32 @@\n     log.info(\"Copying '%s' to '%s' branch and pushing to GitHub.\",\n              config['site_dir'], config['remote_branch'])\n \n-    ghp_import.ghp_import(config['site_dir'], message, remote_name,\n-                          remote_branch)\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('Based on your CNAME file, your documentation should be '\n-                 'available shortly at: http://%s', 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+    result, error = ghp_import.ghp_import(config['site_dir'], message, remote_name,\n+                                          remote_branch)\n+    if not result:\n+        log.error(\"Failed to deploy to GitHub with error: \\n%s\", error)\n+        raise SystemExit(1)\n     else:\n-        username, repo = path.split('/', 1)\n-        if repo.endswith('.git'):\n-            repo = repo[:-len('.git')]\n-        url = 'http://%s.github.io/%s' % (username, repo)\n-        log.info('Your documentation should shortly be available at: ' + url)\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('Based on your CNAME file, your documentation should be '\n+                     'available shortly at: http://%s', 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 = 'http://%s.github.io/%s' % (username, repo)\n+            log.info('Your documentation should shortly be available at: ' + url)\ndiff --git a/mkdocs/utils/ghp_import.py b/mkdocs/utils/ghp_import.py\n--- a/mkdocs/utils/ghp_import.py\n+++ b/mkdocs/utils/ghp_import.py\n@@ -169,5 +169,8 @@\n \n     proc = sp.Popen(['git', 'push', remote, branch],\n                     stdout=sp.PIPE, stderr=sp.PIPE)\n-    proc.communicate()\n-    return proc.wait() == 0\n+\n+    out, err = proc.communicate()\n+    result = proc.wait() == 0\n+\n+    return result, dec(err)\n", "issue": "gh-deploy command fails silently\nIf the `git push` command fails for some reason (e.g., creds access), we don't check the result and then fail the deploy.\n\nPR with a fix coming momentarily.\n\n", "before_files": [{"content": "#! /usr/bin/env python\n#\n# This file is part of the ghp-import package released under\n# the Tumbolia Public License.\n\n#                            Tumbolia Public License\n\n# Copyright 2013, Paul Davis <paul.joseph.davis@gmail.com>\n\n# Copying and distribution of this file, with or without modification, are\n# permitted in any medium without royalty provided the copyright notice and this\n# notice are preserved.\n\n# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n#   0. opan saurce LOL\n\nfrom __future__ import unicode_literals\n\nimport errno\nimport logging\nimport os\nimport subprocess as sp\nimport sys\nimport time\nimport unicodedata\n\nlog = logging.getLogger(__name__)\n\n\nif sys.version_info[0] == 3:\n    def enc(text):\n        if isinstance(text, bytes):\n            return text\n        return text.encode()\n\n    def dec(text):\n        if isinstance(text, bytes):\n            return text.decode('utf-8')\n        return text\n\n    def write(pipe, data):\n        try:\n            pipe.stdin.write(data)\n        except IOError as e:\n            if e.errno != errno.EPIPE:\n                raise\nelse:\n    def enc(text):\n        if isinstance(text, unicode):\n            return text.encode('utf-8')\n        return text\n\n    def dec(text):\n        if isinstance(text, unicode):\n            return text\n        return text.decode('utf-8')\n\n    def write(pipe, data):\n        pipe.stdin.write(data)\n\n\ndef normalize_path(path):\n    # Fix unicode pathnames on OS X\n    # See: http://stackoverflow.com/a/5582439/44289\n    if sys.platform == \"darwin\":\n        return unicodedata.normalize(\"NFKC\", dec(path))\n    return path\n\n\ndef try_rebase(remote, branch):\n    cmd = ['git', 'rev-list', '--max-count=1', '%s/%s' % (remote, branch)]\n    p = sp.Popen(cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)\n    (rev, _) = p.communicate()\n    if p.wait() != 0:\n        return True\n    cmd = ['git', 'update-ref', 'refs/heads/%s' % branch, dec(rev.strip())]\n    if sp.call(cmd) != 0:\n        return False\n    return True\n\n\ndef get_config(key):\n    p = sp.Popen(['git', 'config', key], stdin=sp.PIPE, stdout=sp.PIPE)\n    (value, _) = p.communicate()\n    return value.decode('utf-8').strip()\n\n\ndef get_prev_commit(branch):\n    cmd = ['git', 'rev-list', '--max-count=1', branch, '--']\n    p = sp.Popen(cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)\n    (rev, _) = p.communicate()\n    if p.wait() != 0:\n        return None\n    return rev.decode('utf-8').strip()\n\n\ndef mk_when(timestamp=None):\n    if timestamp is None:\n        timestamp = int(time.time())\n    currtz = \"%+05d\" % (-1 * time.timezone / 36)  # / 3600 * 100\n    return \"%s %s\" % (timestamp, currtz)\n\n\ndef start_commit(pipe, branch, message):\n    uname = dec(get_config(\"user.name\"))\n    email = dec(get_config(\"user.email\"))\n    write(pipe, enc('commit refs/heads/%s\\n' % branch))\n    write(pipe, enc('committer %s <%s> %s\\n' % (uname, email, mk_when())))\n    write(pipe, enc('data %d\\n%s\\n' % (len(message), message)))\n    head = get_prev_commit(branch)\n    if head:\n        write(pipe, enc('from %s\\n' % head))\n    write(pipe, enc('deleteall\\n'))\n\n\ndef add_file(pipe, srcpath, tgtpath):\n    with open(srcpath, \"rb\") as handle:\n        if os.access(srcpath, os.X_OK):\n            write(pipe, enc('M 100755 inline %s\\n' % tgtpath))\n        else:\n            write(pipe, enc('M 100644 inline %s\\n' % tgtpath))\n        data = handle.read()\n        write(pipe, enc('data %d\\n' % len(data)))\n        write(pipe, enc(data))\n        write(pipe, enc('\\n'))\n\n\ndef add_nojekyll(pipe):\n    write(pipe, enc('M 100644 inline .nojekyll\\n'))\n    write(pipe, enc('data 0\\n'))\n    write(pipe, enc('\\n'))\n\n\ndef gitpath(fname):\n    norm = os.path.normpath(fname)\n    return \"/\".join(norm.split(os.path.sep))\n\n\ndef run_import(srcdir, branch, message, nojekyll):\n    cmd = ['git', 'fast-import', '--date-format=raw', '--quiet']\n    kwargs = {\"stdin\": sp.PIPE}\n    if sys.version_info >= (3, 2, 0):\n        kwargs[\"universal_newlines\"] = False\n    pipe = sp.Popen(cmd, **kwargs)\n    start_commit(pipe, branch, message)\n    for path, _, fnames in os.walk(srcdir):\n        for fn in fnames:\n            fpath = os.path.join(path, fn)\n            fpath = normalize_path(fpath)\n            gpath = gitpath(os.path.relpath(fpath, start=srcdir))\n            add_file(pipe, fpath, gpath)\n    if nojekyll:\n        add_nojekyll(pipe)\n    write(pipe, enc('\\n'))\n    pipe.stdin.close()\n    if pipe.wait() != 0:\n        sys.stdout.write(enc(\"Failed to process commit.\\n\"))\n\n\ndef ghp_import(directory, message, remote='origin', branch='gh-pages'):\n\n    if not try_rebase(remote, branch):\n        log.error(\"Failed to rebase %s branch.\", branch)\n\n    nojekyll = True\n\n    run_import(directory, branch, message, nojekyll)\n\n    proc = sp.Popen(['git', 'push', remote, branch],\n                    stdout=sp.PIPE, stderr=sp.PIPE)\n    proc.communicate()\n    return proc.wait() == 0\n", "path": "mkdocs/utils/ghp_import.py"}, {"content": "from __future__ import unicode_literals\nimport logging\nimport subprocess\nimport os\n\nimport mkdocs\nfrom mkdocs.utils import ghp_import\n\nlog = logging.getLogger(__name__)\n\ndefault_message = \"\"\"Deployed {sha} with MkDocs version: {version}\"\"\"\n\n\ndef _is_cwd_git_repo():\n    proc = subprocess.Popen(['git', 'rev-parse', '--is-inside-work-tree'],\n                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n    proc.communicate()\n    return proc.wait() == 0\n\n\ndef _get_current_sha():\n\n    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'],\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 = \"remote.%s.url\" % remote_name\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 gh_deploy(config, message=None):\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    if message is None:\n        sha = _get_current_sha()\n        message = default_message.format(version=mkdocs.__version__, sha=sha)\n\n    remote_branch = config['remote_branch']\n    remote_name = config['remote_name']\n\n    log.info(\"Copying '%s' to '%s' branch and pushing to GitHub.\",\n             config['site_dir'], config['remote_branch'])\n\n    ghp_import.ghp_import(config['site_dir'], message, remote_name,\n                          remote_branch)\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('Based on your CNAME file, your documentation should be '\n                 'available shortly at: http://%s', 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 = 'http://%s.github.io/%s' % (username, repo)\n        log.info('Your documentation should shortly be available at: ' + url)\n", "path": "mkdocs/commands/gh_deploy.py"}], "after_files": [{"content": "#! /usr/bin/env python\n#\n# This file is part of the ghp-import package released under\n# the Tumbolia Public License.\n\n#                            Tumbolia Public License\n\n# Copyright 2013, Paul Davis <paul.joseph.davis@gmail.com>\n\n# Copying and distribution of this file, with or without modification, are\n# permitted in any medium without royalty provided the copyright notice and this\n# notice are preserved.\n\n# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n#   0. opan saurce LOL\n\nfrom __future__ import unicode_literals\n\nimport errno\nimport logging\nimport os\nimport subprocess as sp\nimport sys\nimport time\nimport unicodedata\n\nlog = logging.getLogger(__name__)\n\n\nif sys.version_info[0] == 3:\n    def enc(text):\n        if isinstance(text, bytes):\n            return text\n        return text.encode()\n\n    def dec(text):\n        if isinstance(text, bytes):\n            return text.decode('utf-8')\n        return text\n\n    def write(pipe, data):\n        try:\n            pipe.stdin.write(data)\n        except IOError as e:\n            if e.errno != errno.EPIPE:\n                raise\nelse:\n    def enc(text):\n        if isinstance(text, unicode):\n            return text.encode('utf-8')\n        return text\n\n    def dec(text):\n        if isinstance(text, unicode):\n            return text\n        return text.decode('utf-8')\n\n    def write(pipe, data):\n        pipe.stdin.write(data)\n\n\ndef normalize_path(path):\n    # Fix unicode pathnames on OS X\n    # See: http://stackoverflow.com/a/5582439/44289\n    if sys.platform == \"darwin\":\n        return unicodedata.normalize(\"NFKC\", dec(path))\n    return path\n\n\ndef try_rebase(remote, branch):\n    cmd = ['git', 'rev-list', '--max-count=1', '%s/%s' % (remote, branch)]\n    p = sp.Popen(cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)\n    (rev, _) = p.communicate()\n    if p.wait() != 0:\n        return True\n    cmd = ['git', 'update-ref', 'refs/heads/%s' % branch, dec(rev.strip())]\n    if sp.call(cmd) != 0:\n        return False\n    return True\n\n\ndef get_config(key):\n    p = sp.Popen(['git', 'config', key], stdin=sp.PIPE, stdout=sp.PIPE)\n    (value, _) = p.communicate()\n    return value.decode('utf-8').strip()\n\n\ndef get_prev_commit(branch):\n    cmd = ['git', 'rev-list', '--max-count=1', branch, '--']\n    p = sp.Popen(cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE)\n    (rev, _) = p.communicate()\n    if p.wait() != 0:\n        return None\n    return rev.decode('utf-8').strip()\n\n\ndef mk_when(timestamp=None):\n    if timestamp is None:\n        timestamp = int(time.time())\n    currtz = \"%+05d\" % (-1 * time.timezone / 36)  # / 3600 * 100\n    return \"%s %s\" % (timestamp, currtz)\n\n\ndef start_commit(pipe, branch, message):\n    uname = dec(get_config(\"user.name\"))\n    email = dec(get_config(\"user.email\"))\n    write(pipe, enc('commit refs/heads/%s\\n' % branch))\n    write(pipe, enc('committer %s <%s> %s\\n' % (uname, email, mk_when())))\n    write(pipe, enc('data %d\\n%s\\n' % (len(message), message)))\n    head = get_prev_commit(branch)\n    if head:\n        write(pipe, enc('from %s\\n' % head))\n    write(pipe, enc('deleteall\\n'))\n\n\ndef add_file(pipe, srcpath, tgtpath):\n    with open(srcpath, \"rb\") as handle:\n        if os.access(srcpath, os.X_OK):\n            write(pipe, enc('M 100755 inline %s\\n' % tgtpath))\n        else:\n            write(pipe, enc('M 100644 inline %s\\n' % tgtpath))\n        data = handle.read()\n        write(pipe, enc('data %d\\n' % len(data)))\n        write(pipe, enc(data))\n        write(pipe, enc('\\n'))\n\n\ndef add_nojekyll(pipe):\n    write(pipe, enc('M 100644 inline .nojekyll\\n'))\n    write(pipe, enc('data 0\\n'))\n    write(pipe, enc('\\n'))\n\n\ndef gitpath(fname):\n    norm = os.path.normpath(fname)\n    return \"/\".join(norm.split(os.path.sep))\n\n\ndef run_import(srcdir, branch, message, nojekyll):\n    cmd = ['git', 'fast-import', '--date-format=raw', '--quiet']\n    kwargs = {\"stdin\": sp.PIPE}\n    if sys.version_info >= (3, 2, 0):\n        kwargs[\"universal_newlines\"] = False\n    pipe = sp.Popen(cmd, **kwargs)\n    start_commit(pipe, branch, message)\n    for path, _, fnames in os.walk(srcdir):\n        for fn in fnames:\n            fpath = os.path.join(path, fn)\n            fpath = normalize_path(fpath)\n            gpath = gitpath(os.path.relpath(fpath, start=srcdir))\n            add_file(pipe, fpath, gpath)\n    if nojekyll:\n        add_nojekyll(pipe)\n    write(pipe, enc('\\n'))\n    pipe.stdin.close()\n    if pipe.wait() != 0:\n        sys.stdout.write(enc(\"Failed to process commit.\\n\"))\n\n\ndef ghp_import(directory, message, remote='origin', branch='gh-pages'):\n\n    if not try_rebase(remote, branch):\n        log.error(\"Failed to rebase %s branch.\", branch)\n\n    nojekyll = True\n\n    run_import(directory, branch, message, nojekyll)\n\n    proc = sp.Popen(['git', 'push', remote, branch],\n                    stdout=sp.PIPE, stderr=sp.PIPE)\n\n    out, err = proc.communicate()\n    result = proc.wait() == 0\n\n    return result, dec(err)\n", "path": "mkdocs/utils/ghp_import.py"}, {"content": "from __future__ import unicode_literals\nimport logging\nimport subprocess\nimport os\n\nimport mkdocs\nfrom mkdocs.utils import ghp_import\n\nlog = logging.getLogger(__name__)\n\ndefault_message = \"\"\"Deployed {sha} with MkDocs version: {version}\"\"\"\n\n\ndef _is_cwd_git_repo():\n    proc = subprocess.Popen(['git', 'rev-parse', '--is-inside-work-tree'],\n                            stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n    proc.communicate()\n    return proc.wait() == 0\n\n\ndef _get_current_sha():\n\n    proc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'],\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 = \"remote.%s.url\" % remote_name\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 gh_deploy(config, message=None):\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    if message is None:\n        sha = _get_current_sha()\n        message = default_message.format(version=mkdocs.__version__, sha=sha)\n\n    remote_branch = config['remote_branch']\n    remote_name = config['remote_name']\n\n    log.info(\"Copying '%s' to '%s' branch and pushing to GitHub.\",\n             config['site_dir'], config['remote_branch'])\n\n    result, error = ghp_import.ghp_import(config['site_dir'], message, remote_name,\n                                          remote_branch)\n    if not result:\n        log.error(\"Failed to deploy to GitHub with error: \\n%s\", error)\n        raise SystemExit(1)\n    else:\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('Based on your CNAME file, your documentation should be '\n                     'available shortly at: http://%s', 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 = 'http://%s.github.io/%s' % (username, repo)\n            log.info('Your documentation should shortly be available at: ' + url)\n", "path": "mkdocs/commands/gh_deploy.py"}]}