-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2196] Use git blame line info for aggregate blame author modified a…
…nd date info (#2232) `aggregateBlameAuthorModifiedAndDateInfo` is hard to maintain, due to complex string wrangling and seemingly magic numbers. Let's fix these using `GitBlameLineInfo` introduced in #2140. - Use blameLine to abstract away the string wrangling and improve understandability. Magic numbers are also replaced to improve code quality. - In order to use blameLine however, it is also changed to use author-time instead of commit-time, as there is a discrepancy between the two, causing some test cases to fail. - The naming of the timestamp field in GitBlameLineInfo is changed to reflect that it is in seconds, as author-time is in seconds.
- Loading branch information
1 parent
33df258
commit e53c52c
Showing
5 changed files
with
121 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package reposense.git; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
|
@@ -78,4 +80,50 @@ public void blameLine_nonExistentLine_throwsRunTimeException() { | |
Assertions.assertThrows(RuntimeException.class, () -> GitBlame.blameLine(config.getRepoRoot(), | ||
FAKE_AUTHOR_BLAME_TEST_FILE_COMMIT_08022018_STRING, "blameTest.java", 5)); | ||
} | ||
|
||
@Test | ||
public void blameFile_validFile_success() { | ||
List<GitBlameLineInfo> expectedLineInfos = new ArrayList<>(); | ||
expectedLineInfos.add(new GitBlameLineInfo("8d0ac2ee20f04dce8df0591caed460bffacb65a4", | ||
MAIN_AUTHOR_NAME, "[email protected]", 1517863105)); | ||
expectedLineInfos.add(new GitBlameLineInfo("8d0ac2ee20f04dce8df0591caed460bffacb65a4", | ||
MAIN_AUTHOR_NAME, "[email protected]", 1517863105)); | ||
expectedLineInfos.add(new GitBlameLineInfo("768015345e70f06add2a8b7d1f901dc07bf70582", | ||
FAKE_AUTHOR_NAME, "[email protected]", 1518085550)); | ||
expectedLineInfos.add(new GitBlameLineInfo("8d0ac2ee20f04dce8df0591caed460bffacb65a4", | ||
MAIN_AUTHOR_NAME, "[email protected]", 1517863105)); | ||
List<GitBlameLineInfo> actualLineInfos = GitBlame.blameFile(config.getRepoRoot(), "blameTest.java", false); | ||
Assertions.assertEquals(expectedLineInfos, actualLineInfos); | ||
} | ||
|
||
@Test | ||
public void blameFile_validFileWithPreviousAuthors_success() { | ||
config.setBranch(TEST_REPO_BLAME_WITH_PREVIOUS_AUTHORS_BRANCH); | ||
GitCheckout.checkoutBranch(config.getRepoRoot(), TEST_REPO_BLAME_WITH_PREVIOUS_AUTHORS_BRANCH); | ||
createTestIgnoreRevsFile(AUTHOR_TO_IGNORE_BLAME_COMMIT_LIST_07082021); | ||
|
||
List<GitBlameLineInfo> expectedLineInfos = new ArrayList<>(); | ||
expectedLineInfos.add(new GitBlameLineInfo("8d0ac2ee20f04dce8df0591caed460bffacb65a4", | ||
MAIN_AUTHOR_NAME, "[email protected]", 1517863105)); | ||
expectedLineInfos.add(new GitBlameLineInfo("8d0ac2ee20f04dce8df0591caed460bffacb65a4", | ||
MAIN_AUTHOR_NAME, "[email protected]", 1517863105)); | ||
expectedLineInfos.add(new GitBlameLineInfo("768015345e70f06add2a8b7d1f901dc07bf70582", | ||
FAKE_AUTHOR_NAME, "[email protected]", 1518085550)); | ||
expectedLineInfos.add(new GitBlameLineInfo("8d0ac2ee20f04dce8df0591caed460bffacb65a4", | ||
MAIN_AUTHOR_NAME, "[email protected]", 1517863105)); | ||
List<GitBlameLineInfo> actualLineInfos = GitBlame.blameFile(config.getRepoRoot(), "blameTest.java", true); | ||
Assertions.assertEquals(expectedLineInfos, actualLineInfos); | ||
} | ||
|
||
@Test | ||
public void blameFile_nonExistentFile_throwsRunTimeException() { | ||
Assertions.assertThrows(RuntimeException.class, () -> GitBlame.blameFile(config.getRepoRoot(), | ||
"nonExistentFile", false)); | ||
} | ||
|
||
@Test | ||
public void blameFile_nonExistentFileWithPreviousAuthors_throwsRunTimeException() { | ||
Assertions.assertThrows(RuntimeException.class, () -> GitBlame.blameFile(config.getRepoRoot(), | ||
"nonExistentFile", true)); | ||
} | ||
} |