2525import static org .hamcrest .CoreMatchers .is ;
2626import static org .hamcrest .Matchers .*;
2727import static org .junit .Assert .*;
28+ import org .junit .ClassRule ;
2829import org .junit .Test ;
2930import org .junit .runner .RunWith ;
3031import org .junit .runners .Parameterized ;
3132
33+ import jenkins .plugins .git .GitSampleRepoRule ;
34+
3235@ RunWith (Parameterized .class )
3336public class GitChangeSetPluginHistoryTest {
3437
@@ -41,19 +44,25 @@ public class GitChangeSetPluginHistoryTest {
4144
4245 private final GitChangeSet changeSet ;
4346
44- private static String gitVersion = "Unknown" ;
47+ @ ClassRule
48+ public static GitSampleRepoRule sampleRepo = new GitSampleRepoRule ();
4549
4650 /* git 1.7.1 on CentOS 6.7 "whatchanged" generates no output for
4751 * the SHA1 hashes (from this repository) in this list. Rather
4852 * than skip testing on that old git version, this exclusion list
4953 * allows most tests to run. Debian 6 / git 1.7.2.5 also has the issue.
5054 */
5155 private static final String [] git171exceptions = {
56+ "6e467b23" ,
5257 "750b6806" ,
5358 "7eeb070b" ,
5459 "87988f4d" ,
60+ "94d982c2" ,
5561 "a571899e" ,
56- "bc71cd2d"
62+ "b9e497b0" ,
63+ "bc71cd2d" ,
64+ "dcd329f4" ,
65+ "edf066f3" ,
5766 };
5867
5968 public GitChangeSetPluginHistoryTest (GitClient git , boolean authorOrCommitter , String sha1String ) throws IOException , InterruptedException {
@@ -66,20 +75,6 @@ public GitChangeSetPluginHistoryTest(GitClient git, boolean authorOrCommitter, S
6675 changeSet = new GitChangeSet (changeLogStrings , authorOrCommitter );
6776 }
6877
69- private static String getGitVersion () throws IOException {
70- Process process = new ProcessBuilder ("git" , "--version" ).start ();
71- String version ;
72- try (BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()))) {
73- version = "unknown" ;
74- String line ;
75- while ((line = reader .readLine ()) != null ) {
76- version = line .trim ();
77- }
78- }
79- process .destroy ();
80- return version ;
81- }
82-
8378 /**
8479 * Merge changes won't compute their date in GitChangeSet, apparently as an
8580 * intentional design choice. Return all changes for this repository which
@@ -116,8 +111,6 @@ private static List<ObjectId> getNonMergeChanges(boolean honorExclusions) throws
116111
117112 @ Parameterized .Parameters (name = "{2}-{1}" )
118113 public static Collection <Object []> generateData () throws IOException , InterruptedException {
119- gitVersion = getGitVersion ();
120-
121114 List <Object []> args = new ArrayList <>();
122115 String [] implementations = new String []{"git" , "jgit" };
123116 boolean [] choices = {true , false };
@@ -126,8 +119,7 @@ public static Collection<Object[]> generateData() throws IOException, Interrupte
126119 EnvVars envVars = new EnvVars ();
127120 TaskListener listener = StreamTaskListener .fromStdout ();
128121 GitClient git = Git .with (listener , envVars ).in (new FilePath (new File ("." ))).using (implementation ).getClient ();
129- boolean honorExclusions = implementation .equals ("git" )
130- && (gitVersion .equals ("git version 1.7.1" ) || gitVersion .equals ("git version 1.7.2.5" ));
122+ boolean honorExclusions = implementation .equals ("git" ) && !sampleRepo .gitVersionAtLeast (1 , 7 , 10 );
131123 List <ObjectId > allNonMergeChanges = getNonMergeChanges (honorExclusions );
132124 int count = allNonMergeChanges .size () / 10 ; /* 10% of all changes */
133125
0 commit comments