From 8cdf70ac123b26d2234014bce344332f9b0787b3 Mon Sep 17 00:00:00 2001 From: Miguel Molina Date: Mon, 4 May 2020 09:14:42 +0200 Subject: plumbing: exact renames detection could leave gaps in the changes This fixes an issue where exact renames detection could leave gaps with nil changes in the added and deleted change slices. That could lead to panics in the content rename detection and others if the user had set OnlyExact to true. Signed-off-by: Miguel Molina --- plumbing/object/rename_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'plumbing/object/rename_test.go') diff --git a/plumbing/object/rename_test.go b/plumbing/object/rename_test.go index bf5044d..5dd77e8 100644 --- a/plumbing/object/rename_test.go +++ b/plumbing/object/rename_test.go @@ -271,6 +271,32 @@ func (s *RenameSuite) TestRenameLimit(c *C) { } } +func (s *RenameSuite) TestRenameExactManyAddsManyDeletesNoGaps(c *C) { + content := "a" + detector := &renameDetector{ + added: []*Change{ + makeAdd(c, makeFile(c, pathA, filemode.Regular, content)), + makeAdd(c, makeFile(c, pathQ, filemode.Regular, content)), + makeAdd(c, makeFile(c, "something", filemode.Regular, content)), + }, + deleted: []*Change{ + makeDelete(c, makeFile(c, pathA, filemode.Regular, content)), + makeDelete(c, makeFile(c, pathB, filemode.Regular, content)), + makeDelete(c, makeFile(c, "foo/bar/other", filemode.Regular, content)), + }, + } + + detector.detectExactRenames() + + for _, added := range detector.added { + c.Assert(added, NotNil) + } + + for _, deleted := range detector.deleted { + c.Assert(deleted, NotNil) + } +} + func detectRenames(c *C, changes Changes, opts *DiffTreeOptions, expectedResults int) Changes { result, err := DetectRenames(changes, opts) c.Assert(err, IsNil) -- cgit