From 0fcf6877f750e0f50ba2ab2197b363cd5d3612bc Mon Sep 17 00:00:00 2001 From: Mattias Granlund Date: Fri, 5 Jan 2024 11:30:56 +0100 Subject: [PATCH] Fix file status determination - this broke when we stopped loading full file contents --- gitbutler-ui/src/lib/vbranches/fileStatus.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gitbutler-ui/src/lib/vbranches/fileStatus.ts b/gitbutler-ui/src/lib/vbranches/fileStatus.ts index a4f111638..901cea5cb 100644 --- a/gitbutler-ui/src/lib/vbranches/fileStatus.ts +++ b/gitbutler-ui/src/lib/vbranches/fileStatus.ts @@ -16,8 +16,10 @@ export function computedAddedRemoved(...files: File[]) { } export function computeFileStatus(file: File): FileStatus { - const { added, removed } = computedAddedRemoved(file); - // TODO: How should we handle this for binary files? See: https://git-scm.com/docs/git-status - const contentLineCount = file.content?.trim().split('\n').length; - return added == contentLineCount ? 'A' : removed == contentLineCount ? 'D' : 'M'; + if (file.hunks.length == 1) { + const diff = file.hunks[0].diff; + if (/^@@ -0,0 /.test(diff)) return 'A'; + if (/^@@ -\d+,\d+ \+0,0/.test(diff)) return 'D'; + } + return 'M'; }