Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow tests with shallow clone of source repository #1365

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package hudson.plugins.git.browser;

import hudson.EnvVars;
import hudson.model.TaskListener;
import hudson.plugins.git.GitChangeSet;
import hudson.plugins.git.GitChangeSetUtil;
import hudson.plugins.git.GitTool;

import org.eclipse.jgit.lib.ObjectId;

import org.jenkinsci.plugins.gitclient.Git;
import org.jenkinsci.plugins.gitclient.GitClient;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -40,6 +47,8 @@ public GitRepositoryBrowserTest(String useAuthorName, String gitImplementation,
this.sha1 = sha1;
}

private static final ObjectId HEAD = getMostRecentCommit();

@Parameterized.Parameters(name = "{0},{1},{2}")
public static Collection permuteAuthorNameAndGitImplementationAndObjectId() {
List<Object[]> values = new ArrayList<>();
Expand All @@ -55,15 +64,35 @@ public static Collection permuteAuthorNameAndGitImplementationAndObjectId() {
};
for (String authorName : allowed) {
for (String gitImplementation : implementations) {
for (ObjectId sha1 : sha1Array) {
Object[] combination = {authorName, gitImplementation, sha1};
values.add(combination);
Object[] headCommitCombination = {authorName, gitImplementation, HEAD};
values.add(headCommitCombination);
if (!isShallowClone()) {
for (ObjectId sha1 : sha1Array) {
Object[] combination = {authorName, gitImplementation, sha1};
values.add(combination);
}
}
}
}
return values;
}

private static boolean isShallowClone() {
File shallowFile = new File(".git", "shallow");
return shallowFile.isFile();
}

private static ObjectId getMostRecentCommit() {
ObjectId headCommit;
try {
GitClient git = Git.with(TaskListener.NULL, new EnvVars()).getClient();
headCommit = git.revParse("HEAD");
} catch (IOException | InterruptedException e) {
headCommit = ObjectId.fromString("016407404eeda093385ba2ebe9557068b519b669"); // simple commit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
return headCommit;
}

@Before
public void setUp() throws IOException, InterruptedException {
browser = new GitRepositoryBrowserImpl(null);
Expand Down