Lines 56-61
Link Here
|
56 |
import org.netbeans.libs.git.GitException; |
56 |
import org.netbeans.libs.git.GitException; |
57 |
import org.netbeans.libs.git.GitMergeResult; |
57 |
import org.netbeans.libs.git.GitMergeResult; |
58 |
import org.netbeans.libs.git.GitMergeResult.MergeStatus; |
58 |
import org.netbeans.libs.git.GitMergeResult.MergeStatus; |
|
|
59 |
import org.netbeans.libs.git.GitRepository; |
59 |
import org.netbeans.libs.git.GitRevisionInfo; |
60 |
import org.netbeans.libs.git.GitRevisionInfo; |
60 |
import org.netbeans.libs.git.GitTransportUpdate; |
61 |
import org.netbeans.libs.git.GitTransportUpdate; |
61 |
import org.netbeans.libs.git.SearchCriteria; |
62 |
import org.netbeans.libs.git.SearchCriteria; |
Lines 381-384
Link Here
|
381 |
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); |
382 |
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); |
382 |
client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); |
383 |
client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); |
383 |
} |
384 |
} |
|
|
385 |
|
386 |
public void testMergeNoFastForward () throws Exception { |
387 |
File f = new File(workDir, "file"); |
388 |
write(f, "init"); |
389 |
add(f); |
390 |
commit(f); |
391 |
|
392 |
GitClient client = getClient(workDir); |
393 |
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR); |
394 |
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); |
395 |
write(f, BRANCH_NAME); |
396 |
add(f); |
397 |
GitRevisionInfo info = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR); |
398 |
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); |
399 |
|
400 |
assertEquals("init", read(f)); |
401 |
|
402 |
GitMergeResult result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); |
403 |
assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); |
404 |
assertEquals(BRANCH_NAME, read(f)); |
405 |
|
406 |
SearchCriteria crit = new SearchCriteria(); |
407 |
crit.setRevisionTo(Constants.MASTER); |
408 |
GitRevisionInfo[] logs = client.log(crit, NULL_PROGRESS_MONITOR); |
409 |
assertEquals(2, logs.length); |
410 |
assertEquals(logs[0].getRevision(), info.getRevision()); |
411 |
|
412 |
// continue working on branch |
413 |
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); |
414 |
remove(false, f); |
415 |
client.commit(new File[] { f }, "delete on branch", null, null, NULL_PROGRESS_MONITOR); |
416 |
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); |
417 |
|
418 |
assertEquals(BRANCH_NAME, read(f)); |
419 |
|
420 |
result = client.merge(BRANCH_NAME, GitRepository.FastForwardOption.NO_FAST_FORWARD, NULL_PROGRESS_MONITOR); |
421 |
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); |
422 |
assertFalse(f.exists()); |
423 |
|
424 |
crit = new SearchCriteria(); |
425 |
crit.setRevisionTo(Constants.MASTER); |
426 |
logs = client.log(crit, NULL_PROGRESS_MONITOR); |
427 |
assertEquals(4, logs.length); |
428 |
assertEquals(2, logs[0].getParents().length); |
429 |
} |
430 |
|
431 |
public void testMergeFFOnly () throws Exception { |
432 |
File f1 = new File(workDir, "file1"); |
433 |
File f2 = new File(workDir, "file2"); |
434 |
write(f1, "init"); |
435 |
write(f2, "init"); |
436 |
add(f1, f2); |
437 |
commit(f1, f2); |
438 |
|
439 |
GitClient client = getClient(workDir); |
440 |
client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR); |
441 |
client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); |
442 |
write(f1, BRANCH_NAME); |
443 |
add(f1); |
444 |
client.commit(new File[] { f1 }, "change on branch", null, null, NULL_PROGRESS_MONITOR); |
445 |
client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); |
446 |
write(f2, "another change"); |
447 |
add(f2); |
448 |
client.commit(new File[] { f2 }, "change on master", null, null, NULL_PROGRESS_MONITOR); |
449 |
|
450 |
GitMergeResult result = client.merge(BRANCH_NAME, GitRepository.FastForwardOption.FAST_FORWARD_ONLY, NULL_PROGRESS_MONITOR); |
451 |
// no merge commits allowed => FAIL |
452 |
assertEquals(MergeStatus.ABORTED, result.getMergeStatus()); |
453 |
|
454 |
// test also config files |
455 |
assertEquals(GitRepository.FastForwardOption.FAST_FORWARD, GitRepository.getInstance(workDir).getDefaultFastForwardOption()); |
456 |
|
457 |
StoredConfig cfg = repo.getConfig(); |
458 |
cfg.setEnum(ConfigConstants.CONFIG_KEY_MERGE, null, |
459 |
ConfigConstants.CONFIG_KEY_FF, org.eclipse.jgit.api.MergeCommand.FastForwardMode.Merge.ONLY); |
460 |
cfg.save(); |
461 |
assertEquals(GitRepository.FastForwardOption.FAST_FORWARD_ONLY, GitRepository.getInstance(workDir).getDefaultFastForwardOption()); |
462 |
result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); |
463 |
// no merge commits allowed => FAIL |
464 |
assertEquals(MergeStatus.ABORTED, result.getMergeStatus()); |
465 |
|
466 |
result = client.merge(BRANCH_NAME, GitRepository.FastForwardOption.FAST_FORWARD, NULL_PROGRESS_MONITOR); |
467 |
// merge commits allowed => OK |
468 |
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); |
469 |
} |
384 |
} |
470 |
} |