Here are the examples of the java api org.netbeans.libs.git.GitClient.commit() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
126 Examples
19
Source : TagTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testOverwriteTag() throws Exception {
File f = new File(workDir, "f");
File[] files = new File[] { f };
GitClient client = getClient(workDir);
write(f, "init");
GitRevisionInfo commit = client.commit(files, "init commit", null, null, NULL_PROGRESS_MONITOR);
GitTag tag = client.createTag("tag-name", commit.getRevision(), "tag message\nfor tag-name", false, false, NULL_PROGRESS_MONITOR);
replacedertTag(tag, commit.getRevision(), "tag-name", "tag message\nfor tag-name", client.getUser(), GitObjectType.COMMIT, false);
write(f, "modif");
commit = client.commit(files, "change", null, null, NULL_PROGRESS_MONITOR);
try {
tag = client.createTag("tag-name", commit.getRevision(), "second tag message\nfor tag-name", false, false, NULL_PROGRESS_MONITOR);
fail("Tag already exists, should fail");
} catch (GitException ex) {
}
tag = client.createTag("tag-name", commit.getRevision(), "second tag message\nfor tag-name", false, true, NULL_PROGRESS_MONITOR);
replacedertTag(tag, commit.getRevision(), "tag-name", "second tag message\nfor tag-name", client.getUser(), GitObjectType.COMMIT, false);
}
19
Source : TagTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testTagInvalidName() throws Exception {
File f = new File(workDir, "f");
File[] files = new File[] { f };
GitClient client = getClient(workDir);
write(f, "init");
GitRevisionInfo commit = client.commit(files, "init commit", null, null, NULL_PROGRESS_MONITOR);
String name = "tag with spaces";
try {
client.createTag(name, commit.getRevision(), null, false, false, NULL_PROGRESS_MONITOR);
fail("Should fail");
} catch (GitException ex) {
replacedertTrue(ex.getCause() != null);
replacedertTrue(ex.getCause().toString(), ex.getCause() instanceof InvalidTagNameException);
}
}
19
Source : TagTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testCreateTag() throws Exception {
File f = new File(workDir, "f");
File[] files = new File[] { f };
GitClient client = getClient(workDir);
write(f, "init");
GitRevisionInfo commit = client.commit(files, "init commit", null, null, NULL_PROGRESS_MONITOR);
GitTag tag = client.createTag("tag-name", commit.getRevision(), "tag message\nfor tag-name", false, false, NULL_PROGRESS_MONITOR);
replacedertTag(tag, commit.getRevision(), "tag-name", "tag message\nfor tag-name", client.getUser(), GitObjectType.COMMIT, false);
}
19
Source : SetUpstreamBranchTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testRemoteTrackingNoRemoteSet() throws GitException {
GitClient client = getClient(workDir);
File f = new File(workDir, "f");
add(f);
client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR);
// push to remote
String remoteUri = getRemoteRepository().getWorkTree().toURI().toString();
client.push(remoteUri, Arrays.asList("refs/heads/master:refs/heads/master"), Arrays.asList("+refs/heads/*:refs/remotes/origin/*"), NULL_PROGRESS_MONITOR);
Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
replacedertTrue(branches.containsKey("origin/master"));
replacedertNull(branches.get("master").getTrackedBranch());
// set tracking
GitBranch b = client.setUpstreamBranch("master", "origin/master", NULL_PROGRESS_MONITOR);
replacedertEquals("origin/master", b.getTrackedBranch().getName());
Config cfg = repository.getConfig();
replacedertEquals(".", cfg.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE));
replacedertEquals("refs/remotes/origin/master", cfg.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE));
}
19
Source : SetUpstreamBranchTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testLocalTracking() throws GitException {
GitClient client = getClient(workDir);
File f = new File(workDir, "f");
add(f);
client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR);
// prepare twp branches
GitBranch b = client.createBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR);
replacedertNull(b.getTrackedBranch());
// set tracking
b = client.setUpstreamBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR);
replacedertEquals(Constants.MASTER, b.getTrackedBranch().getName());
}
19
Source : SetUpstreamBranchTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testRemoteTracking() throws Exception {
GitClient client = getClient(workDir);
File f = new File(workDir, "f");
add(f);
client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR);
// push to remote
String remoteUri = getRemoteRepository().getWorkTree().toURI().toString();
client.setRemote(new GitRemoteConfig("origin", Arrays.asList(remoteUri), Collections.<String>emptyList(), Arrays.asList("+refs/heads/*:refs/remotes/origin/*"), Collections.<String>emptyList()), NULL_PROGRESS_MONITOR);
client.push("origin", Arrays.asList("refs/heads/master:refs/heads/master"), Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR);
Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
replacedertTrue(branches.containsKey("origin/master"));
replacedertNull(branches.get("master").getTrackedBranch());
StoredConfig config = repository.getConfig();
config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE, ConfigConstants.CONFIG_KEY_NEVER);
config.save();
// set tracking
GitBranch b = client.setUpstreamBranch("master", "origin/master", NULL_PROGRESS_MONITOR);
replacedertEquals("origin/master", b.getTrackedBranch().getName());
config = repository.getConfig();
replacedertEquals("origin", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE));
replacedertEquals("refs/heads/master", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE));
replacedertFalse(config.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REBASE, false));
// change autosetuprebase
config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE, ConfigConstants.CONFIG_KEY_REMOTE);
config.save();
// set tracking
b = client.setUpstreamBranch("master", "origin/master", NULL_PROGRESS_MONITOR);
replacedertEquals("origin/master", b.getTrackedBranch().getName());
config = repository.getConfig();
replacedertEquals("origin", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE));
replacedertEquals("refs/heads/master", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE));
replacedertTrue(config.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REBASE, false));
}
19
Source : RebaseTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testRebaseFailMergeLocalChanges() throws Exception {
File f = new File(workDir, "file");
File f2 = new File(workDir, "file2");
write(f, "init");
write(f2, "init");
add(f, f2);
commit(f, f2);
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
write(f, Constants.MASTER);
add(f);
GitRevisionInfo masterInfo = client.commit(new File[] { f, f2 }, "change on master", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f, BRANCH_NAME);
add(f);
GitRevisionInfo branchInfo = client.commit(new File[] { f, f2 }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
write(f2, "local change");
add(f2);
GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, Constants.MASTER, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.FAILED, result.getRebaseStatus());
replacedertEquals(Arrays.asList(f2), result.getFailures());
replacedertEquals(branchInfo.getRevision(), getRepository(client).resolve(BRANCH_NAME).name());
replacedertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name());
// resets HEAD
replacedertEquals(branchInfo.getRevision(), getRepository(client).resolve(Constants.HEAD).name());
}
19
Source : RebaseTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testRebaseNoChange() throws Exception {
File f = new File(workDir, "file");
write(f, "init");
add(f);
commit(f);
GitClient client = getClient(workDir);
String head = getRepository(client).resolve(Constants.HEAD).getName();
GitBranch branch = client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
// rebase branch to master
GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, Constants.MASTER, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.UP_TO_DATE, result.getRebaseStatus());
replacedertEquals(head, result.getCurrentHead());
// do a commit and
write(f, "change");
add(f);
GitRevisionInfo commit = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
// rebase branch to master, they are now different but still no rebase is needed
result = client.rebase(RebaseOperationType.BEGIN, Constants.MASTER, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.UP_TO_DATE, result.getRebaseStatus());
replacedertEquals(commit.getRevision(), result.getCurrentHead());
}
19
Source : RebaseTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testRebaseSkip() throws Exception {
File f = new File(workDir, "file");
write(f, "init");
add(f);
commit(f);
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
write(f, Constants.MASTER);
add(f);
GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f, BRANCH_NAME);
add(f);
GitRevisionInfo branchInfo = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, Constants.MASTER, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.STOPPED, result.getRebaseStatus());
replacedertEquals(Arrays.asList(f), result.getConflicts());
replacedertEquals(branchInfo.getRevision(), result.getCurrentCommit());
replacedertEquals(masterInfo.getRevision(), result.getCurrentHead());
result = client.rebase(RebaseOperationType.SKIP, null, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.OK, result.getRebaseStatus());
replacedertTrue(result.getConflicts().isEmpty());
replacedertEquals(masterInfo.getRevision(), result.getCurrentHead());
replacedertEquals(masterInfo.getRevision(), getRepository(client).resolve(BRANCH_NAME).name());
replacedertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name());
}
19
Source : RebaseTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testResolveConflicts() throws Exception {
File f = new File(workDir, "file");
write(f, "init");
add(f);
commit(f);
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
write(f, Constants.MASTER);
add(f);
GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f, BRANCH_NAME);
add(f);
GitRevisionInfo branchInfo = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, Constants.MASTER, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.STOPPED, result.getRebaseStatus());
replacedertEquals(Arrays.asList(f), result.getConflicts());
replacedertEquals(branchInfo.getRevision(), result.getCurrentCommit());
replacedertEquals(masterInfo.getRevision(), result.getCurrentHead());
write(f, "resolving conflict");
add(f);
result = client.rebase(RebaseOperationType.CONTINUE, null, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.OK, result.getRebaseStatus());
replacedertEquals(getRepository(client).resolve(Constants.HEAD).name(), result.getCurrentHead());
replacedertEquals(getRepository(client).resolve(Constants.HEAD).name(), getRepository(client).resolve(BRANCH_NAME).name());
replacedertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name());
}
19
Source : RebaseTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testRebaseFailCheckoutLocalChanges() throws Exception {
File f = new File(workDir, "file");
write(f, "init");
add(f);
commit(f);
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
write(f, Constants.MASTER);
add(f);
GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f, BRANCH_NAME);
add(f);
GitRevisionInfo branchInfo = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
write(f, "local change");
GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, Constants.MASTER, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.FAILED, result.getRebaseStatus());
replacedertEquals(Arrays.asList(f), result.getFailures());
replacedertEquals(branchInfo.getRevision(), getRepository(client).resolve(BRANCH_NAME).name());
replacedertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name());
// resets HEAD
replacedertEquals(branchInfo.getRevision(), getRepository(client).resolve(Constants.HEAD).name());
}
19
Source : RebaseTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testRebaseAbort() throws Exception {
File f = new File(workDir, "file");
write(f, "init");
add(f);
commit(f);
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
write(f, Constants.MASTER);
add(f);
GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f, BRANCH_NAME);
add(f);
GitRevisionInfo branchInfo = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, Constants.MASTER, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.STOPPED, result.getRebaseStatus());
replacedertEquals(Arrays.asList(f), result.getConflicts());
replacedertEquals(branchInfo.getRevision(), result.getCurrentCommit());
replacedertEquals(masterInfo.getRevision(), result.getCurrentHead());
result = client.rebase(RebaseOperationType.ABORT, null, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.ABORTED, result.getRebaseStatus());
replacedertTrue(result.getConflicts().isEmpty());
// resets to original state
replacedertEquals(branchInfo.getRevision(), result.getCurrentHead());
replacedertEquals(branchInfo.getRevision(), getRepository(client).resolve(BRANCH_NAME).name());
replacedertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name());
}
19
Source : MergeTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testMergeFFOnly() throws Exception {
File f1 = new File(workDir, "file1");
File f2 = new File(workDir, "file2");
write(f1, "init");
write(f2, "init");
add(f1, f2);
commit(f1, f2);
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f1, BRANCH_NAME);
add(f1);
client.commit(new File[] { f1 }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR);
write(f2, "another change");
add(f2);
client.commit(new File[] { f2 }, "change on master", null, null, NULL_PROGRESS_MONITOR);
GitMergeResult result = client.merge(BRANCH_NAME, GitRepository.FastForwardOption.FAST_FORWARD_ONLY, NULL_PROGRESS_MONITOR);
// no merge commits allowed => FAIL
replacedertEquals(MergeStatus.ABORTED, result.getMergeStatus());
// test also config files
replacedertEquals(GitRepository.FastForwardOption.FAST_FORWARD, GitRepository.getInstance(workDir).getDefaultFastForwardOption());
StoredConfig cfg = repo.getConfig();
cfg.setEnum(ConfigConstants.CONFIG_KEY_MERGE, null, ConfigConstants.CONFIG_KEY_FF, org.eclipse.jgit.api.MergeCommand.FastForwardMode.Merge.ONLY);
cfg.save();
replacedertEquals(GitRepository.FastForwardOption.FAST_FORWARD_ONLY, GitRepository.getInstance(workDir).getDefaultFastForwardOption());
result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR);
// no merge commits allowed => FAIL
replacedertEquals(MergeStatus.ABORTED, result.getMergeStatus());
result = client.merge(BRANCH_NAME, GitRepository.FastForwardOption.FAST_FORWARD, NULL_PROGRESS_MONITOR);
// merge commits allowed => OK
replacedertEquals(MergeStatus.MERGED, result.getMergeStatus());
}
19
Source : MergeTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testMergeNoFastForward() throws Exception {
File f = new File(workDir, "file");
write(f, "init");
add(f);
commit(f);
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f, BRANCH_NAME);
add(f);
GitRevisionInfo info = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR);
replacedertEquals("init", read(f));
GitMergeResult result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR);
replacedertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
replacedertEquals(BRANCH_NAME, read(f));
SearchCriteria crit = new SearchCriteria();
crit.setRevisionTo(Constants.MASTER);
GitRevisionInfo[] logs = client.log(crit, NULL_PROGRESS_MONITOR);
replacedertEquals(2, logs.length);
replacedertEquals(logs[0].getRevision(), info.getRevision());
// continue working on branch
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
remove(false, f);
client.commit(new File[] { f }, "delete on branch", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR);
replacedertEquals(BRANCH_NAME, read(f));
result = client.merge(BRANCH_NAME, GitRepository.FastForwardOption.NO_FAST_FORWARD, NULL_PROGRESS_MONITOR);
replacedertEquals(MergeStatus.MERGED, result.getMergeStatus());
replacedertFalse(f.exists());
crit = new SearchCriteria();
crit.setRevisionTo(Constants.MASTER);
logs = client.log(crit, NULL_PROGRESS_MONITOR);
replacedertEquals(4, logs.length);
replacedertEquals(2, logs[0].getParents().length);
}
19
Source : MergeTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testMergeFailOnLocalChanges() throws Exception {
File f = new File(workDir, "file");
write(f, "init");
File f2 = new File(workDir, "file2");
write(f2, "init");
File[] files = { f, f2 };
add(files);
commit(files);
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f, BRANCH_NAME);
add(f);
write(f2, BRANCH_NAME);
add(f2);
GitRevisionInfo branchInfo = client.commit(files, "change on branch", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR);
replacedertEquals("init", read(f));
replacedertEquals("init", read(f2));
write(f, Constants.MASTER);
write(f2, Constants.MASTER);
try {
client.merge(branchInfo.getRevision(), NULL_PROGRESS_MONITOR);
fail("Should fail");
} catch (GitException.CheckoutConflictException ex) {
// OK
replacedertEquals(Arrays.asList(new String[] { f.getName(), f2.getName() }), Arrays.asList(ex.getConflicts()));
}
}
19
Source : MergeTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testMergeFastForward() throws Exception {
File f = new File(workDir, "file");
write(f, "init");
add(f);
commit(f);
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f, BRANCH_NAME);
add(f);
GitRevisionInfo info = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR);
replacedertEquals("init", read(f));
GitMergeResult result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR);
replacedertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
replacedertEquals(BRANCH_NAME, read(f));
SearchCriteria crit = new SearchCriteria();
crit.setRevisionTo(Constants.MASTER);
GitRevisionInfo[] logs = client.log(crit, NULL_PROGRESS_MONITOR);
replacedertEquals(2, logs.length);
replacedertEquals(logs[0].getRevision(), info.getRevision());
// continue working on branch
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
remove(false, f);
info = client.commit(new File[] { f }, "delete on branch", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR);
replacedertEquals(BRANCH_NAME, read(f));
result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR);
replacedertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
replacedertFalse(f.exists());
crit = new SearchCriteria();
crit.setRevisionTo(Constants.MASTER);
logs = client.log(crit, NULL_PROGRESS_MONITOR);
replacedertEquals(3, logs.length);
replacedertEquals(logs[0].getRevision(), info.getRevision());
}
19
Source : MergeTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testMergeCommitFails250370() throws Exception {
File f1 = new File(workDir, "file1");
File f2 = new File(workDir, "file2");
write(f1, "init");
write(f2, "init");
add(f1, f2);
commit(f1, f2);
new File(workDir, ".git/rebase-apply").mkdirs();
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f1, BRANCH_NAME);
add(f1);
client.commit(new File[] { f1 }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR);
write(f2, "master");
add(f2);
client.commit(new File[] { f2 }, "change on master", null, null, NULL_PROGRESS_MONITOR);
try {
client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR);
fail();
} catch (GitException ex) {
// merge should return a meaningful message with a description
replacedertEquals(Utils.getBundle(MergeCommand.clreplaced).getString("MSG_MergeCommand.commitErr.wrongRepoState"), ex.getLocalizedMessage());
}
}
19
Source : MergeTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testMergeRevision() throws Exception {
File f = new File(workDir, "file");
write(f, "init");
add(f);
commit(f);
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f, BRANCH_NAME);
add(f);
GitRevisionInfo info = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
write(f, "another change");
add(f);
GitRevisionInfo info2 = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR);
replacedertEquals("init", read(f));
GitMergeResult result = client.merge(info.getRevision(), NULL_PROGRESS_MONITOR);
replacedertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
replacedertEquals(BRANCH_NAME, read(f));
SearchCriteria crit = new SearchCriteria();
crit.setRevisionTo(Constants.MASTER);
GitRevisionInfo[] logs = client.log(crit, NULL_PROGRESS_MONITOR);
replacedertEquals(2, logs.length);
replacedertEquals(logs[0].getRevision(), info.getRevision());
// merge the rest
result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR);
replacedertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
replacedertEquals("another change", read(f));
crit = new SearchCriteria();
crit.setRevisionTo(Constants.MASTER);
logs = client.log(crit, NULL_PROGRESS_MONITOR);
replacedertEquals(3, logs.length);
replacedertEquals(logs[0].getRevision(), info2.getRevision());
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
// commit in the middle of a named branch
public void testLogWithBranchInfoMiddleCommit() throws Exception {
File f = new File(workDir, "f");
File f2 = new File(workDir, "f2");
write(f, "init");
write(f2, "init");
File[] files = new File[] { f, f2 };
add(files);
GitClient client = getClient(workDir);
GitRevisionInfo firstCommit = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR);
client.createBranch("newbranch", "master", NULL_PROGRESS_MONITOR);
write(f, "modification");
add(files);
commit(files);
write(f2, "modification");
add(files);
commit(files);
SearchCriteria crit = new SearchCriteria();
crit.setRevisionFrom(firstCommit.getRevision());
crit.setRevisionTo(firstCommit.getRevision());
crit.setFiles(new File[] { f });
GitRevisionInfo info = client.log(crit, true, NULL_PROGRESS_MONITOR)[0];
// the initial commit is from master and head of newbranch
replacedertNotNull(info.getBranches().get("newbranch"));
replacedertEquals(2, info.getBranches().size());
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testLogDateCriteria() throws Exception {
File f = new File(workDir, "f");
write(f, "initial content");
File[] files = new File[] { f };
add(files);
commit(files);
write(f, "modification1");
add(files);
GitClient client = getClient(workDir);
GitRevisionInfo revision1 = client.commit(files, "modification1", null, null, NULL_PROGRESS_MONITOR);
Thread.sleep(1100);
write(f, "modification2");
add(files);
GitRevisionInfo revision2 = client.commit(files, "modification2", null, null, NULL_PROGRESS_MONITOR);
Thread.sleep(1100);
write(f, "modification3");
add(files);
GitRevisionInfo revision3 = client.commit(files, "modification3", null, null, NULL_PROGRESS_MONITOR);
SearchCriteria crit = new SearchCriteria();
crit.setFrom(new Date(revision2.getCommitTime()));
crit.setTo(new Date(revision3.getCommitTime()));
GitRevisionInfo[] revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(2, revisions.length);
replacedertRevisions(revision3, revisions[0]);
replacedertRevisions(revision2, revisions[1]);
Thread.sleep(1100);
write(f, "modification4");
add(files);
GitRevisionInfo revision4 = client.commit(files, "modification4", null, null, NULL_PROGRESS_MONITOR);
crit = new SearchCriteria();
crit.setFrom(new Date(revision2.getCommitTime()));
crit.setTo(new Date(revision3.getCommitTime()));
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(2, revisions.length);
replacedertRevisions(revision3, revisions[0]);
replacedertRevisions(revision2, revisions[1]);
crit = new SearchCriteria();
crit.setFrom(new Date(revision2.getCommitTime()));
crit.setTo(new Date(revision4.getCommitTime()));
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(3, revisions.length);
replacedertRevisions(revision4, revisions[0]);
replacedertRevisions(revision3, revisions[1]);
replacedertRevisions(revision2, revisions[2]);
crit = new SearchCriteria();
crit.setFrom(new Date(revision2.getCommitTime()));
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(3, revisions.length);
replacedertRevisions(revision4, revisions[0]);
replacedertRevisions(revision3, revisions[1]);
replacedertRevisions(revision2, revisions[2]);
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testLogSingleBranch() throws Exception {
File f = new File(workDir, "file");
write(f, "initial content");
File[] files = new File[] { f };
add(files);
GitClient client = getClient(workDir);
GitRevisionInfo revision0 = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR);
write(f, "modification1");
add(files);
GitRevisionInfo revision1 = client.commit(files, "modification1", null, null, NULL_PROGRESS_MONITOR);
write(new File(workDir, ".git/refs/heads/A"), revision1.getRevision());
write(new File(workDir, ".git/refs/heads/B"), revision1.getRevision());
write(new File(workDir, ".git/HEAD"), "ref: refs/heads/A");
Thread.sleep(1000);
write(f, "modificationOnA-1");
add(files);
GitRevisionInfo revisionA1 = client.commit(files, "modificationOnA-1", null, null, NULL_PROGRESS_MONITOR);
// to B
write(new File(workDir, ".git/HEAD"), "ref: refs/heads/B");
client.reset(revision1.getRevision(), GitClient.ResetType.SOFT, NULL_PROGRESS_MONITOR);
Thread.sleep(1000);
write(f, "modificationOnB-1");
add(files);
GitRevisionInfo revisionB1 = client.commit(files, "modificationOnB-1", null, null, NULL_PROGRESS_MONITOR);
// to A
write(new File(workDir, ".git/HEAD"), "ref: refs/heads/A");
client.reset(revisionA1.getRevision(), GitClient.ResetType.SOFT, NULL_PROGRESS_MONITOR);
Thread.sleep(1000);
write(f, "modificationOnA-2");
add(files);
GitRevisionInfo revisionA2 = client.commit(files, "modificationOnA-2", null, null, NULL_PROGRESS_MONITOR);
// to B
write(new File(workDir, ".git/HEAD"), "ref: refs/heads/B");
client.reset(revisionB1.getRevision(), GitClient.ResetType.SOFT, NULL_PROGRESS_MONITOR);
Thread.sleep(1000);
write(f, "modificationOnB-2");
add(files);
GitRevisionInfo revisionB2 = client.commit(files, "modificationOnB-2", null, null, NULL_PROGRESS_MONITOR);
SearchCriteria crit = new SearchCriteria();
crit.setRevisionTo("A");
GitRevisionInfo[] revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(4, revisions.length);
replacedertRevisions(revisionA2, revisions[0]);
replacedertRevisions(revisionA1, revisions[1]);
replacedertRevisions(revision1, revisions[2]);
replacedertRevisions(revision0, revisions[3]);
crit = new SearchCriteria();
crit.setRevisionTo("B");
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(4, revisions.length);
replacedertRevisions(revisionB2, revisions[0]);
replacedertRevisions(revisionB1, revisions[1]);
replacedertRevisions(revision1, revisions[2]);
replacedertRevisions(revision0, revisions[3]);
// try both branches, how are the revisions sorted?
revisions = client.log(new SearchCriteria(), true, NULL_PROGRESS_MONITOR);
replacedertEquals(6, revisions.length);
replacedertRevisions(revisionB2, revisions[0]);
replacedertRevisions(revisionA2, revisions[1]);
replacedertRevisions(revisionB1, revisions[2]);
replacedertRevisions(revisionA1, revisions[3]);
replacedertRevisions(revision1, revisions[4]);
replacedertRevisions(revision0, revisions[5]);
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testLimit() throws Exception {
File f1 = new File(workDir, "f1");
write(f1, "init");
File f2 = new File(workDir, "f2");
write(f2, "init");
File[] files = new File[] { f1, f2 };
add(files);
commit(files);
write(f1, "modif1");
add(f1);
GitClient client = getClient(workDir);
GitRevisionInfo c1 = client.commit(files, "m1", new GitUser("another", "netbeans.org"), new GitUser("another", "netbeans.org"), NULL_PROGRESS_MONITOR);
write(f2, "modif2");
add(f2);
GitRevisionInfo c2 = client.commit(files, "m2", new GitUser("user", "netbeans.org"), new GitUser("user", "netbeans.org"), NULL_PROGRESS_MONITOR);
SearchCriteria crit = new SearchCriteria();
crit.setLimit(1);
crit.setUsername("another");
GitRevisionInfo[] log = client.log(crit, NULL_PROGRESS_MONITOR);
replacedertEquals(c1.getRevision(), log[0].getRevision());
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testLogRevision() throws Exception {
File f = new File(workDir, "testcat1");
write(f, "initial content");
File[] files = new File[] { f };
add(files);
GitClient client = getClient(workDir);
GitRevisionInfo revision1 = client.commit(files, "commit1", null, null, NULL_PROGRESS_MONITOR);
GitRevisionInfo revision = client.log(revision1.getRevision(), NULL_PROGRESS_MONITOR);
replacedertRevisions(revision1, revision);
write(f, "modification");
add(files);
GitRevisionInfo revision2 = client.commit(files, "commit2", null, null, NULL_PROGRESS_MONITOR);
revision = client.log(revision1.getRevision(), NULL_PROGRESS_MONITOR);
replacedertRevisions(revision1, revision);
revision = client.log(revision2.getRevision(), NULL_PROGRESS_MONITOR);
replacedertRevisions(revision2, revision);
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testLogMessage() throws Exception {
File f = new File(workDir, "f");
write(f, "initial content");
File[] files = new File[] { f };
add(files);
commit(files);
write(f, "modification1");
add(files);
GitClient client = getClient(workDir);
GitRevisionInfo revision1 = client.commit(files, "modification1\non master", null, null, NULL_PROGRESS_MONITOR);
SearchCriteria crit = new SearchCriteria();
GitRevisionInfo[] revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(2, revisions.length);
crit = new SearchCriteria();
crit.setMessage("blablabla");
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(0, revisions.length);
crit = new SearchCriteria();
crit.setMessage("modification");
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(1, revisions.length);
replacedertRevisions(revision1, revisions[0]);
crit = new SearchCriteria();
crit.setMessage("modification1\non master");
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(1, revisions.length);
replacedertRevisions(revision1, revisions[0]);
// see bug #228905
crit = new SearchCriteria();
crit.setMessage("on master");
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(1, revisions.length);
replacedertRevisions(revision1, revisions[0]);
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testLogUsername() throws Exception {
File f = new File(workDir, "f");
write(f, "initial content");
File[] files = new File[] { f };
add(files);
commit(files);
write(f, "modification1");
add(files);
GitClient client = getClient(workDir);
GitUser user1 = ApiUtils.getClreplacedFactory().createUser(new PersonIdent("git-test-user", "[email protected]"));
GitRevisionInfo revision1 = client.commit(files, "modification1", user1, null, NULL_PROGRESS_MONITOR);
write(f, "modification2");
add(files);
GitRevisionInfo revision2 = client.commit(files, "modification2", null, user1, NULL_PROGRESS_MONITOR);
SearchCriteria crit = new SearchCriteria();
GitRevisionInfo[] revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(3, revisions.length);
crit = new SearchCriteria();
crit.setUsername("git-test-user");
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(2, revisions.length);
replacedertRevisions(revision2, revisions[0]);
replacedertRevisions(revision1, revisions[1]);
crit = new SearchCriteria();
crit.setUsername("[email protected]");
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(2, revisions.length);
replacedertRevisions(revision2, revisions[0]);
replacedertRevisions(revision1, revisions[1]);
crit = new SearchCriteria();
crit.setUsername("test-user");
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(2, revisions.length);
replacedertRevisions(revision2, revisions[0]);
replacedertRevisions(revision1, revisions[1]);
crit = new SearchCriteria();
crit.setUsername("[email protected]");
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(0, revisions.length);
crit = new SearchCriteria();
crit.setUsername("git-test-user <[email protected]>");
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(2, revisions.length);
replacedertRevisions(revision2, revisions[0]);
replacedertRevisions(revision1, revisions[1]);
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testLogFiles() throws Exception {
File f1 = new File(workDir, "file1");
write(f1, "initial content");
File f2 = new File(workDir, "file2");
write(f2, "initial content");
File f3 = new File(workDir, "file3");
File[] files = new File[] { f1, f2 };
add(files);
GitClient client = getClient(workDir);
commit(files);
write(f1, "modification1");
add(files);
GitRevisionInfo revision1 = client.commit(files, "modification1", null, null, NULL_PROGRESS_MONITOR);
write(f2, "modification2");
add(files);
GitRevisionInfo revision2 = client.commit(files, "modification2", null, null, NULL_PROGRESS_MONITOR);
write(f1, "modification3");
write(f2, "modification3");
add(files);
GitRevisionInfo revision3 = client.commit(files, "modification3", null, null, NULL_PROGRESS_MONITOR);
write(f3, "modification4");
add(new File[] { f3 });
GitRevisionInfo revision4 = client.commit(new File[] { f3 }, "modification4", null, null, NULL_PROGRESS_MONITOR);
SearchCriteria crit = new SearchCriteria();
crit.setFiles(new File[] { f1 });
crit.setRevisionFrom(revision1.getRevision());
GitRevisionInfo[] revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(2, revisions.length);
replacedertRevisions(revision3, revisions[0]);
replacedertRevisions(revision1, revisions[1]);
crit = new SearchCriteria();
crit.setFiles(new File[] { f2 });
crit.setRevisionFrom(revision1.getRevision());
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(2, revisions.length);
replacedertRevisions(revision3, revisions[0]);
replacedertRevisions(revision2, revisions[1]);
crit = new SearchCriteria();
crit.setFiles(files);
crit.setRevisionFrom(revision1.getRevision());
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(3, revisions.length);
replacedertRevisions(revision3, revisions[0]);
replacedertRevisions(revision2, revisions[1]);
replacedertRevisions(revision1, revisions[2]);
crit = new SearchCriteria();
crit.setFiles(new File[] { f1, f2, f3 });
crit.setRevisionFrom(revision1.getRevision());
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(4, revisions.length);
replacedertRevisions(revision4, revisions[0]);
replacedertRevisions(revision3, revisions[1]);
replacedertRevisions(revision2, revisions[2]);
replacedertRevisions(revision1, revisions[3]);
crit = new SearchCriteria();
crit.setFiles(new File[] { workDir });
crit.setRevisionFrom(revision1.getRevision());
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(4, revisions.length);
replacedertRevisions(revision4, revisions[0]);
replacedertRevisions(revision3, revisions[1]);
replacedertRevisions(revision2, revisions[2]);
replacedertRevisions(revision1, revisions[3]);
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testLogShowMerges() throws Exception {
File f = new File(workDir, "f");
write(f, "a\nb\nc");
File[] files = new File[] { f };
add(files);
commit(files);
GitClient client = getClient(workDir);
client.createBranch("b", "master", NULL_PROGRESS_MONITOR);
client.checkoutRevision("b", true, NULL_PROGRESS_MONITOR);
write(f, "modification on branch\nb\nc");
add(files);
GitRevisionInfo revisionBranch = client.commit(files, "modification on branch", null, null, NULL_PROGRESS_MONITOR);
Thread.sleep(1100);
client.checkoutRevision("master", true, NULL_PROGRESS_MONITOR);
write(f, "a\nb\nmodification on master");
add(files);
GitRevisionInfo revisionMaster = client.commit(files, "modification on master", null, null, NULL_PROGRESS_MONITOR);
GitRevisionInfo revisionMerge = client.log(client.merge("b", NULL_PROGRESS_MONITOR).getNewHead(), NULL_PROGRESS_MONITOR);
SearchCriteria crit = new SearchCriteria();
crit.setRevisionTo("master");
GitRevisionInfo[] revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(4, revisions.length);
replacedertRevisions(revisionMerge, revisions[0]);
crit = new SearchCriteria();
crit.setIncludeMerges(true);
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(4, revisions.length);
replacedertRevisions(revisionMerge, revisions[0]);
crit = new SearchCriteria();
crit.setIncludeMerges(false);
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(3, revisions.length);
replacedertRevisions(revisionMaster, revisions[0]);
replacedertRevisions(revisionBranch, revisions[1]);
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testShortMessages() throws Exception {
File f = new File(workDir, "f");
write(f, "init");
File[] files = new File[] { f };
add(files);
GitClient client = getClient(workDir);
client.commit(files, "short message", null, null, NULL_PROGRESS_MONITOR);
replacedertEquals("short message", client.log("HEAD", NULL_PROGRESS_MONITOR).getShortMessage());
write(f, "m1");
add(f);
client.commit(files, "short message\n\n\n", null, null, NULL_PROGRESS_MONITOR);
replacedertEquals("short message", client.log("HEAD", NULL_PROGRESS_MONITOR).getShortMessage());
write(f, "m1");
add(f);
client.commit(files, "short message\nbla\nbla\nbla", null, null, NULL_PROGRESS_MONITOR);
replacedertEquals("short message", client.log("HEAD", NULL_PROGRESS_MONITOR).getShortMessage());
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testLogLimit() throws Exception {
File f = new File(workDir, "testcat1");
write(f, "initial content");
File[] files = new File[] { f };
add(files);
commit(files);
write(f, "modification1");
add(files);
GitClient client = getClient(workDir);
GitRevisionInfo revision1 = client.commit(files, "modification1", null, null, NULL_PROGRESS_MONITOR);
write(f, "modification2");
add(files);
GitRevisionInfo revision2 = client.commit(files, "modification2", null, null, NULL_PROGRESS_MONITOR);
write(f, "modification3");
add(files);
GitRevisionInfo revision3 = client.commit(files, "modification3", null, null, NULL_PROGRESS_MONITOR);
write(f, "modification4");
add(files);
GitRevisionInfo revision4 = client.commit(files, "modification4", null, null, NULL_PROGRESS_MONITOR);
SearchCriteria crit = new SearchCriteria();
crit.setRevisionFrom(revision2.getRevision());
crit.setRevisionTo(revision4.getRevision());
GitRevisionInfo[] revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(3, revisions.length);
replacedertRevisions(revision4, revisions[0]);
replacedertRevisions(revision3, revisions[1]);
replacedertRevisions(revision2, revisions[2]);
crit = new SearchCriteria();
crit.setRevisionFrom(revision2.getRevision());
crit.setRevisionTo(revision4.getRevision());
crit.setLimit(2);
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(2, revisions.length);
replacedertRevisions(revision4, revisions[0]);
replacedertRevisions(revision3, revisions[1]);
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testLogRevisionRange() throws Exception {
File f = new File(workDir, "testcat1");
write(f, "initial content");
File[] files = new File[] { f };
add(files);
commit(files);
write(f, "modification1");
add(files);
GitClient client = getClient(workDir);
GitRevisionInfo revision1 = client.commit(files, "modification1", null, null, NULL_PROGRESS_MONITOR);
write(f, "modification2");
add(files);
GitRevisionInfo revision2 = client.commit(files, "modification2", null, null, NULL_PROGRESS_MONITOR);
write(f, "modification3");
add(files);
GitRevisionInfo revision3 = client.commit(files, "modification3", null, null, NULL_PROGRESS_MONITOR);
SearchCriteria crit = new SearchCriteria();
crit.setRevisionFrom(revision2.getRevision());
crit.setRevisionTo(revision3.getRevision());
GitRevisionInfo[] revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(2, revisions.length);
replacedertRevisions(revision3, revisions[0]);
replacedertRevisions(revision2, revisions[1]);
write(f, "modification4");
add(files);
GitRevisionInfo revision4 = client.commit(files, "modification4", null, null, NULL_PROGRESS_MONITOR);
crit = new SearchCriteria();
crit.setRevisionFrom(revision2.getRevision());
crit.setRevisionTo(revision4.getRevision());
revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(3, revisions.length);
replacedertRevisions(revision4, revisions[0]);
replacedertRevisions(revision3, revisions[1]);
replacedertRevisions(revision2, revisions[2]);
}
19
Source : LogTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testLogRevisionTo() throws Exception {
File f = new File(workDir, "testcat1");
write(f, "initial content");
File[] files = new File[] { f };
add(files);
GitClient client = getClient(workDir);
GitRevisionInfo revision0 = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR);
write(f, "modification1");
add(files);
GitRevisionInfo revision1 = client.commit(files, "modification1", null, null, NULL_PROGRESS_MONITOR);
write(f, "modification2");
add(files);
GitRevisionInfo revision2 = client.commit(files, "modification2", null, null, NULL_PROGRESS_MONITOR);
write(f, "modification3");
add(files);
GitRevisionInfo revision3 = client.commit(files, "modification3", null, null, NULL_PROGRESS_MONITOR);
write(f, "modification4");
add(files);
GitRevisionInfo revision4 = client.commit(files, "modification4", null, null, NULL_PROGRESS_MONITOR);
SearchCriteria crit = new SearchCriteria();
crit.setRevisionTo(revision4.getRevision());
GitRevisionInfo[] revisions = client.log(crit, true, NULL_PROGRESS_MONITOR);
replacedertEquals(5, revisions.length);
replacedertRevisions(revision4, revisions[0]);
replacedertRevisions(revision3, revisions[1]);
replacedertRevisions(revision2, revisions[2]);
replacedertRevisions(revision1, revisions[3]);
replacedertRevisions(revision0, revisions[4]);
}
19
Source : CheckoutTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testCheckoutAfterUnresolvedMerge() throws Exception {
File file = new File(workDir, "file");
write(file, "initial");
File[] files = new File[] { file };
add(files);
GitClient client = getClient(workDir);
GitRevisionInfo info = client.commit(files, "initial", null, null, NULL_PROGRESS_MONITOR);
client.createBranch(BRANCH, info.getRevision(), NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR);
write(file, BRANCH);
add(file);
client.commit(files, BRANCH, null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR);
write(file, "master change");
add(file);
client.commit(files, "master commit", null, null, NULL_PROGRESS_MONITOR);
client.merge(BRANCH, NULL_PROGRESS_MONITOR);
try {
client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR);
fail("Should fail, there are conflicts");
} catch (GitException.CheckoutConflictException ex) {
// ok
}
try {
client.checkoutRevision(BRANCH, false, NULL_PROGRESS_MONITOR);
fail("Should fail, there are conflicts");
} catch (GitException ex) {
replacedertEquals(ex.getMessage(), MessageFormat.format(Utils.getBundle(GitCommand.clreplaced).getString("MSG_Error_CannotCheckoutHasConflicts"), workDir));
}
}
19
Source : BlameTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testBlameRename() throws Exception {
File f = new File(workDir, "f");
File f2 = new File(workDir, "f2");
write(f, "aaa\nbbb\nccc\n");
File[] files = { f, f2 };
add(files);
GitClient client = getClient(workDir);
String revision1 = client.commit(files, "initial commit", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();
client.rename(f, f2, false, NULL_PROGRESS_MONITOR);
write(f2, "aaa\nbbb\nddd\n");
add(f2);
String revision2 = client.commit(files, "rename", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();
GitBlameResult result = client.blame(f, revision2, NULL_PROGRESS_MONITOR);
replacedertNull(result);
result = client.blame(f, revision1, NULL_PROGRESS_MONITOR);
replacedertEquals(f, result.getBlamedFile());
replacedertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
replacedertLineDetails(f, 1, revision1, USER1, USER1, result.getLineDetails(1));
replacedertLineDetails(f, 2, revision1, USER1, USER1, result.getLineDetails(2));
result = client.blame(f2, null, NULL_PROGRESS_MONITOR);
replacedertEquals(f2, result.getBlamedFile());
replacedertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
replacedertLineDetails(f, 1, revision1, USER1, USER1, result.getLineDetails(1));
replacedertLineDetails(f2, 2, revision2, USER1, USER1, result.getLineDetails(2));
}
19
Source : BlameTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testBlameRemoveLine() throws Exception {
File f = new File(workDir, "f");
write(f, "aaa\nbbb\nccc");
File[] files = { f };
add(files);
GitClient client = getClient(workDir);
String revision1 = client.commit(files, "initial commit", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();
write(f, "aaa\nccc");
add(f);
String revision2 = client.commit(files, "remove line", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();
GitBlameResult result = client.blame(f, revision2, NULL_PROGRESS_MONITOR);
replacedertEquals(f, result.getBlamedFile());
replacedertEquals(2, result.getLineCount());
replacedertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
replacedertLineDetails(f, 2, revision1, USER1, USER1, result.getLineDetails(1));
}
19
Source : BlameTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testBlameNullForModifiedLines() throws Exception {
File f = new File(workDir, "f");
write(f, "aaa\nbbb\n");
File[] files = { f };
add(files);
GitClient client = getClient(workDir);
String revision1 = client.commit(files, "initial commit", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();
write(f, "aaa\nccc\n");
GitBlameResult result = client.blame(f, null, NULL_PROGRESS_MONITOR);
replacedertEquals(f, result.getBlamedFile());
replacedertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
replacedertNull(result.getLineDetails(1));
add(files);
result = client.blame(f, null, NULL_PROGRESS_MONITOR);
replacedertEquals(f, result.getBlamedFile());
replacedertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
replacedertNull(result.getLineDetails(1));
write(f, "aaa\nbbb\n");
result = client.blame(f, null, NULL_PROGRESS_MONITOR);
replacedertEquals(f, result.getBlamedFile());
replacedertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
replacedertNull(result.getLineDetails(1));
}
19
Source : BlameTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testBlameSimple() throws Exception {
File f = new File(workDir, "f");
write(f, "aaa\nbbb\nccc\n");
File[] files = { f };
add(files);
GitClient client = getClient(workDir);
String revision1 = client.commit(files, "initial commit", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();
GitBlameResult result = client.blame(f, revision1, NULL_PROGRESS_MONITOR);
replacedertEquals(f, result.getBlamedFile());
replacedertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
// the same authors should be the same one instance
replacedertSame(result.getLineDetails(0).getAuthor(), result.getLineDetails(1).getAuthor());
replacedertSame(result.getLineDetails(1).getAuthor(), result.getLineDetails(2).getAuthor());
replacedertSame(result.getLineDetails(0).getAuthor(), result.getLineDetails(0).getCommitter());
replacedertSame(result.getLineDetails(0).getCommitter(), result.getLineDetails(1).getCommitter());
replacedertSame(result.getLineDetails(1).getCommitter(), result.getLineDetails(2).getCommitter());
// the same commits should be the same one instance
replacedertSame(result.getLineDetails(0).getRevisionInfo(), result.getLineDetails(1).getRevisionInfo());
replacedertSame(result.getLineDetails(1).getRevisionInfo(), result.getLineDetails(2).getRevisionInfo());
write(f, "aaa\nzzz\nccc\n");
add(files);
String revision2 = client.commit(files, "change 1", USER2, USER1, NULL_PROGRESS_MONITOR).getRevision();
result = client.blame(f, revision2, NULL_PROGRESS_MONITOR);
replacedertEquals(f, result.getBlamedFile());
replacedertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
replacedertLineDetails(f, 1, revision2, USER2, USER1, result.getLineDetails(1));
replacedertLineDetails(f, 2, revision1, USER1, USER1, result.getLineDetails(2));
write(f, "aaa\nzzz\nyyy\n");
add(files);
String revision3 = client.commit(files, "change 2", USER1, USER2, NULL_PROGRESS_MONITOR).getRevision();
result = client.blame(f, revision3, NULL_PROGRESS_MONITOR);
replacedertEquals(f, result.getBlamedFile());
replacedertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
replacedertLineDetails(f, 1, revision2, USER2, USER1, result.getLineDetails(1));
replacedertLineDetails(f, 2, revision3, USER1, USER2, result.getLineDetails(2));
}
19
Source : BlameTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testBlameAddLine() throws Exception {
File f = new File(workDir, "f");
write(f, "aaa\nccc\n");
File[] files = { f };
add(files);
GitClient client = getClient(workDir);
String revision1 = client.commit(files, "initial commit", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();
write(f, "aaa\nbbb\nccc\n");
add(f);
String revision2 = client.commit(files, "add line", USER1, USER1, NULL_PROGRESS_MONITOR).getRevision();
GitBlameResult result = client.blame(f, revision2, NULL_PROGRESS_MONITOR);
replacedertEquals(f, result.getBlamedFile());
replacedertLineDetails(f, 0, revision1, USER1, USER1, result.getLineDetails(0));
replacedertLineDetails(f, 1, revision2, USER1, USER1, result.getLineDetails(1));
replacedertLineDetails(f, 1, revision1, USER1, USER1, result.getLineDetails(2));
}
18
Source : TagTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testDeleteTag() throws Exception {
File f = new File(workDir, "f");
File[] files = new File[] { f };
GitClient client = getClient(workDir);
write(f, "init");
GitRevisionInfo commit = client.commit(files, "init commit", null, null, NULL_PROGRESS_MONITOR);
GitTag tag = client.createTag("tag-name", commit.getRevision(), null, false, false, NULL_PROGRESS_MONITOR);
Map<String, GitTag> tags = client.getTags(NULL_PROGRESS_MONITOR, true);
replacedertEquals(1, tags.size());
client.deleteTag("tag-name", NULL_PROGRESS_MONITOR);
tags = client.getTags(NULL_PROGRESS_MONITOR, true);
replacedertEquals(0, tags.size());
// and what about real tag object? not a lightweight one?
tag = client.createTag("tag-name", commit.getRevision(), "tag message", false, false, NULL_PROGRESS_MONITOR);
String tagId = tag.getTagId();
tags = client.getTags(NULL_PROGRESS_MONITOR, true);
replacedertEquals(1, tags.size());
client.deleteTag("tag-name", NULL_PROGRESS_MONITOR);
tags = client.getTags(NULL_PROGRESS_MONITOR, true);
replacedertEquals(0, tags.size());
// can the same tag be created again?
tag = client.createTag("tag-name", commit.getRevision(), "tag message", false, false, NULL_PROGRESS_MONITOR);
replacedertEquals(tagId, tag.getTagId());
tags = client.getTags(NULL_PROGRESS_MONITOR, true);
replacedertEquals(1, tags.size());
client.deleteTag("tag-name", NULL_PROGRESS_MONITOR);
tags = client.getTags(NULL_PROGRESS_MONITOR, true);
replacedertEquals(0, tags.size());
}
18
Source : TagTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testCreateLightweightTag() throws Exception {
File f = new File(workDir, "f");
File[] files = new File[] { f };
GitClient client = getClient(workDir);
write(f, "init");
GitRevisionInfo commit = client.commit(files, "init commit", null, null, NULL_PROGRESS_MONITOR);
GitTag tag = client.createTag("tag-name", commit.getRevision(), null, false, false, NULL_PROGRESS_MONITOR);
replacedertTag(tag, commit.getRevision(), "tag-name", commit.getFullMessage(), commit.getCommitter(), GitObjectType.COMMIT, true);
Map<String, GitTag> tags = client.getTags(NULL_PROGRESS_MONITOR, true);
replacedertEquals(1, tags.size());
replacedertTag(tags.get("tag-name"), commit.getRevision(), "tag-name", commit.getFullMessage(), commit.getCommitter(), GitObjectType.COMMIT, true);
}
18
Source : TagTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testListTags() throws Exception {
File f = new File(workDir, "f");
File[] files = new File[] { f };
GitClient client = getClient(workDir);
write(f, "init");
GitRevisionInfo commit = client.commit(files, "init commit", null, null, NULL_PROGRESS_MONITOR);
client.createTag("tag-name", commit.getRevision(), "tag message", false, false, NULL_PROGRESS_MONITOR);
client.createTag("tag-name-2", commit.getRevision(), "second tag message", false, false, NULL_PROGRESS_MONITOR);
Map<String, GitTag> tags = client.getTags(NULL_PROGRESS_MONITOR, false);
replacedertEquals(2, tags.size());
replacedertTag(tags.get("tag-name"), commit.getRevision(), "tag-name", "tag message", client.getUser(), GitObjectType.COMMIT, false);
replacedertTag(tags.get("tag-name-2"), commit.getRevision(), "tag-name-2", "second tag message", client.getUser(), GitObjectType.COMMIT, false);
}
18
Source : TagTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testListTagsAll() throws Exception {
File f = new File(workDir, "f");
File[] files = new File[] { f };
GitClient client = getClient(workDir);
write(f, "init");
GitRevisionInfo commit = client.commit(files, "init commit", null, null, NULL_PROGRESS_MONITOR);
GitTag tag = client.createTag("tag-name", commit.getRevision(), "tag message", false, false, NULL_PROGRESS_MONITOR);
client.createTag("tag-name-2", Utils.findCommit(repository, commit.getRevision()).getTree().getId().getName(), "tag for tree", false, false, NULL_PROGRESS_MONITOR);
client.createTag("tag-name-3", tag.getTagId(), "tag for tag", false, false, NULL_PROGRESS_MONITOR);
Map<String, GitTag> tags = client.getTags(NULL_PROGRESS_MONITOR, false);
replacedertEquals(1, tags.size());
replacedertTag(tags.get("tag-name"), commit.getRevision(), "tag-name", "tag message", client.getUser(), GitObjectType.COMMIT, false);
tags = client.getTags(NULL_PROGRESS_MONITOR, true);
replacedertEquals(3, tags.size());
replacedertTag(tags.get("tag-name"), commit.getRevision(), "tag-name", "tag message", client.getUser(), GitObjectType.COMMIT, false);
replacedertTag(tags.get("tag-name-2"), Utils.findCommit(repository, commit.getRevision()).getTree().getId().getName(), "tag-name-2", "tag for tree", client.getUser(), GitObjectType.TREE, false);
replacedertTag(tags.get("tag-name-3"), tag.getTagId(), "tag-name-3", "tag for tag", client.getUser(), GitObjectType.TAG, false);
}
18
Source : SubmoduleTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testStatusCommit() throws Exception {
prepareUninitializedWorkdir();
GitClient client = getClient(workDir);
client.initializeSubmodules(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR);
client.updateSubmodules(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR);
GitClient subClient = getClient(submoduleFolder1);
subClient.checkoutRevision("master", true, NULL_PROGRESS_MONITOR);
GitRevisionInfo previous = subClient.log("HEAD", NULL_PROGRESS_MONITOR);
write(f1, "change");
subClient.add(new File[] { f1 }, NULL_PROGRESS_MONITOR);
Map<File, GitSubmoduleStatus> status = client.getSubmoduleStatus(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR);
replacedertEquals(GitSubmoduleStatus.StatusType.INITIALIZED, status.get(submoduleFolder1).getStatus());
replacedertEquals(previous.getRevision(), status.get(submoduleFolder1).getReferencedCommitId());
subClient.commit(new File[] { f1 }, "change commit", null, null, NULL_PROGRESS_MONITOR);
GitRevisionInfo current = subClient.log("HEAD", NULL_PROGRESS_MONITOR);
status = client.getSubmoduleStatus(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR);
replacedertEquals(GitSubmoduleStatus.StatusType.REV_CHECKED_OUT, status.get(submoduleFolder1).getStatus());
replacedertEquals(previous.getRevision(), status.get(submoduleFolder1).getReferencedCommitId());
}
18
Source : SubmoduleTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Override
protected void setUp() throws Exception {
super.setUp();
workDir = getWorkingDirectory();
repository = getRepository(getLocalGitRepository());
moduleRepo = new File(workDir.getParentFile(), "module");
GitClient client = getClient(moduleRepo);
client.init(NULL_PROGRESS_MONITOR);
submoduleRepo1 = new File(workDir.getParentFile(), "submodule1");
client = getClient(submoduleRepo1);
client.init(NULL_PROGRESS_MONITOR);
submoduleRepo2 = new File(workDir.getParentFile(), "submodule2");
client = getClient(submoduleRepo2);
client.init(NULL_PROGRESS_MONITOR);
client = getClient(workDir);
f = new File(workDir, "f");
write(f, "init");
client.add(new File[] { f }, NULL_PROGRESS_MONITOR);
client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR);
RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin");
cfg.addURI(new URIish(moduleRepo.toURI().toURL().toString()));
cfg.update(repository.getConfig());
repository.getConfig().save();
client.push("origin", Arrays.asList("refs/heads/master:refs/heads/master"), Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR);
File submodules = new File(workDir, "submodules");
submoduleFolder1 = new File(submodules, "submodule1");
submoduleFolder1.mkdirs();
getClient(submoduleFolder1).init(NULL_PROGRESS_MONITOR);
f1 = new File(submoduleFolder1, "file");
write(f1, "init");
getClient(submoduleFolder1).add(new File[] { f1 }, NULL_PROGRESS_MONITOR);
getClient(submoduleFolder1).commit(new File[] { f1 }, "init SM1 commit", null, null, NULL_PROGRESS_MONITOR);
repositorySM1 = getRepository(getClient(submoduleFolder1));
cfg = new RemoteConfig(repositorySM1.getConfig(), "origin");
cfg.addURI(new URIish(submoduleRepo1.toURI().toURL().toString()));
cfg.update(repositorySM1.getConfig());
repositorySM1.getConfig().save();
getClient(submoduleFolder1).push("origin", Arrays.asList("refs/heads/master:refs/heads/master"), Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR);
submoduleFolder2 = new File(submodules, "submodule2");
submoduleFolder2.mkdirs();
getClient(submoduleFolder2).init(NULL_PROGRESS_MONITOR);
f2 = new File(submoduleFolder2, "file");
write(f2, "init");
getClient(submoduleFolder2).add(new File[] { f2 }, NULL_PROGRESS_MONITOR);
getClient(submoduleFolder2).commit(new File[] { f2 }, "init SM1 commit", null, null, NULL_PROGRESS_MONITOR);
repositorySM2 = getRepository(getClient(submoduleFolder2));
cfg = new RemoteConfig(repositorySM2.getConfig(), "origin");
cfg.addURI(new URIish(submoduleRepo2.toURI().toURL().toString()));
cfg.update(repositorySM2.getConfig());
repositorySM2.getConfig().save();
getClient(submoduleFolder2).push("origin", Arrays.asList("refs/heads/master:refs/heads/master"), Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR);
}
18
Source : SubmoduleTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
private void prepareUninitializedWorkdir() throws Exception {
File gmFile = new File(workDir, ".gitmodules");
gmFile.createNewFile();
write(gmFile, "[submodule \"submodules/submodule1\"]\n" + " path = submodules/submodule1\n" + " url = " + submoduleRepo1.toURI().toURL().toString() + "\n" + "[submodule \"submodules/submodule2\"]\n" + " path = submodules/submodule2\n" + " url = " + submoduleRepo2.toURI().toURL().toString() + "\n");
GitClient client = getClient(workDir);
client.add(new File[] { gmFile, submoduleFolder1, submoduleFolder2 }, NULL_PROGRESS_MONITOR);
client.commit(new File[0], "adding modules", null, null, NULL_PROGRESS_MONITOR);
client.push("origin", Arrays.asList("refs/heads/master:refs/heads/master"), Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), NULL_PROGRESS_MONITOR);
Utils.deleteRecursively(submoduleFolder1);
Utils.deleteRecursively(submoduleFolder2);
replacedertFalse(submoduleFolder1.exists());
replacedertFalse(submoduleFolder2.exists());
client.reset("master", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR);
replacedertTrue(submoduleFolder1.exists());
replacedertTrue(submoduleFolder2.exists());
// must clear temporary git pool instances
// submodule commands initialize submodules with .git as a link to parent/.git/... folders
ApiUtils.clearRepositoryPool();
}
18
Source : RemotesTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testRemoveRemote() throws Exception {
File otherWT = new File(workDir.getParentFile(), "repo2");
GitClient client = getClient(otherWT);
client.init(NULL_PROGRESS_MONITOR);
File f = new File(otherWT, "f");
write(f, "init");
client.add(new File[] { f }, NULL_PROGRESS_MONITOR);
client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR);
RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin");
cfg.addURI(new URIish(otherWT.toURI().toURL().toString()));
cfg.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
cfg.update(repository.getConfig());
repository.getConfig().save();
client = getClient(workDir);
client.fetch("origin", NULL_PROGRESS_MONITOR);
client.createBranch("master", "origin/master", NULL_PROGRESS_MONITOR);
client.createBranch("nova", "origin/master", NULL_PROGRESS_MONITOR);
StoredConfig config = repository.getConfig();
replacedertEquals("+refs/heads/*:refs/remotes/origin/*", config.getString("remote", "origin", "fetch"));
replacedertEquals("origin", config.getString("branch", "master", "remote"));
replacedertEquals("refs/heads/master", config.getString("branch", "master", "merge"));
replacedertEquals("origin", config.getString("branch", "nova", "remote"));
replacedertEquals("refs/heads/master", config.getString("branch", "nova", "merge"));
// now try to remove the remote
client.removeRemote("origin", NULL_PROGRESS_MONITOR);
config = repository.getConfig();
config.load();
// is everything deleted?
replacedertEquals(0, config.getSubsections("remote").size());
replacedertNull(config.getString("branch", "master", "remote"));
replacedertNull(config.getString("branch", "master", "merge"));
replacedertNull(config.getString("branch", "nova", "remote"));
replacedertNull(config.getString("branch", "nova", "merge"));
}
18
Source : RebaseTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testConflicts() throws Exception {
File f = new File(workDir, "file");
File f2 = new File(workDir, "file2");
write(f, "init");
add(f);
commit(f);
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
write(f, Constants.MASTER);
add(f);
GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f, BRANCH_NAME);
add(f);
write(f2, BRANCH_NAME);
add(f2);
GitRevisionInfo branchInfo = client.commit(new File[] { f, f2 }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, Constants.MASTER, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.STOPPED, result.getRebaseStatus());
replacedertEquals("<<<<<<< Upstream, based on master\nmaster\n=======\nnew_branch\n>>>>>>> " + branchInfo.getRevision().substring(0, 7) + " " + branchInfo.getShortMessage(), read(f));
replacedertEquals(Arrays.asList(f), result.getConflicts());
Map<File, GitStatus> statuses = client.getStatus(new File[] { f, f2 }, NULL_PROGRESS_MONITOR);
replacedertTrue(statuses.get(f).isConflict());
replacedertStatus(statuses, workDir, f2, true, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, false);
replacedertEquals(branchInfo.getRevision(), result.getCurrentCommit());
replacedertEquals(masterInfo.getRevision(), result.getCurrentHead());
}
18
Source : RebaseTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testRebaseSimple() throws Exception {
File f = new File(workDir, "file");
File f2 = new File(workDir, "file2");
write(f, "init");
add(f);
commit(f);
GitClient client = getClient(workDir);
write(f2, Constants.MASTER);
add(f2);
GitRevisionInfo master = client.commit(new File[] { f2 }, "change on master", null, null, NULL_PROGRESS_MONITOR);
client.createBranch(BRANCH_NAME, "master^1", NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
replacedertFalse(f2.exists());
write(f, BRANCH_NAME);
add(f);
GitRevisionInfo info = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
write(f, "another change");
add(f);
GitRevisionInfo info2 = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
// sleep to change time
Thread.sleep(1100);
GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, Constants.MASTER, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.OK, result.getRebaseStatus());
replacedertEquals("another change", read(f));
replacedertEquals(Constants.MASTER, read(f2));
SearchCriteria crit = new SearchCriteria();
crit.setRevisionFrom(Constants.MASTER);
crit.setRevisionTo(result.getCurrentHead());
GitRevisionInfo[] logs = client.log(crit, NULL_PROGRESS_MONITOR);
replacedertEquals(3, logs.length);
replacedertFalse(info2.getRevision().equals(logs[0].getRevision()));
replacedertEquals(info2.getCommitTime(), logs[0].getCommitTime());
replacedertFalse(info.getRevision().equals(logs[1].getRevision()));
replacedertEquals(info.getCommitTime(), logs[1].getCommitTime());
replacedertEquals(master.getRevision(), logs[2].getRevision());
}
18
Source : RebaseTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testResolveConflictsNoCommit() throws Exception {
File f = new File(workDir, "file");
write(f, "init");
add(f);
commit(f);
GitClient client = getClient(workDir);
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR);
write(f, Constants.MASTER);
add(f);
GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR);
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR);
write(f, BRANCH_NAME);
add(f);
GitRevisionInfo branchInfo = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR);
GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, Constants.MASTER, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.STOPPED, result.getRebaseStatus());
replacedertEquals("<<<<<<< Upstream, based on master\nmaster\n=======\nnew_branch\n>>>>>>> " + branchInfo.getRevision().substring(0, 7) + " " + branchInfo.getShortMessage(), read(f));
replacedertEquals(Arrays.asList(f), result.getConflicts());
Map<File, GitStatus> statuses = client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR);
replacedertTrue(statuses.get(f).isConflict());
replacedertEquals(branchInfo.getRevision(), result.getCurrentCommit());
replacedertEquals(masterInfo.getRevision(), result.getCurrentHead());
write(f, Constants.MASTER);
add(f);
result = client.rebase(RebaseOperationType.CONTINUE, null, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.NOTHING_TO_COMMIT, result.getRebaseStatus());
replacedertTrue(result.getConflicts().isEmpty());
replacedertEquals(masterInfo.getRevision(), result.getCurrentHead());
replacedertEquals(branchInfo.getRevision(), getRepository(client).resolve(BRANCH_NAME).name());
replacedertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name());
// still have to finish rebase
result = client.rebase(RebaseOperationType.SKIP, null, NULL_PROGRESS_MONITOR);
replacedertEquals(RebaseStatus.OK, result.getRebaseStatus());
replacedertTrue(result.getConflicts().isEmpty());
replacedertEquals(masterInfo.getRevision(), result.getCurrentHead());
replacedertEquals(masterInfo.getRevision(), getRepository(client).resolve(BRANCH_NAME).name());
replacedertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name());
}
18
Source : PullTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void testPullChangesInSameBranchPlusMerge() throws Exception {
GitClient client = getClient(workDir);
client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
File f = new File(workDir, this.f.getName());
File f2 = new File(workDir, "f2");
write(f2, "hi, i am new");
add(f2);
String localCommitId = client.commit(new File[] { f2 }, "local change", null, null, NULL_PROGRESS_MONITOR).getRevision();
Map<String, GitBranch> branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
String commitId = makeRemoteChange("master");
GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR);
branches = client.getBranches(true, NULL_PROGRESS_MONITOR);
replacedertTrue(branches.get("master").isActive());
replacedertEquals(commitId, branches.get("origin/master").getId());
replacedertFalse(commitId.equals(branches.get("master").getId()));
Map<String, GitTransportUpdate> updates = result.getFetchResult();
replacedertEquals(1, updates.size());
replacedertUpdate(updates.get("origin/master"), "origin/master", "master", commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD);
replacedertEquals(MergeStatus.MERGED, result.getMergeResult().getMergeStatus());
replacedertEquals(new HashSet<String>(Arrays.asList(commitId, localCommitId)), new HashSet<String>(Arrays.asList(result.getMergeResult().getMergedCommits())));
replacedertTrue(f.exists());
replacedertTrue(f2.exists());
}
18
Source : PullTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
private String makeLocalChange(File f, String content) throws Exception {
GitClient client = getClient(workDir);
write(f, content);
File[] roots = new File[] { f };
client.add(roots, NULL_PROGRESS_MONITOR);
return client.commit(roots, "local change: " + content, null, null, NULL_PROGRESS_MONITOR).getRevision();
}
See More Examples