Skip to content

Commit f8623ad

Browse files
committed
Remove old git tests and related conditionals
Red Hat Enterprise Linux 7 includes command line git 1.8. No other supported operating system includes a command line git version older than 2.20. Debian 10 is the oldest command line git version on a supported operating system with command line git 2.20. Ubuntu 20 has a newer command line git version.
1 parent fb5d97c commit f8623ad

File tree

7 files changed

+25
-164
lines changed

7 files changed

+25
-164
lines changed

src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,10 +1499,6 @@ public void execute() throws GitException, InterruptedException {
14991499
}
15001500
if (isAtLeastVersion(1, 8, 4, 0)) {
15011501
args.add("--depth=" + depth);
1502-
} else {
1503-
listener.getLogger()
1504-
.println(
1505-
"[WARNING] Git client older than 1.8.4 doesn't support shallow submodule updates. This flag is ignored.");
15061502
}
15071503
}
15081504

@@ -1749,7 +1745,6 @@ public boolean isBareRepository(String GIT_DIR) throws GitException, Interrupted
17491745

17501746
/**
17511747
* Returns true if this repository is configured as a shallow clone.
1752-
* Shallow clone requires command line git 1.9 or later.
17531748
* @return true if this repository is configured as a shallow clone
17541749
*/
17551750
public boolean isShallowRepository() {
@@ -2932,10 +2927,6 @@ public void execute() throws GitException, InterruptedException {
29322927
args.add("--tags");
29332928
}
29342929

2935-
if (!isAtLeastVersion(1, 9, 0, 0) && isShallowRepository()) {
2936-
throw new GitException("Can't push from shallow repository using git client older than 1.9.0");
2937-
}
2938-
29392930
StandardCredentials cred = credentials.get(remote.toPrivateString());
29402931
if (cred == null) {
29412932
cred = defaultCredentials;

src/main/java/org/jenkinsci/plugins/gitclient/GitClient.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,7 @@ Map<String, ObjectId> getRemoteReferences(String remoteRepoUrl, String pattern,
653653
* @param remoteRepoUrl Remote repository URL.
654654
* @param pattern Only references matching the given pattern are displayed.
655655
* @return a map of reference names and their underlying references. Empty if none or if the remote does not report
656-
* symbolic references (i.e. Git 1.8.4 or earlier) or if the client does not support reporting symbolic references
657-
* (e.g. command line Git prior to 2.8.0).
656+
* symbolic references or if the command line git version does not support reporting symbolic references.
658657
* @throws hudson.plugins.git.GitException if underlying git operation fails.
659658
* @throws java.lang.InterruptedException if interrupted.
660659
*/

src/main/java/org/jenkinsci/plugins/gitclient/SubmoduleUpdateCommand.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public interface SubmoduleUpdateCommand extends GitCommand {
1616
/**
1717
* If set true and if the git version supports it, update the
1818
* submodules to the tip of the branch rather than to a specific
19-
* SHA1. Refer to git documentation for details. First available
20-
* in command line git 1.8.2. Default is to update to a specific
21-
* SHA1 (compatible with previous versions of git)
19+
* SHA1. Refer to git documentation for details. Default is to
20+
* update to a specific SHA1 (compatible with previous versions of
21+
* git)
2222
*
23-
* @param remoteTracking if true, will update the submodule to the tip of the branch requested (requires git&gt;=1.8.2)
23+
* @param remoteTracking if true, will update the submodule to the tip of the branch requested
2424
* @return a {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand} object.
2525
*/
2626
SubmoduleUpdateCommand remoteTracking(boolean remoteTracking);
@@ -63,7 +63,7 @@ public interface SubmoduleUpdateCommand extends GitCommand {
6363
* Only clone the most recent history, not preceding history. Depth of the
6464
* shallow clone is controlled by the #depth method.
6565
*
66-
* @param shallow boolean controlling whether the clone is shallow (requires git&gt;=1.8.4)
66+
* @param shallow boolean controlling whether the clone is shallow
6767
* @return a {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand} object.
6868
*/
6969
SubmoduleUpdateCommand shallow(boolean shallow);
@@ -72,7 +72,7 @@ public interface SubmoduleUpdateCommand extends GitCommand {
7272
* When shallow cloning, allow for a depth to be set in cases where you need more than the immediate last commit.
7373
* Has no effect if shallow is set to false (default).
7474
*
75-
* @param depth number of revisions to be included in shallow clone (requires git&gt;=1.8.4)
75+
* @param depth number of revisions to be included in shallow clone
7676
* @return a {@link org.jenkinsci.plugins.gitclient.SubmoduleUpdateCommand} object.
7777
*/
7878
SubmoduleUpdateCommand depth(Integer depth);

src/test/java/org/jenkinsci/plugins/gitclient/GitAPIForCliGitTest.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.jenkinsci.plugins.gitclient;
22

33
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertFalse;
54
import static org.junit.Assert.assertTrue;
65

76
import hudson.Util;
@@ -156,21 +155,10 @@ public void testPushFromShallowClone() throws Exception {
156155
testGitClient.commit("commit2");
157156
ObjectId sha1 = workspace.head();
158157

159-
try {
160-
testGitClient.push("origin", defaultBranchName);
161-
assertTrue(
162-
"git < 1.9.0 can push from shallow repository",
163-
workspace.cgit().isAtLeastVersion(1, 9, 0, 0));
164-
String remoteSha1 =
165-
remote.launchCommand("git", "rev-parse", defaultBranchName).substring(0, 40);
166-
assertEquals(sha1.name(), remoteSha1);
167-
} catch (GitException ge) {
168-
// expected for git cli < 1.9.0
169-
assertExceptionMessageContains(ge, "push from shallow repository");
170-
assertFalse(
171-
"git >= 1.9.0 can't push from shallow repository",
172-
workspace.cgit().isAtLeastVersion(1, 9, 0, 0));
173-
}
158+
testGitClient.push("origin", defaultBranchName);
159+
String remoteSha1 =
160+
remote.launchCommand("git", "rev-parse", defaultBranchName).substring(0, 40);
161+
assertEquals(sha1.name(), remoteSha1);
174162
}
175163

176164
private void assertExceptionMessageContains(GitException ge, String expectedSubstring) {

src/test/java/org/jenkinsci/plugins/gitclient/GitClientFetchTest.java

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -284,42 +284,18 @@ public void test_fetch() throws Exception {
284284
.getHeadRev(bareWorkspace.getGitFileDir().getAbsolutePath(), defaultBranchName);
285285
assertThat("bare5 != working5", bareCommit5, is(commit5));
286286

287-
/* Fetch into newArea repo with null RefSpec - should only
288-
* pull tags, not commits in git versions prior to git 1.9.0.
289-
* In git 1.9.0, fetch -t pulls tags and versions. */
287+
/* Fetch into newArea repo with null RefSpec. */
290288
newAreaWorkspace.getGitClient().fetch("origin", null, null);
291289
assertThat(
292290
"null refSpec fetch modified local repo",
293291
newAreaWorkspace.getGitClient().revParse("HEAD"),
294292
is(bareCommit4));
295-
ObjectId expectedHead = bareCommit4;
296-
if (gitImplName.startsWith("jgit") || workspace.cgit().isAtLeastVersion(1, 9, 0, 0)) {
297-
newAreaWorkspace
298-
.getGitClient()
299-
.merge()
300-
.setRevisionToMerge(bareCommit5)
301-
.execute();
302-
expectedHead = bareCommit5;
303-
} else {
304-
GitException gitException = assertThrows(GitException.class, () -> newAreaWorkspace
305-
.getGitClient()
306-
.merge()
307-
.setRevisionToMerge(bareCommit5)
308-
.execute());
309-
assertThat(
310-
gitException.getMessage(),
311-
anyOf(
312-
containsString("Could not merge"),
313-
containsString("not something we can merge"),
314-
containsString("does not point to a commit")));
315-
}
316-
/* Assert that expected change is in repo after merge. With
317-
* git 1.7 and 1.8, it should be bareCommit4. With git 1.9
318-
* and later, it should be bareCommit5. */
293+
ObjectId expectedHead = bareCommit5;
294+
newAreaWorkspace.getGitClient().merge().setRevisionToMerge(bareCommit5).execute();
319295
assertThat(
320296
"null refSpec fetch modified local repo",
321297
newAreaWorkspace.getGitClient().revParse("HEAD"),
322-
is(expectedHead));
298+
is(bareCommit5));
323299
}
324300

325301
@Test

src/test/java/org/jenkinsci/plugins/gitclient/GitClientSecurityTest.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ public GitClientSecurityTest(final String badRemoteUrl, final boolean enableRemo
6363
this.enableRemoteCheckUrl = enableRemoteCheckUrl;
6464
}
6565

66-
/* Capabilities of command line git in current environment */
67-
private static final boolean CLI_GIT_SUPPORTS_OPERAND_SEPARATOR;
68-
private static final boolean CLI_GIT_SUPPORTS_SYMREF;
69-
7066
static {
7167
CliGitAPIImpl tempGitClient;
7268
try {
@@ -77,13 +73,6 @@ public GitClientSecurityTest(final String badRemoteUrl, final boolean enableRemo
7773
} catch (Exception e) {
7874
tempGitClient = null;
7975
}
80-
if (tempGitClient != null) {
81-
CLI_GIT_SUPPORTS_OPERAND_SEPARATOR = tempGitClient.isAtLeastVersion(2, 8, 0, 0);
82-
CLI_GIT_SUPPORTS_SYMREF = tempGitClient.isAtLeastVersion(2, 8, 0, 0);
83-
} else {
84-
CLI_GIT_SUPPORTS_OPERAND_SEPARATOR = false;
85-
CLI_GIT_SUPPORTS_SYMREF = false;
86-
}
8776
}
8877

8978
private static final Random CONFIG_RANDOM = new Random();
@@ -100,23 +89,14 @@ public GitClientSecurityTest(final String badRemoteUrl, final boolean enableRemo
10089
*
10190
* This function returns a randomly selected value to enable or
10291
* disable the repository URL check based on the contents of the
103-
* attack string. If remote check is selected to be disabled and
104-
* the command line git implementation does not have full support
105-
* for the '--' separator between options and operands and the
92+
* attack string. If remote check is selected to be disabled and the
10693
* attack is one of a known list of strings, then this function
10794
* will always return 'true' so that the remote checks will be
10895
* enabled.
109-
*
110-
* Returning 'false' in those cases on certain older command line
111-
* git implementations (git 1.8.3 on CentOS 7, git 2.7.4 on Ubuntu
112-
* 16) would cause the tested code to not throw an exception
113-
* because those command line git versions do not fully support
114-
* '--' to separate options and operands.
11596
*/
11697
private static boolean enableRemoteCheck(String attack) {
11798
boolean enabled = CONFIG_RANDOM.nextBoolean();
11899
if (!enabled
119-
&& !CLI_GIT_SUPPORTS_OPERAND_SEPARATOR
120100
&& (attack.equals("-q")
121101
|| attack.equals("--quiet")
122102
|| attack.equals("-t")
@@ -298,9 +278,6 @@ public void testGetRemoteReferences_SECURITY_1534() {
298278
@Test
299279
@Issue("SECURITY-1534")
300280
public void testGetRemoteSymbolicReferences_SECURITY_1534() {
301-
if (!CLI_GIT_SUPPORTS_SYMREF) {
302-
return;
303-
}
304281
String expectedMessage = enableRemoteCheckUrl ? "Invalid remote URL: " + badRemoteUrl : badRemoteUrl.trim();
305282
GitException e = assertThrows(
306283
GitException.class, () -> gitClient.getRemoteSymbolicReferences(badRemoteUrl, DEFAULT_BRANCH_NAME));

0 commit comments

Comments
 (0)