@@ -23,6 +23,7 @@ - (nullable NSString *)patchWithFileHeader:(NSArray<NSString *> *)fileHeader
2323 hunkLines : (NSArray <NSString *> *)hunkLines
2424 selectedIndexes : (NSIndexSet *)selectedIndexes
2525 reverse : (BOOL )reverse ;
26+ - (NSString *)pathForDiffHeaderAtIndex : (NSUInteger )headerIndex lines : (NSArray <NSString *> *)lines ;
2627@end
2728
2829@interface GitXTestRepository : NSObject
@@ -423,6 +424,29 @@ - (void)testCommitGraphDecoratesMergeHistory
423424 XCTAssertGreaterThanOrEqual (maximumColumns, 2 , @" A merge should use at least two graph lanes" );
424425}
425426
427+ - (void )testUnchangedSymlinkRenameUsesRenameMetadata
428+ {
429+ NSError *error = nil ;
430+ NSString *oldPath = [self .fixture.path stringByAppendingPathComponent: @" linked.json" ];
431+ NSString *newPath = [self .fixture.path stringByAppendingPathComponent: @" moved-link.json" ];
432+ XCTAssertTrue ([[NSFileManager defaultManager ] createSymbolicLinkAtPath: oldPath withDestinationPath: @" tracked.txt" error: &error], @" %@ " , error);
433+ XCTAssertTrue ([self .fixture commitAllWithMessage: @" add symlink" error: &error], @" %@ " , error);
434+ XCTAssertTrue ([[NSFileManager defaultManager ] moveItemAtPath: oldPath toPath: newPath error: &error], @" %@ " , error);
435+ XCTAssertTrue ([self .fixture commitAllWithMessage: @" rename symlink" error: &error], @" %@ " , error);
436+
437+ NSString *diff = [self .fixture git: @[ @" diff" , @" --find-renames" , @" --no-ext-diff" , @" HEAD^" , @" HEAD" ] error: &error];
438+ XCTAssertNotNil (diff, @" %@ " , error);
439+ XCTAssertTrue ([diff containsString: @" similarity index 100%" ]);
440+ XCTAssertTrue ([diff containsString: @" rename from linked.json" ]);
441+ XCTAssertTrue ([diff containsString: @" rename to moved-link.json" ]);
442+ XCTAssertFalse ([diff containsString: @" deleted file mode" ]);
443+ XCTAssertFalse ([diff containsString: @" new file mode" ]);
444+
445+ PBNativeContentView *view = [[PBNativeContentView alloc ] initWithFrame: NSMakeRect (0 , 0 , 500 , 300 )];
446+ NSArray <NSString *> *lines = [diff componentsSeparatedByString: @" \n " ];
447+ XCTAssertEqualObjects ([view pathForDiffHeaderAtIndex: 0 lines: lines], @" moved-link.json" );
448+ }
449+
426450@end
427451
428452
@@ -511,6 +535,39 @@ - (void)testRefreshRepresentsPartiallyStagedFileInBothSections
511535 XCTAssertTrue ([unstagedDiff containsString: @" +unstaged line" ]);
512536}
513537
538+ - (void )testRefreshDistinguishesPartiallyStagedAdditionFromUntrackedFile
539+ {
540+ NSError *error = nil ;
541+ NSString *partiallyStagedPath = @" folder/spaced ünicode.txt" ;
542+ XCTAssertTrue ([self .fixture writeText: @" first staged line\n " toPath: partiallyStagedPath error: &error], @" %@ " , error);
543+ XCTAssertNotNil (([self .fixture git: @[ @" add" , @" --" , partiallyStagedPath ] error: &error]), @" %@ " , error);
544+ XCTAssertTrue ([self .fixture writeText: @" first staged line\n second unstaged line\n " toPath: partiallyStagedPath error: &error], @" %@ " , error);
545+ XCTAssertTrue ([self .fixture writeText: @" never staged\n " toPath: @" untracked.txt" error: &error], @" %@ " , error);
546+ [self refreshIndexAfterPerforming: ^{
547+ [self .repository.index refresh ];
548+ }];
549+
550+ PBChangedFile *partiallyStaged = [self changedFileAtPath: partiallyStagedPath];
551+ XCTAssertNotNil (partiallyStaged);
552+ XCTAssertEqual (partiallyStaged.status , NEW );
553+ XCTAssertTrue (partiallyStaged.hasStagedChanges );
554+ XCTAssertTrue (partiallyStaged.hasUnstagedChanges );
555+
556+ PBChangedFile *untracked = [self changedFileAtPath: @" untracked.txt" ];
557+ XCTAssertNotNil (untracked);
558+ XCTAssertEqual (untracked.status , NEW );
559+ XCTAssertFalse (untracked.hasStagedChanges );
560+ XCTAssertTrue (untracked.hasUnstagedChanges );
561+ XCTAssertEqualObjects ([self .repository.index diffForFile: untracked staged: NO contextLines: 3 ], @" never staged\n " );
562+
563+ NSString *cached = [self .fixture git: @[ @" diff" , @" --cached" , @" --" , partiallyStagedPath ] error: &error];
564+ NSString *working = [self .fixture git: @[ @" diff" , @" --" , partiallyStagedPath ] error: &error];
565+ XCTAssertTrue ([cached containsString: @" +first staged line" ]);
566+ XCTAssertFalse ([cached containsString: @" second unstaged line" ]);
567+ XCTAssertTrue ([working containsString: @" first staged line" ]);
568+ XCTAssertTrue ([working containsString: @" +second unstaged line" ]);
569+ }
570+
514571- (void )testWholeFileUnstageAfterPartialStageIgnoresStaleIndexMetadata
515572{
516573 NSError *error = nil ;
0 commit comments