Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions GitUpKit/Core/GCIndex.m
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ - (BOOL)addFileInWorkingDirectory:(NSString*)path toIndex:(GCIndex*)index error:
- (BOOL)addLinesInWorkingDirectoryFile:(NSString*)path toIndex:(GCIndex*)index error:(NSError**)error usingFilter:(GCIndexLineFilter)filter {
const char* filePath = GCGitPathFromFileSystemPath(path);

// If the file is already in the index, preserve the entry, otherwise create a new entry from the file metadata
// If the file is already in the index, mutate the entry, otherwise create a new entry from the file metadata
git_index_entry entry;
const git_index_entry* entryPtr = git_index_get_bypath(index.private, filePath, 0);
if (entryPtr == NULL) {
Expand All @@ -367,6 +367,11 @@ - (BOOL)addLinesInWorkingDirectoryFile:(NSString*)path toIndex:(GCIndex*)index e
entry.path = filePath;
git_index_entry__init_from_stat(&entry, &info, true);
entryPtr = &entry;
} else {
// Null out the entry's modification date: otherwise Git might assume the file is unchanged from the on-disk version, and produce incorrect diffs
bcopy(entryPtr, &entry, sizeof(git_index_entry));
entry.mtime = (git_index_time){.seconds = 0, .nanoseconds = 0};
entryPtr = &entry;
}
NSMutableData* data = [[NSMutableData alloc] initWithCapacity:(1024 * 1024)];

Expand Down Expand Up @@ -453,7 +458,7 @@ - (BOOL)resetFile:(NSString*)path inIndex:(GCIndex*)index toCommit:(GCCommit*)co
- (BOOL)resetLinesInFile:(NSString*)path index:(GCIndex*)index toCommit:(GCCommit*)commit error:(NSError**)error usingFilter:(GCIndexLineFilter)filter {
const char* filePath = GCGitPathFromFileSystemPath(path);

// If the file is already in the index, preserve the entry, otherwise create a new entry from the file blob
// If the file is already in the index, mutate the entry, otherwise create a new entry from the file blob
git_index_entry entry;
const git_index_entry* entryPtr = git_index_get_bypath(index.private, filePath, 0);
if (entryPtr == NULL) {
Expand All @@ -468,6 +473,11 @@ - (BOOL)resetLinesInFile:(NSString*)path index:(GCIndex*)index toCommit:(GCCommi
entry.mode = git_tree_entry_filemode(treeEntry);
entryPtr = &entry;
git_tree_entry_free(treeEntry);
} else {
// Null out the entry's modification date: otherwise Git might assume the file is unchanged from the on-disk version, and produce incorrect diffs
bcopy(entryPtr, &entry, sizeof(git_index_entry));
entry.mtime = (git_index_time){.seconds = 0, .nanoseconds = 0};
entryPtr = &entry;
}
NSMutableData* data = [[NSMutableData alloc] initWithCapacity:(1024 * 1024)];

Expand Down