Skip to content

Commit 82fbfbd

Browse files
committed
Fix #585
1 parent 2787178 commit 82fbfbd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

jupyterlab_git/git.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ async def diff_content(self, filename, prev_ref, curr_ref, top_repo_path):
977977
if curr_ref["special"] == "WORKING":
978978
curr_content = self.get_content(filename, top_repo_path)
979979
elif curr_ref["special"] == "INDEX":
980-
is_binary = await self._is_binary(filename, "", top_repo_path)
980+
is_binary = await self._is_binary(filename, "INDEX", top_repo_path)
981981
if is_binary:
982982
raise tornado.web.HTTPError(log_message="Error occurred while executing command to retrieve plaintext diff as file is not UTF-8.")
983983

@@ -1005,7 +1005,10 @@ async def _is_binary(self, filename, ref, top_repo_path):
10051005
- <https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---numstat>
10061006
- <https://git-scm.com/docs/git-diff#_other_diff_formats>
10071007
"""
1008-
command = ["git", "diff", "--numstat", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", ref, "--", filename] # where 4b825... is a magic SHA which represents the empty tree
1008+
if ref == "INDEX":
1009+
command = ["git", "diff", "--numstat", "--cached", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", "--", filename]
1010+
else:
1011+
command = ["git", "diff", "--numstat", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", ref, "--", filename] # where 4b825... is a magic SHA which represents the empty tree
10091012
code, output, error = await execute(command, cwd=top_repo_path)
10101013

10111014
if code != 0:
@@ -1016,10 +1019,7 @@ async def _is_binary(self, filename, ref, top_repo_path):
10161019
raise tornado.web.HTTPError(log_message="Error while determining if file is binary or text '{}'.".format(error))
10171020

10181021
# For binary files, `--numstat` outputs two `-` characters separated by TABs:
1019-
if output.startswith('-\t-\t'):
1020-
return True
1021-
1022-
return False
1022+
return output.startswith('-\t-\t')
10231023

10241024
def remote_add(self, top_repo_path, url, name=DEFAULT_REMOTE_NAME):
10251025
"""Handle call to `git remote add` command.

0 commit comments

Comments
 (0)