use of jetbrains.buildServer.vcs.RepositoryStateData in project teamcity-git by JetBrains.
the class MapFullPathTest method bulk.
public void bulk() throws Exception {
// clone repository for myRoot and root3
RepositoryStateData state0 = RepositoryStateData.createSingleVersionState("a7274ca8e024d98c7d59874f19f21d26ee31d41d");
RepositoryStateData state1 = myGit.getCurrentState(myRoot);
myGit.getCollectChangesPolicy().collectChanges(myRoot, state0, state1, CheckoutRules.DEFAULT);
// tracks same repo as myRoot1
VcsRoot root3 = vcsRoot().withId(3).withFetchUrl(myRemoteRepositoryDir.getAbsolutePath()).build();
// tracks same repo as myRoot2
VcsRoot root4 = vcsRoot().withId(4).withFetchUrl(myRemoteRepositoryDir2.getAbsolutePath()).build();
List<Boolean> result = myGit.checkSuitable(asList(new VcsRootEntry(myRoot, new CheckoutRules("-:dir1")), new VcsRootEntry(myRoot, new CheckoutRules("+:dir1")), new VcsRootEntry(myRoot, new CheckoutRules("+:dir2")), new VcsRootEntry(myRoot2, new CheckoutRules("+:dir2")), new VcsRootEntry(root3, new CheckoutRules("+:dir1")), new VcsRootEntry(root4, new CheckoutRules("+:dir4")), new VcsRootEntry(root3, new CheckoutRules("+:dir5")), new VcsRootEntry(root4, new CheckoutRules("+:dir6"))), asList(// affects root and root3
"a7274ca8e024d98c7d59874f19f21d26ee31d41d-add81050184d3c818560bdd8839f50024c188586||dir1/text1.txt", // affects no repo
"abababababababababababababababababababab||."));
then(result).containsExactly(false, true, false, false, true, false, false, false);
}
use of jetbrains.buildServer.vcs.RepositoryStateData in project teamcity-git by JetBrains.
the class GitLabelingSupport method tag.
@Override
@NotNull
public String tag(@NotNull OperationContext context, @NotNull String label, @NotNull String version) throws VcsException {
GitVcsRoot gitRoot = context.getGitRoot();
RevisionsInfo revisionsInfo = new RevisionsInfo();
if (myConfig.useTagPackHeuristics()) {
LOG.debug("Update repository before labeling " + gitRoot.debugInfo());
RepositoryStateData currentState = myVcs.getCurrentState(gitRoot);
if (!myConfig.analyzeTagsInPackHeuristics())
currentState = excludeTags(currentState);
try {
myVcs.getCollectChangesPolicy().ensureRepositoryStateLoadedFor(context, currentState, false);
} catch (Exception e) {
LOG.debug("Error while updating repository " + gitRoot.debugInfo(), e);
}
revisionsInfo = new RevisionsInfo(currentState);
}
try {
long start = System.currentTimeMillis();
Repository r = context.getRepository();
String commitSHA = GitUtils.versionRevision(version);
RevCommit commit = myCommitLoader.loadCommit(context, gitRoot, commitSHA);
Git git = new Git(r);
Ref tagRef = git.tag().setTagger(PersonIdentFactory.getTagger(gitRoot, r)).setName(label).setObjectId(commit).setForceUpdate(true).call();
if (tagRef.getObjectId() == null || resolve(r, tagRef) == null) {
LOG.warn("Tag's " + tagRef.getName() + " objectId " + (tagRef.getObjectId() != null ? tagRef.getObjectId().name() + " " : "") + "cannot be resolved");
} else if (LOG.isDebugEnabled()) {
LOG.debug("Tag created " + label + "=" + version + " for " + gitRoot.debugInfo() + " in " + (System.currentTimeMillis() - start) + "ms");
}
return push(label, version, gitRoot, r, tagRef, revisionsInfo);
} catch (Exception e) {
throw context.wrapException(e);
}
}
use of jetbrains.buildServer.vcs.RepositoryStateData in project teamcity-git by JetBrains.
the class MapFullPathTest method mapFullPath_should_report_up_to_date_info.
@TestFor(issues = "TW-21185")
@Test
public void mapFullPath_should_report_up_to_date_info() throws Exception {
RepositoryStateData state0 = RepositoryStateData.createSingleVersionState("a7274ca8e024d98c7d59874f19f21d26ee31d41d");
RepositoryStateData state1 = myGit.getCurrentState(myRoot);
myGit.getCollectChangesPolicy().collectChanges(myRoot, state0, state1, CheckoutRules.DEFAULT);
Collection<String> paths = myGit.mapFullPath(myRootEntry, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168||.");
assertTrue(paths.isEmpty());
paths = myGit.mapFullPath(myRootEntry, "252771029d6ac61aaa78d282d5818d210812a4e5||.");
assertTrue(paths.isEmpty());
remoteRepositoryUpdated();
RepositoryStateData state2 = myGit.getCurrentState(myRoot);
// now we have d47dda159b27b9a8c4cee4ce98e4435eb5b17168
myGit.getCollectChangesPolicy().collectChanges(myRoot, state1, state2, CheckoutRules.DEFAULT);
paths = myGit.mapFullPath(myRootEntry, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168||.");
assertFalse("mapFullPath returns outdated info", paths.isEmpty());
paths = myGit.mapFullPath(myRootEntry, "252771029d6ac61aaa78d282d5818d210812a4e5||.");
assertFalse("mapFullPath returns outdated info", paths.isEmpty());
}
use of jetbrains.buildServer.vcs.RepositoryStateData in project teamcity-git by JetBrains.
the class MapFullPathTest method fetchAction.
@DataProvider
public Object[][] fetchAction() {
return new Object[][] { new Object[] { new FetchAction("collect changes") {
@Override
public void run() throws Exception {
RepositoryStateData state0 = RepositoryStateData.createSingleVersionState("9ef3a588831557040e81e4063ecf27d5442837f4");
RepositoryStateData state1 = myGit.getCurrentState(myRoot);
myGit.getCollectChangesPolicy().collectChanges(myRoot, state0, state1, CheckoutRules.DEFAULT);
}
} }, new Object[] { new FetchAction("build patch") {
@Override
public void run() throws Exception {
ByteArrayOutputStream output = new ByteArrayOutputStream();
PatchBuilderImpl builder = new PatchBuilderImpl(output);
myGit.buildPatch(myRoot, null, "add81050184d3c818560bdd8839f50024c188586", builder, CheckoutRules.DEFAULT);
}
} }, new Object[] { new FetchAction("get content") {
@Override
public void run() throws Exception {
myGit.getContentProvider().getContent("readme", myRoot, "add81050184d3c818560bdd8839f50024c188586");
}
} } };
}
use of jetbrains.buildServer.vcs.RepositoryStateData in project teamcity-git by JetBrains.
the class MapFullPathTest method should_not_do_unnecessary_commit_lookup_after_fetch.
public void should_not_do_unnecessary_commit_lookup_after_fetch() throws Exception {
final String existingCommit = "a7274ca8e024d98c7d59874f19f21d26ee31d41d";
final String nonExistingCommit = "abababababababababababababababababababab";
final CommitLoader commitLoader = myContext.mock(CommitLoader.class);
final RevCommit commit = myContext.mock(RevCommit.class);
myMapFullPath.setCommitLoader(commitLoader);
myContext.checking(new Expectations() {
{
// ask for existing commit only once:
one(commitLoader).findCommit(with(any(Repository.class)), with(existingCommit));
will(returnValue(commit));
one(commitLoader).findCommit(with(any(Repository.class)), with(nonExistingCommit));
will(returnValue(null));
}
});
RepositoryStateData state0 = RepositoryStateData.createSingleVersionState("a7274ca8e024d98c7d59874f19f21d26ee31d41d");
RepositoryStateData state1 = myGit.getCurrentState(myRoot);
// fetch repository, so mapFullPath works
myGit.getCollectChangesPolicy().collectChanges(myRoot, state0, state1, CheckoutRules.DEFAULT);
OperationContext context = myGit.createContext(myRoot, "map full path");
myMapFullPath.mapFullPath(context, myRootEntry, existingCommit + "||.");
myMapFullPath.mapFullPath(context, myRootEntry, nonExistingCommit + "||.");
remoteRepositoryUpdated();
RepositoryStateData state2 = myGit.getCurrentState(myRoot);
// this fetch should not cause new commit lookup
myGit.getCollectChangesPolicy().collectChanges(myRoot, state1, state2, CheckoutRules.DEFAULT);
myGit.mapFullPath(myRootEntry, existingCommit + "||.");
myGit.mapFullPath(myRootEntry, nonExistingCommit + "||.");
myContext.assertIsSatisfied();
}
Aggregations