From 0a91add3c72342a1e4822e351955aa9145fd936c Mon Sep 17 00:00:00 2001 From: Nathan Manceaux-Panot Date: Thu, 23 Apr 2026 18:21:30 +0200 Subject: [PATCH] Fix crash when staging lines with the index locked These error overrides might have worked at some point? But in my quick tests, now, if the function errors, it'll return a null diff. As a result of the override, the null diff unexpectedly goes in the rest of GUK. IIRC, a GCDiff gets created with it, GCDiff._cacheDeltasIfNeeded tries to allocate an array of capacity -1 (which maps to unsigned int 18446744073709551615) because that's the output of git_diff_num_deltas on a null value, and that crashes. --- GitUpKit/Core/GCDiff.m | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/GitUpKit/Core/GCDiff.m b/GitUpKit/Core/GCDiff.m index b83046a9..02925726 100644 --- a/GitUpKit/Core/GCDiff.m +++ b/GitUpKit/Core/GCDiff.m @@ -560,9 +560,6 @@ - (GCDiff*)diffWorkingDirectoryWithCommit:(GCCommit*)commit git_diff* diff2; diffOptions->flags |= GIT_DIFF_UPDATE_INDEX; status = git_diff_index_to_workdir(&diff2, self.private, index.private, diffOptions); - if (status == GIT_ELOCKED) { - status = GIT_OK; // Passing GIT_DIFF_UPDATE_INDEX means git_diff_index_to_workdir() may attempt to write the index and this could fail if it is currently locked by another process but that's OK to ignore this failure - } if (status == GIT_OK) { status = git_diff_merge(*outDiff, diff2); if (status != GIT_OK) { @@ -599,11 +596,7 @@ - (GCDiff*)diffWorkingDirectoryWithIndex:(GCIndex*)index error:error block:^int(git_diff** outDiff, git_diff_options* diffOptions) { diffOptions->flags |= GIT_DIFF_UPDATE_INDEX; - int status = git_diff_index_to_workdir(outDiff, self.private, index.private, diffOptions); - if (status == GIT_ELOCKED) { - status = GIT_OK; // Passing GIT_DIFF_UPDATE_INDEX means git_diff_index_to_workdir() will attempt to write the index even if there are no changes and this could fail if it is currently locked by another process - } - return status; + return git_diff_index_to_workdir(outDiff, self.private, index.private, diffOptions); }]; }