diff test/org/tmatesoft/hg/test/TestCommit.java @ 612:dca70c0b1f74

Test tags, branches and hgingore information get refreshed on external (and/or internal) change
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 10 May 2013 14:29:35 +0200
parents 66f1cc23b906
children f41dd9a3b8af
line wrap: on
line diff
--- a/test/org/tmatesoft/hg/test/TestCommit.java	Thu May 09 21:52:01 2013 +0200
+++ b/test/org/tmatesoft/hg/test/TestCommit.java	Fri May 10 14:29:35 2013 +0200
@@ -271,7 +271,7 @@
 	
 	@Test
 	public void testUpdateActiveBookmark() throws Exception {
-		File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit-cmd", false);
+		File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit-bookmark-update", false);
 		ExecHelper eh = new ExecHelper(new OutputParser.Stub(), repoLoc);
 		String activeBookmark = "bm1";
 		eh.run("hg", "bookmarks", activeBookmark);
@@ -299,6 +299,33 @@
 		errorCollector.assertEquals(activeBookmark, hgRepo.getBookmarks().getActiveBookmarkName());
 		errorCollector.assertEquals(c, hgRepo.getBookmarks().getRevision(activeBookmark));
 	}
+
+	@Test
+	public void testRefreshTagsAndBranches() throws Exception {
+		File repoLoc = RepoUtils.cloneRepoToTempLocation("log-branches", "test-refresh-after-commit", false);
+		final String tag = "tag.refresh", branch = "branch-refresh";
+		HgRepository hgRepo = new HgLookup().detect(repoLoc);
+		assertFalse(hgRepo.getTags().getAllTags().containsKey(tag));
+		assertNull(hgRepo.getBranches().getBranch(branch));
+		RepoUtils.modifyFileAppend(new File(repoLoc, "a"), "whatever");
+		//
+		final int parentCsetRevIndex = hgRepo.getChangelog().getLastRevision();
+		// HgCommitCommand can't do branch yet
+		CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), parentCsetRevIndex);
+		cf.add(hgRepo.getFileNode("a"), new FileContentSupplier(new File(repoLoc, "a")));
+		cf.branch(branch);
+		Nodeid commit = cf.commit("FIRST");
+		errorCollector.assertEquals("commit with branch shall update WC", branch, hgRepo.getWorkingCopyBranchName());
+		
+		ExecHelper eh = new ExecHelper(new OutputParser.Stub(), repoLoc);
+		eh.run("hg", "tag", tag);
+		assertEquals("[sanity]", 0, eh.getExitValue());
+		
+		errorCollector.assertTrue(hgRepo.getTags().getAllTags().containsKey(tag));
+		errorCollector.assertFalse(hgRepo.getBranches().getBranch(branch) == null);
+		errorCollector.assertTrue(hgRepo.getTags().tagged(tag).contains(commit));
+		errorCollector.assertTrue(hgRepo.getTags().tags(commit).contains(tag));
+	}
 	
 	private void assertHgVerifyOk(File repoLoc) throws InterruptedException, IOException {
 		ExecHelper verifyRun = new ExecHelper(new OutputParser.Stub(), repoLoc);