diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/AbstractGitTestCase.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/AbstractGitTestCase.java index 3f149bb81046..fb9d17c0f66e 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/AbstractGitTestCase.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/AbstractGitTestCase.java @@ -35,6 +35,7 @@ import java.util.Map; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEntry; +import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; @@ -60,6 +61,7 @@ public class AbstractGitTestCase extends NbTestCase { private final File repositoryLocation; private JGitRepository localRepository; protected static final ProgressMonitor NULL_PROGRESS_MONITOR = new NullProgressMonitor (); + private String defaultBranchName; public AbstractGitTestCase (String testName) throws IOException { super(testName); @@ -170,6 +172,15 @@ private void initializeRepository() throws Exception { localRepository = (JGitRepository) f.get(fact); client.release(); } + // cache defaut branch name + defaultBranchName = repository.getConfig().getString(ConfigConstants.CONFIG_INIT_SECTION, null, ConfigConstants.CONFIG_KEY_DEFAULT_BRANCH); + if (defaultBranchName == null) { + defaultBranchName = Constants.MASTER; + } + } + + protected String getDefaultBranch() { + return defaultBranchName; } protected GitClient getClient (File repository) throws GitException { diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/BranchTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/BranchTest.java index cbed6a01d6ff..ecc093b43e4c 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/BranchTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/BranchTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -49,13 +48,14 @@ * @author ondra */ public class BranchTest extends AbstractGitTestCase { + private Repository repository; private File workDir; private static final String BRANCH_NAME = "new_branch"; private static final String BRANCH_NAME_2 = "new_branch2"; private static final String BRANCH_NAME_3 = "new_branch3"; - public BranchTest (String testName) throws IOException { + public BranchTest(String testName) throws IOException { super(testName); } @@ -66,14 +66,14 @@ protected void setUp() throws Exception { repository = getRepository(getLocalGitRepository()); } - public void testListBranches () throws Exception { + public void testListBranches() throws Exception { GitClient client = getClient(workDir); Map branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertEquals(0, branches.size()); - + File f = new File(workDir, "file"); write(f, "hello"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; client.add(files, NULL_PROGRESS_MONITOR); client.commit(files, "init", null, null, NULL_PROGRESS_MONITOR); write(f, "hello again"); @@ -85,18 +85,18 @@ public void testListBranches () throws Exception { branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(1, branches.size()); - assertEquals("master", branches.get("master").getName()); - assertEquals(commitId, branches.get("master").getId()); - assertFalse(branches.get("master").isRemote()); - assertTrue(branches.get("master").isActive()); + assertEquals(getDefaultBranch(), branches.get(getDefaultBranch()).getName()); + assertEquals(commitId, branches.get(getDefaultBranch()).getId()); + assertFalse(branches.get(getDefaultBranch()).isRemote()); + assertTrue(branches.get(getDefaultBranch()).isActive()); write(new File(workDir, ".git/refs/heads/nova"), commitId); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); - assertEquals("master", branches.get("master").getName()); - assertFalse(branches.get("master").isRemote()); - assertTrue(branches.get("master").isActive()); - assertEquals(commitId, branches.get("master").getId()); + assertEquals(getDefaultBranch(), branches.get(getDefaultBranch()).getName()); + assertFalse(branches.get(getDefaultBranch()).isRemote()); + assertTrue(branches.get(getDefaultBranch()).isActive()); + assertEquals(commitId, branches.get(getDefaultBranch()).getId()); assertEquals("nova", branches.get("nova").getName()); assertFalse(branches.get("nova").isRemote()); assertFalse(branches.get("nova").isActive()); @@ -110,18 +110,18 @@ public void testListBranches () throws Exception { assertFalse(branches.get(GitBranch.NO_BRANCH).isRemote()); assertTrue(branches.get(GitBranch.NO_BRANCH).isActive()); assertEquals(commitId, branches.get(GitBranch.NO_BRANCH).getId()); - assertEquals("master", branches.get("master").getName()); - assertFalse(branches.get("master").isRemote()); - assertFalse(branches.get("master").isActive()); + assertEquals(getDefaultBranch(), branches.get(getDefaultBranch()).getName()); + assertFalse(branches.get(getDefaultBranch()).isRemote()); + assertFalse(branches.get(getDefaultBranch()).isActive()); assertEquals("nova", branches.get("nova").getName()); assertFalse(branches.get("nova").isRemote()); assertFalse(branches.get("nova").isActive()); } - - public void testCreateBranch () throws Exception { + + public void testCreateBranch() throws Exception { File f = new File(workDir, "file"); write(f, "hello"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); commit(files); write(f, "hello again"); @@ -136,7 +136,7 @@ public void testCreateBranch () throws Exception { GitBranch branch = client.createBranch(BRANCH_NAME, commitId, NULL_PROGRESS_MONITOR); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); - assertTrue(branches.containsKey("master")); + assertTrue(branches.containsKey(getDefaultBranch())); assertTrue(branches.containsKey(BRANCH_NAME)); assertEquals(BRANCH_NAME, branch.getName()); assertEquals(commitId, branch.getId()); @@ -147,25 +147,25 @@ public void testCreateBranch () throws Exception { assertEquals(commitId, branch.getId()); assertFalse(branch.isActive()); assertFalse(branch.isRemote()); - assertTrue(branches.get("master").isActive()); + assertTrue(branches.get(getDefaultBranch()).isActive()); assertEquals(commitId, read(new File(workDir, ".git/refs/heads/" + BRANCH_NAME))); client.createBranch(BRANCH_NAME_2, Constants.HEAD, NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(3, branches.size()); - assertTrue(branches.containsKey("master")); + assertTrue(branches.containsKey(getDefaultBranch())); assertTrue(branches.containsKey(BRANCH_NAME)); assertTrue(branches.containsKey(BRANCH_NAME_2)); - assertTrue(branches.get("master").isActive()); + assertTrue(branches.get(getDefaultBranch()).isActive()); assertEquals(lastCommitId, read(new File(workDir, ".git/refs/heads/" + BRANCH_NAME_2))); - client.createBranch(BRANCH_NAME_3, "refs/heads/master", NULL_PROGRESS_MONITOR); + client.createBranch(BRANCH_NAME_3, "refs/heads/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(4, branches.size()); - assertTrue(branches.containsKey("master")); + assertTrue(branches.containsKey(getDefaultBranch())); assertTrue(branches.containsKey(BRANCH_NAME)); assertTrue(branches.containsKey(BRANCH_NAME_2)); assertTrue(branches.containsKey(BRANCH_NAME_3)); - assertTrue(branches.get("master").isActive()); + assertTrue(branches.get(getDefaultBranch()).isActive()); assertEquals(lastCommitId, read(new File(workDir, ".git/refs/heads/" + BRANCH_NAME_3))); try { @@ -177,32 +177,32 @@ public void testCreateBranch () throws Exception { } branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(4, branches.size()); - assertTrue(branches.get("master").isActive()); + assertTrue(branches.get(getDefaultBranch()).isActive()); assertEquals(commitId, read(new File(workDir, ".git/refs/heads/" + BRANCH_NAME))); } - public void testCreateBranchWithRebase () throws Exception { + public void testCreateBranchWithRebase() throws Exception { final 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); + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + client.commit(new File[]{f}, "init commit", null, null, NULL_PROGRESS_MONITOR); client = getClient(workDir); client.setRemote(new GitRemoteConfig("origin", - Arrays.asList(new String[] { otherWT.getAbsolutePath() }), - Arrays.asList(new String[] { otherWT.getAbsolutePath() }), - Arrays.asList(new String[] { "refs/heads/*:refs/remotes/origin/*" }), - Arrays.asList(new String[] { "refs/remotes/origin/*:refs/heads/*" })), NULL_PROGRESS_MONITOR); + Arrays.asList(new String[]{otherWT.getAbsolutePath()}), + Arrays.asList(new String[]{otherWT.getAbsolutePath()}), + Arrays.asList(new String[]{"refs/heads/*:refs/remotes/origin/*"}), + Arrays.asList(new String[]{"refs/remotes/origin/*:refs/heads/*"})), NULL_PROGRESS_MONITOR); client.fetch("origin", NULL_PROGRESS_MONITOR); StoredConfig config = repository.getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE, ConfigConstants.CONFIG_KEY_NEVER); config.save(); - GitBranch b = client.createBranch(BRANCH_NAME, "origin/master", NULL_PROGRESS_MONITOR); + GitBranch b = client.createBranch(BRANCH_NAME, "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); assertFalse(repository.getConfig().getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, BRANCH_NAME, ConfigConstants.CONFIG_KEY_REBASE, false)); client.deleteBranch(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); @@ -210,103 +210,103 @@ public void testCreateBranchWithRebase () throws Exception { config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE, ConfigConstants.CONFIG_KEY_REMOTE); config.save(); - b = client.createBranch(BRANCH_NAME, "origin/master", NULL_PROGRESS_MONITOR); + b = client.createBranch(BRANCH_NAME, "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); assertTrue(repository.getConfig().getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, BRANCH_NAME, ConfigConstants.CONFIG_KEY_REBASE, false)); } - - public void testFileProtocolFails () throws Exception { + + public void testFileProtocolFails() throws Exception { try { Transport.open(repository, new URIish(workDir.toURI().toURL())); fail("Workaround not needed, fix ListRemoteBranchesCommand - Transport.open(String) to Transport.open(URL)"); } catch (NotSupportedException ex) { - + } } - - public void testListRemoteBranches () throws Exception { + + public void testListRemoteBranches() 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); - GitBranch branch = client.createBranch(BRANCH_NAME, "master", NULL_PROGRESS_MONITOR); + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + client.commit(new File[]{f}, "init commit", null, null, NULL_PROGRESS_MONITOR); + GitBranch branch = client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); write(f, "change on master"); - client.add(new File[] { f }, NULL_PROGRESS_MONITOR); - GitRevisionInfo master = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR); - + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + GitRevisionInfo master = client.commit(new File[]{f}, "change on master", null, null, NULL_PROGRESS_MONITOR); + Map remoteBranches = getClient(workDir).listRemoteBranches(otherWT.getAbsolutePath(), NULL_PROGRESS_MONITOR); assertEquals(2, remoteBranches.size()); assertEquals(branch.getId(), remoteBranches.get(BRANCH_NAME).getId()); - assertEquals(master.getRevision(), remoteBranches.get("master").getId()); + assertEquals(master.getRevision(), remoteBranches.get(getDefaultBranch()).getId()); } - - public void testDeleteUntrackedLocalBranch () throws Exception { + + public void testDeleteUntrackedLocalBranch() throws Exception { File f = new File(workDir, "f"); - File[] files = { f }; + File[] files = {f}; write(f, "init"); add(files); commit(files); GitClient client = getClient(workDir); - GitBranch b = client.createBranch(BRANCH_NAME, "master", NULL_PROGRESS_MONITOR); + GitBranch b = client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); Map branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); assertNotNull(branches.get(BRANCH_NAME)); assertEquals(0, repository.getConfig().getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION).size()); - + // delete branch client.deleteBranch(BRANCH_NAME, false, NULL_PROGRESS_MONITOR); branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertEquals(1, branches.size()); assertNull(branches.get(BRANCH_NAME)); } - - public void testDeleteTrackedBranch () throws Exception { + + public void testDeleteTrackedBranch() throws Exception { final 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); - + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + client.commit(new File[]{f}, "init commit", null, null, NULL_PROGRESS_MONITOR); + client = getClient(workDir); client.setRemote(new GitRemoteConfig("origin", - Arrays.asList(new String[] { otherWT.getAbsolutePath() }), - Arrays.asList(new String[] { otherWT.getAbsolutePath() }), - Arrays.asList(new String[] { "refs/heads/*:refs/remotes/origin/*" }), - Arrays.asList(new String[] { "refs/remotes/origin/*:refs/heads/*" })), NULL_PROGRESS_MONITOR); + Arrays.asList(new String[]{otherWT.getAbsolutePath()}), + Arrays.asList(new String[]{otherWT.getAbsolutePath()}), + Arrays.asList(new String[]{"refs/heads/*:refs/remotes/origin/*"}), + Arrays.asList(new String[]{"refs/remotes/origin/*:refs/heads/*"})), NULL_PROGRESS_MONITOR); client.fetch("origin", NULL_PROGRESS_MONITOR); - client.checkoutRevision("origin/master", true, NULL_PROGRESS_MONITOR); - GitBranch b = client.createBranch(BRANCH_NAME, "origin/master", NULL_PROGRESS_MONITOR); + client.checkoutRevision("origin/" + getDefaultBranch(), true, NULL_PROGRESS_MONITOR); + GitBranch b = client.createBranch(BRANCH_NAME, "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); Map branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); assertNotNull(branches.get(BRANCH_NAME)); assertEquals(1, repository.getConfig().getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION).size()); - + //delete tracked branch and test client.deleteBranch(BRANCH_NAME, false, NULL_PROGRESS_MONITOR); branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertEquals(1, branches.size()); assertNull(branches.get(BRANCH_NAME)); - assertEquals(0, repository.getConfig().getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION).size()); + assertEquals(0, repository.getConfig().getSubsections(ConfigConstants.CONFIG_BRANCH_SECTION).size()); } - - public void testDeleteUnmergedBranch () throws Exception { + + public void testDeleteUnmergedBranch() throws Exception { File f = new File(workDir, "f"); - File[] files = { f }; + File[] files = {f}; write(f, "init"); add(files); commit(files); GitClient client = getClient(workDir); - GitBranch b = client.createBranch(BRANCH_NAME, "master", NULL_PROGRESS_MONITOR); + GitBranch b = client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); write(f, "change on branch"); add(files); commit(files); //checkout other revision - client.checkoutRevision("master", true, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); Map branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); assertNotNull(branches.get(BRANCH_NAME)); @@ -326,89 +326,89 @@ public void testDeleteUnmergedBranch () throws Exception { assertEquals(1, branches.size()); assertNull(branches.get(BRANCH_NAME)); } - - public void testDeleteActiveBranch () throws Exception { + + public void testDeleteActiveBranch() throws Exception { File f = new File(workDir, "f"); - File[] files = { f }; + File[] files = {f}; write(f, "init"); add(files); commit(files); GitClient client = getClient(workDir); try { - client.deleteBranch("master", true, NULL_PROGRESS_MONITOR); + client.deleteBranch(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); fail("Can not delete active branch"); } catch (GitException ex) { - assertTrue(ex.getMessage().contains("Branch master is checked out and cannot be deleted")); + assertTrue(ex.getMessage().contains("Branch " + getDefaultBranch() + " is checked out and cannot be deleted")); } } - - public void testDeleteRemoteBranch () throws Exception { + + public void testDeleteRemoteBranch() throws Exception { final 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); - + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + client.commit(new File[]{f}, "init commit", null, null, NULL_PROGRESS_MONITOR); + client = getClient(workDir); - client.fetch(otherWT.getAbsolutePath(), Arrays.asList(new String[] { "refs/heads/*:refs/remotes/origin/*" }), NULL_PROGRESS_MONITOR); + client.fetch(otherWT.getAbsolutePath(), Arrays.asList(new String[]{"refs/heads/*:refs/remotes/origin/*"}), NULL_PROGRESS_MONITOR); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(1, branches.size()); - assertNotNull(branches.get("origin/master")); - + assertNotNull(branches.get("origin/" + getDefaultBranch())); + // delete remote branch - client.deleteBranch("origin/master", false, NULL_PROGRESS_MONITOR); + client.deleteBranch("origin/" + getDefaultBranch(), false, NULL_PROGRESS_MONITOR); branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertEquals(0, branches.size()); } - - public void testBranchTracking () throws Exception { + + public void testBranchTracking() throws Exception { final 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); - + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + client.commit(new File[]{f}, "init commit", null, null, NULL_PROGRESS_MONITOR); + client = getClient(workDir); - client.setRemote(new GitRemoteConfig("origin", + client.setRemote(new GitRemoteConfig("origin", Arrays.asList(otherWT.getAbsolutePath()), Arrays.asList(otherWT.getAbsolutePath()), Arrays.asList("+refs/heads/*:refs/remotes/origin/*"), Collections.emptyList()), NULL_PROGRESS_MONITOR); client.fetch("origin", NULL_PROGRESS_MONITOR); - GitBranch b = client.createBranch(Constants.MASTER, "origin/master", NULL_PROGRESS_MONITOR); - assertEquals("origin/master", b.getTrackedBranch().getName()); + GitBranch b = client.createBranch(getDefaultBranch(), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); + assertEquals("origin/" + getDefaultBranch(), b.getTrackedBranch().getName()); assertTrue(b.getTrackedBranch().isRemote()); - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); - - b = client.createBranch("nova1", Constants.MASTER, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); + + b = client.createBranch("nova1", getDefaultBranch(), NULL_PROGRESS_MONITOR); assertNull(b.getTrackedBranch()); - + StoredConfig cfg = repository.getConfig(); cfg.setString(ConfigConstants.CONFIG_BRANCH_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOSETUPMERGE, "always"); cfg.save(); - b = client.createBranch("nova2", Constants.MASTER, NULL_PROGRESS_MONITOR); - assertEquals("master", b.getTrackedBranch().getName()); + b = client.createBranch("nova2", getDefaultBranch(), NULL_PROGRESS_MONITOR); + assertEquals(getDefaultBranch(), b.getTrackedBranch().getName()); assertFalse(b.getTrackedBranch().isRemote()); - + // list branches Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); - b = branches.get(Constants.MASTER); - assertEquals("origin/master", b.getTrackedBranch().getName()); + b = branches.get(getDefaultBranch()); + assertEquals("origin/" + getDefaultBranch(), b.getTrackedBranch().getName()); assertTrue(b.getTrackedBranch().isRemote()); - b = branches.get("origin/master"); + b = branches.get("origin/" + getDefaultBranch()); assertNull(b.getTrackedBranch()); } - - public void testListBranches_Issue213538 () throws Exception { + + public void testListBranches_Issue213538() throws Exception { GitClient client = getClient(workDir); File 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); - + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + client.commit(new File[]{f}, "init commit", null, null, NULL_PROGRESS_MONITOR); + // cannot end with a RuntimeException File configFile = new File(Utils.getMetadataFolder(workDir), Constants.CONFIG); String config = read(configFile); @@ -421,26 +421,26 @@ public void testListBranches_Issue213538 () throws Exception { assertEquals("It seems the config file for repository at [" + workDir + "] is corrupted.\nEnsure it's valid.", ex.getMessage()); } } - - public void testCreateInitialBranch () throws Exception { + + public void testCreateInitialBranch() throws Exception { File emptyRepo = new File(workDir, "empty"); GitClient client = getClient(emptyRepo); client.init(NULL_PROGRESS_MONITOR); Repository repo = getRepository(client); FileBasedConfig cfg = new FileBasedConfig(repo.getFS().resolve(repo.getDirectory(), Constants.CONFIG), - repo.getFS()); + repo.getFS()); cfg.load(); assertFalse(cfg.getSections().contains(ConfigConstants.CONFIG_BRANCH_SECTION)); - client.createBranch(Constants.MASTER, Constants.R_REMOTES + "origin/whateverbranch", NULL_PROGRESS_MONITOR); + client.createBranch(getDefaultBranch(), Constants.R_REMOTES + "origin/whateverbranch", NULL_PROGRESS_MONITOR); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertTrue(branches.isEmpty()); cfg = new FileBasedConfig(repo.getFS().resolve(repo.getDirectory(), Constants.CONFIG), - repo.getFS()); + repo.getFS()); cfg.load(); assertTrue(cfg.getSections().contains(ConfigConstants.CONFIG_BRANCH_SECTION)); assertEquals("origin", cfg.getString(ConfigConstants.CONFIG_BRANCH_SECTION, - Constants.MASTER, ConfigConstants.CONFIG_KEY_REMOTE)); + getDefaultBranch(), ConfigConstants.CONFIG_KEY_REMOTE)); assertEquals(Constants.R_HEADS + "whateverbranch", cfg.getString(ConfigConstants.CONFIG_BRANCH_SECTION, - Constants.MASTER, ConfigConstants.CONFIG_KEY_MERGE)); + getDefaultBranch(), ConfigConstants.CONFIG_KEY_MERGE)); } } diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CheckoutTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CheckoutTest.java index 34889db08a38..172fd3b1ad6b 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CheckoutTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CheckoutTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.BufferedInputStream; @@ -69,13 +68,12 @@ public class CheckoutTest extends AbstractGitTestCase { private Repository repository; private static final String BRANCH = "nova"; - public CheckoutTest (String testName) throws IOException { + public CheckoutTest(String testName) throws IOException { super(testName); if (Boolean.getBoolean("skip.git.integration.tests")) { Filter filter = new Filter(); - filter.setExcludes(new Filter.IncludeExclude[] { - new Filter.IncludeExclude("testLargeFile", ""), - }); + filter.setExcludes(new Filter.IncludeExclude[]{ + new Filter.IncludeExclude("testLargeFile", ""),}); setFilter(filter); } } @@ -87,7 +85,7 @@ protected void setUp() throws Exception { repository = getRepository(getLocalGitRepository()); } - public void testJGitCheckout () throws Exception { + public void testJGitCheckout() throws Exception { File file1 = new File(workDir, "file1"); write(file1, "blablablabla"); Git git = new Git(repository); @@ -110,12 +108,12 @@ public void testJGitCheckout () throws Exception { } } - public void testCheckoutFilesFromIndex () throws Exception { + public void testCheckoutFilesFromIndex() throws Exception { File file1 = new File(workDir, "file1"); write(file1, "file 1 content"); File file2 = new File(workDir, "file2"); write(file2, "file 2 content"); - File[] files = new File[] { file1, file2 }; + File[] files = new File[]{file1, file2}; add(files); commit(files); @@ -132,14 +130,14 @@ public void testCheckoutFilesFromIndex () throws Exception { Map statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); - client.checkout(new File[] { file1 }, null, true, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{file1}, null, true, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); assertEquals(content1, read(file1)); assertEquals(content2, read(file2)); write(file1, "another change in file 1"); - client.checkout(new File[] { file1 }, null, false, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{file1}, null, false, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); @@ -150,14 +148,14 @@ public void testCheckoutFilesFromIndex () throws Exception { statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_REMOVED, GitStatus.Status.STATUS_REMOVED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); - client.checkout(new File[] { file1 }, null, true, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{file1}, null, true, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); assertEquals(content1, read(file1)); assertEquals(content2, read(file2)); file1.delete(); - client.checkout(new File[] { file1 }, null, false, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{file1}, null, false, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); @@ -166,7 +164,7 @@ public void testCheckoutFilesFromIndex () throws Exception { } // @TODO randomly failing - public void /*test*/CheckoutFilesFromIndex_NotRecursive () throws Exception { + public void /*test*/ CheckoutFilesFromIndex_NotRecursive() throws Exception { File folder = new File(workDir, "folder"); folder.mkdirs(); File file1 = new File(folder, "file1"); @@ -175,7 +173,7 @@ public void testCheckoutFilesFromIndex () throws Exception { subFolder.mkdirs(); File file2 = new File(subFolder, "file2"); write(file2, "file 2 content"); - File[] files = new File[] { file1, file2 }; + File[] files = new File[]{file1, file2}; add(files); commit(files); @@ -194,7 +192,7 @@ public void testCheckoutFilesFromIndex () throws Exception { assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); // direct file descendants - client.checkout(new File[] { folder }, null, false, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{folder}, null, false, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); @@ -203,7 +201,7 @@ public void testCheckoutFilesFromIndex () throws Exception { write(file1, content2); // recursive - client.checkout(new File[] { folder }, null, true, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{folder}, null, true, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); @@ -211,11 +209,11 @@ public void testCheckoutFilesFromIndex () throws Exception { assertEquals(content1, read(file2)); } - public void testCheckoutFilesFromIndexFolderToFile () throws Exception { + public void testCheckoutFilesFromIndexFolderToFile() throws Exception { File file1 = new File(workDir, "file1"); write(file1, "file 1 content"); File file2 = new File(file1, "file2"); - File[] files = new File[] { file1 }; + File[] files = new File[]{file1}; add(files); commit(files); @@ -226,20 +224,20 @@ public void testCheckoutFilesFromIndexFolderToFile () throws Exception { GitClient client = getClient(workDir); Map statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_REMOVED, GitStatus.Status.STATUS_REMOVED, false); - client.checkout(new File[] { file1 }, null, true, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{file1}, null, true, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); - assert(file1.isFile()); + assert (file1.isFile()); assertEquals("file 1 content", read(file1)); } - public void testCheckoutFilesFromIndexFileToFolder () throws Exception { + public void testCheckoutFilesFromIndexFileToFolder() throws Exception { File folder = new File(workDir, "folder"); File subFolder = new File(folder, "folder"); File file1 = new File(subFolder, "file2"); subFolder.mkdirs(); write(file1, "file 1 content"); - File[] files = new File[] { folder }; + File[] files = new File[]{folder}; add(files); commit(files); @@ -251,17 +249,17 @@ public void testCheckoutFilesFromIndexFileToFolder () throws Exception { GitClient client = getClient(workDir); Map statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_REMOVED, GitStatus.Status.STATUS_REMOVED, false); - client.checkout(new File[] { folder }, null, true, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{folder}, null, true, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); - assert(file1.isFile()); + assert (file1.isFile()); assertEquals("file 1 content", read(file1)); } - public void testCheckoutPathsFromRevision () throws Exception { + public void testCheckoutPathsFromRevision() throws Exception { File file1 = new File(workDir, "file1"); write(file1, "file 1 content"); - File[] files = new File[] { file1 }; + File[] files = new File[]{file1}; add(files); commit(files); @@ -279,13 +277,13 @@ public void testCheckoutPathsFromRevision () throws Exception { GitClient client = getClient(workDir); Map statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); - client.checkout(new File[] { file1 }, currentRevision, true, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{file1}, currentRevision, true, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertEquals(content1, read(file1)); assertEquals(currentRevision, new Git(repository).log().call().iterator().next().getId().getName()); write(file1, "another change in file 1"); - client.checkout(new File[] { file1 }, currentRevision, true, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{file1}, currentRevision, true, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertEquals(content1, read(file1)); @@ -294,21 +292,20 @@ public void testCheckoutPathsFromRevision () throws Exception { write(file1, "another change in file 1"); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); - client.checkout(new File[] { file1 }, previousRevision, true, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{file1}, previousRevision, true, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertEquals("file 1 content", read(file1)); assertEquals(currentRevision, new Git(repository).log().call().iterator().next().getId().getName()); write(file1, "another change in file 1"); - client.checkout(new File[] { file1 }, previousRevision, false, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{file1}, previousRevision, false, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertEquals("file 1 content", read(file1)); assertEquals(currentRevision, new Git(repository).log().call().iterator().next().getId().getName()); } - - - public void testCheckoutPathsFromRevision_NotRecursive () throws Exception { + + public void testCheckoutPathsFromRevision_NotRecursive() throws Exception { File folder = new File(workDir, "folder"); folder.mkdirs(); File file1 = new File(folder, "file1"); @@ -317,7 +314,7 @@ public void testCheckoutPathsFromRevision_NotRecursive () throws Exception { subFolder.mkdirs(); File file2 = new File(subFolder, "file2"); write(file2, "file 2 content"); - File[] files = new File[] { file1, file2 }; + File[] files = new File[]{file1, file2}; add(files); GitClient client = getClient(workDir); commit(files); @@ -332,7 +329,7 @@ public void testCheckoutPathsFromRevision_NotRecursive () throws Exception { assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); // direct file descendants - client.checkout(new File[] { folder }, "HEAD", false, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{folder}, "HEAD", false, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); @@ -341,13 +338,13 @@ public void testCheckoutPathsFromRevision_NotRecursive () throws Exception { write(file1, content1); add(files); // recursive - client.checkout(new File[] { folder }, "HEAD", true, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{folder}, "HEAD", true, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); } - public void testLargeFile () throws Exception { + public void testLargeFile() throws Exception { unpack("large.dat.zip"); File large = new File(workDir, "large.dat"); assertTrue(large.exists()); @@ -362,169 +359,169 @@ public void testLargeFile () throws Exception { .setRecursiveDeletion(false) .checkout(e, null, repository.newObjectReader(), null); } - - public void testCheckoutBranch () throws Exception { + + public void testCheckoutBranch() throws Exception { File file = new File(workDir, "file"); write(file, "initial"); - File[] files = new File[] { file }; + 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); - - write(file, Constants.MASTER); + + write(file, getDefaultBranch()); add(file); - GitRevisionInfo masterInfo = client.commit(files, Constants.MASTER, null, null, NULL_PROGRESS_MONITOR); - + GitRevisionInfo masterInfo = client.commit(files, getDefaultBranch(), null, null, NULL_PROGRESS_MONITOR); + // test checkout Monitor m = new Monitor(); client.addNotificationListener(m); client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); String logFileContent[] = read(new File(workDir, ".git/logs/HEAD")).split("\\n"); - assertEquals("checkout: moving from master to nova", logFileContent[logFileContent.length - 1].substring(logFileContent[logFileContent.length - 1].indexOf("checkout: "))); + assertEquals("checkout: moving from " + getDefaultBranch() + " to nova", logFileContent[logFileContent.length - 1].substring(logFileContent[logFileContent.length - 1].indexOf("checkout: "))); assertTrue(m.notifiedFiles.contains(file)); assertEquals("initial", read(file)); - Map statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); Map branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertTrue(branches.get(BRANCH).isActive()); - + write(file, BRANCH); add(); GitRevisionInfo novaInfo = client.commit(files, BRANCH, null, null, NULL_PROGRESS_MONITOR); m = new Monitor(); client.addNotificationListener(m); - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); assertTrue(m.notifiedFiles.contains(file)); - assertEquals(Constants.MASTER, read(file)); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + assertEquals(getDefaultBranch(), read(file)); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); branches = client.getBranches(false, NULL_PROGRESS_MONITOR); - assertTrue(branches.get(Constants.MASTER).isActive()); - + assertTrue(branches.get(getDefaultBranch()).isActive()); + m = new Monitor(); client.addNotificationListener(m); client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); assertTrue(m.notifiedFiles.contains(file)); assertEquals(BRANCH, read(file)); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertTrue(branches.get(BRANCH).isActive()); } - - public void testCheckoutRevision () throws Exception { + + public void testCheckoutRevision() throws Exception { File file = new File(workDir, "file"); write(file, "initial"); - File[] files = new File[] { file }; + File[] files = new File[]{file}; add(files); GitClient client = getClient(workDir); GitRevisionInfo info = client.commit(files, "initial", null, null, NULL_PROGRESS_MONITOR); - - write(file, Constants.MASTER); + + write(file, getDefaultBranch()); add(file); - GitRevisionInfo masterInfo = client.commit(files, Constants.MASTER, null, null, NULL_PROGRESS_MONITOR); - + GitRevisionInfo masterInfo = client.commit(files, getDefaultBranch(), null, null, NULL_PROGRESS_MONITOR); + // test checkout Monitor m = new Monitor(); client.addNotificationListener(m); client.checkoutRevision(info.getRevision(), true, NULL_PROGRESS_MONITOR); String logFileContent[] = read(new File(workDir, ".git/logs/HEAD")).split("\\n"); - assertEquals("checkout: moving from master to " + info.getRevision(), logFileContent[logFileContent.length - 1].substring(logFileContent[logFileContent.length - 1].indexOf("checkout: "))); + assertEquals("checkout: moving from " + getDefaultBranch() + " to " + info.getRevision(), logFileContent[logFileContent.length - 1].substring(logFileContent[logFileContent.length - 1].indexOf("checkout: "))); assertTrue(m.notifiedFiles.contains(file)); assertEquals("initial", read(file)); - Map statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); Map branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertTrue(branches.get(GitBranch.NO_BRANCH).isActive()); - + write(file, BRANCH); add(); GitRevisionInfo novaInfo = client.commit(files, BRANCH, null, null, NULL_PROGRESS_MONITOR); m = new Monitor(); client.addNotificationListener(m); - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); assertTrue(m.notifiedFiles.contains(file)); - assertEquals(Constants.MASTER, read(file)); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + assertEquals(getDefaultBranch(), read(file)); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); branches = client.getBranches(false, NULL_PROGRESS_MONITOR); - assertTrue(branches.get(Constants.MASTER).isActive()); + assertTrue(branches.get(getDefaultBranch()).isActive()); } - - public void testCheckoutRevisionKeepLocalChanges () throws Exception { + + public void testCheckoutRevisionKeepLocalChanges() throws Exception { File file = new File(workDir, "file"); write(file, "initial"); - File[] files = new File[] { file }; + 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); - - write(file, Constants.MASTER); - + + write(file, getDefaultBranch()); + // test checkout // the file remains modified in WT client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); - assertEquals(Constants.MASTER, read(file)); - Map statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + assertEquals(getDefaultBranch(), read(file)); + Map statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); Map branches = client.getBranches(false, NULL_PROGRESS_MONITOR); assertTrue(branches.get(BRANCH).isActive()); - + add(file); // the file remains modified in index - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); - assertEquals(Constants.MASTER, read(file)); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); + assertEquals(getDefaultBranch(), read(file)); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); branches = client.getBranches(false, NULL_PROGRESS_MONITOR); - assertTrue(branches.get(Constants.MASTER).isActive()); + assertTrue(branches.get(getDefaultBranch()).isActive()); } - - public void testCheckoutRevisionAddRemoveFile () throws Exception { + + public void testCheckoutRevisionAddRemoveFile() throws Exception { File file = new File(workDir, "file"); write(file, "initial"); - File[] files = new File[] { file }; + 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); - + remove(false, file); commit(files); - + // test checkout // the file is added to WT - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); assertTrue(file.exists()); - Map statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); - + // the file is removed from WT client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); assertFalse(file.exists()); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertNull(statuses.get(file)); } - - public void testCheckoutRevisionMergeLocalChanges () throws Exception { + + public void testCheckoutRevisionMergeLocalChanges() throws Exception { File file = new File(workDir, "file"); write(file, "initial"); - File[] files = new File[] { file }; + 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); write(file, "branch change"); try { - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); fail("Should fail, there are conflicts"); } catch (GitException.CheckoutConflictException ex) { assertEquals(1, ex.getConflicts().length); @@ -535,10 +532,11 @@ public void testCheckoutRevisionMergeLocalChanges () throws Exception { client.reset(BRANCH, GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); write(file, "branch change"); - - CheckoutRevisionCommand cmd = new CheckoutRevisionCommand(repository, ApiUtils.getClassFactory(), Constants.MASTER, false, NULL_PROGRESS_MONITOR, new FileListener() { + + CheckoutRevisionCommand cmd = new CheckoutRevisionCommand(repository, ApiUtils.getClassFactory(), getDefaultBranch(), false, NULL_PROGRESS_MONITOR, new FileListener() { @Override - public void notifyFile (File file, String relativePathToRoot) { } + public void notifyFile(File file, String relativePathToRoot) { + } }); cmd.execute(); Map status = client.getStatus(files, NULL_PROGRESS_MONITOR); @@ -546,128 +544,128 @@ public void notifyFile (File file, String relativePathToRoot) { } assertEquals("<<<<<<< OURS\nbranch change\n=======\ninitial\n>>>>>>> THEIRS", read(file)); } - public void testCheckoutNoHeadYet () throws Exception { + public void testCheckoutNoHeadYet() throws Exception { final 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); - + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + client.commit(new File[]{f}, "init commit", null, null, NULL_PROGRESS_MONITOR); + client = getClient(workDir); - client.fetch(otherWT.getAbsolutePath(), Arrays.asList(new String[] { "refs/heads/*:refs/remotes/origin/*" }), NULL_PROGRESS_MONITOR); - client.checkoutRevision("origin/master", true, NULL_PROGRESS_MONITOR); + client.fetch(otherWT.getAbsolutePath(), Arrays.asList(new String[]{"refs/heads/*:refs/remotes/origin/*"}), NULL_PROGRESS_MONITOR); + client.checkoutRevision("origin/" + getDefaultBranch(), true, NULL_PROGRESS_MONITOR); } // must not checkout from nested repositories - public void testCheckoutIndexNested () throws Exception { + public void testCheckoutIndexNested() throws Exception { File f = new File(workDir, "f"); write(f, "file"); - + GitClient client = getClient(workDir); - client.add(new File[] { f }, NULL_PROGRESS_MONITOR); - client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR); - + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + client.commit(new File[]{f}, "init commit", null, null, NULL_PROGRESS_MONITOR); + File nested = new File(workDir, "nested"); nested.mkdirs(); File f2 = new File(nested, "f"); write(f2, "file"); GitClient clientNested = getClient(nested); clientNested.init(NULL_PROGRESS_MONITOR); - clientNested.add(new File[] { f2 }, NULL_PROGRESS_MONITOR); - clientNested.commit(new File[] { f2 }, "init commit", null, null, NULL_PROGRESS_MONITOR); - + clientNested.add(new File[]{f2}, NULL_PROGRESS_MONITOR); + clientNested.commit(new File[]{f2}, "init commit", null, null, NULL_PROGRESS_MONITOR); + write(f, "change"); write(f2, "change"); - - client.checkout(new File[] { workDir }, null, true, NULL_PROGRESS_MONITOR); - Map statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + + client.checkout(new File[]{workDir}, null, true, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, nested, false, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_ADDED, false); - statuses = clientNested.getStatus(new File[] { nested }, NULL_PROGRESS_MONITOR); + statuses = clientNested.getStatus(new File[]{nested}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, nested, f2, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); - - clientNested.add(new File[] { f2 }, NULL_PROGRESS_MONITOR); - client.checkout(new File[] { workDir }, "HEAD", true, NULL_PROGRESS_MONITOR); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + + clientNested.add(new File[]{f2}, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{workDir}, "HEAD", true, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, nested, false, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_ADDED, false); - statuses = clientNested.getStatus(new File[] { nested }, NULL_PROGRESS_MONITOR); + statuses = clientNested.getStatus(new File[]{nested}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, nested, f2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); - - client.checkoutRevision("master", true, NULL_PROGRESS_MONITOR); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, nested, false, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_ADDED, false); assertStatus(statuses, workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); - statuses = clientNested.getStatus(new File[] { nested }, NULL_PROGRESS_MONITOR); + statuses = clientNested.getStatus(new File[]{nested}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, nested, f2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); } - public void testCheckoutWithAddedNestedRoot () throws Exception { + public void testCheckoutWithAddedNestedRoot() throws Exception { File f = new File(workDir, "f"); write(f, "file"); - + GitClient client = getClient(workDir); - client.add(new File[] { f }, NULL_PROGRESS_MONITOR); - client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR); - client.createBranch(BRANCH, "master", NULL_PROGRESS_MONITOR); - + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + client.commit(new File[]{f}, "init commit", null, null, NULL_PROGRESS_MONITOR); + client.createBranch(BRANCH, getDefaultBranch(), NULL_PROGRESS_MONITOR); + File nested = new File(workDir, "nested"); nested.mkdirs(); File f2 = new File(nested, "f"); write(f2, "file"); GitClient clientNested = getClient(nested); clientNested.init(NULL_PROGRESS_MONITOR); - clientNested.add(new File[] { f2 }, NULL_PROGRESS_MONITOR); - clientNested.commit(new File[] { f2 }, "init commit", null, null, NULL_PROGRESS_MONITOR); - + clientNested.add(new File[]{f2}, NULL_PROGRESS_MONITOR); + clientNested.commit(new File[]{f2}, "init commit", null, null, NULL_PROGRESS_MONITOR); + // add the root as gitlink - client.add(new File[] { nested }, NULL_PROGRESS_MONITOR); - client.commit(new File[] { nested }, "nested repo added", null, null, NULL_PROGRESS_MONITOR); + client.add(new File[]{nested}, NULL_PROGRESS_MONITOR); + client.commit(new File[]{nested}, "nested repo added", null, null, NULL_PROGRESS_MONITOR); Utils.deleteRecursively(nested); nested.mkdirs(); - Map statuses = client.getStatus(new File[] { nested }, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{nested}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, workDir, nested, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); - + client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); assertFalse(nested.isDirectory()); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); // ours assertFalse(nested.isDirectory()); - client.checkoutRevision("master", true, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); assertTrue(nested.isDirectory()); DirCacheEntry e = repository.readDirCache().getEntry("nested"); assertEquals(FileMode.GITLINK, e.getFileMode()); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, nested, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); //checkout index - aka revert assertTrue(nested.delete()); - client.remove(new File[] { nested }, true, NULL_PROGRESS_MONITOR); - client.checkout(new File[] { nested }, "master", true, NULL_PROGRESS_MONITOR); + client.remove(new File[]{nested}, true, NULL_PROGRESS_MONITOR); + client.checkout(new File[]{nested}, getDefaultBranch(), true, NULL_PROGRESS_MONITOR); assertTrue(nested.isDirectory()); e = repository.readDirCache().getEntry("nested"); assertEquals(FileMode.GITLINK, e.getFileMode()); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, nested, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); } - private void checkoutJGitTestNestedAddedRoot (Repository repository, String revision) throws Exception { + private void checkoutJGitTestNestedAddedRoot(Repository repository, String revision) throws Exception { try { ObjectId headTree = Utils.findCommit(repository, Constants.HEAD).getTree(); DirCache cache = repository.lockDirCache(); @@ -688,8 +686,8 @@ private void checkoutJGitTestNestedAddedRoot (Repository repository, String revi throw new GitException(ex); } } - - public void testLineEndingsWindows () throws Exception { + + public void testLineEndingsWindows() throws Exception { if (!isWindows()) { return; } @@ -698,18 +696,18 @@ public void testLineEndingsWindows () throws Exception { StoredConfig cfg = repository.getConfig(); cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true"); cfg.save(); - + File f = new File(workDir, "f"); write(f, "a\r\nb\r\n"); - File[] roots = new File[] { f }; - + File[] roots = new File[]{f}; + GitClient client = getClient(workDir); runExternally(workDir, Arrays.asList("git.cmd", "add", "f")); List res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("A f"), res); DirCacheEntry e1 = repository.readDirCache().getEntry("f"); runExternally(workDir, Arrays.asList("git.cmd", "commit", "-m", "hello")); - + write(f, "a\r\nb\r\nc\r\n"); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList(" M f"), res); @@ -717,7 +715,7 @@ public void testLineEndingsWindows () throws Exception { res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("M f"), res); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); - + client.checkout(roots, "HEAD", true, NULL_PROGRESS_MONITOR); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertEquals(e1.getObjectId(), repository.readDirCache().getEntry("f").getObjectId()); @@ -728,42 +726,42 @@ public void testLineEndingsWindows () throws Exception { res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList(" M f"), res); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); - + client.checkout(roots, null, true, NULL_PROGRESS_MONITOR); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertEquals(e1.getObjectId(), repository.readDirCache().getEntry("f").getObjectId()); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(0, res.size()); } - - public void testCheckoutAfterUnresolvedMerge () throws Exception { + + public void testCheckoutAfterUnresolvedMerge() throws Exception { File file = new File(workDir, "file"); write(file, "initial"); - File[] files = new File[] { file }; + 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); + + client.checkoutRevision(getDefaultBranch(), 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"); @@ -772,7 +770,7 @@ public void testCheckoutAfterUnresolvedMerge () throws Exception { } } - private void unpack (String filename) throws IOException { + private void unpack(String filename) throws IOException { File zipLarge = new File(getDataDir(), filename); ZipInputStream is = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipLarge))); ZipEntry entry; diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CherryPickTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CherryPickTest.java index 99138d7420c9..d6913ff330de 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CherryPickTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CherryPickTest.java @@ -16,13 +16,11 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryState; @@ -45,8 +43,8 @@ public class CherryPickTest extends AbstractGitTestCase { private File workDir; private Repository repository; private static final String BRANCH = "b"; - - public CherryPickTest (String testName) throws IOException { + + public CherryPickTest(String testName) throws IOException { super(testName); } @@ -56,27 +54,27 @@ protected void setUp() throws Exception { workDir = getWorkingDirectory(); repository = getRepository(getLocalGitRepository()); } - - public void testCherryPickCommit () throws Exception { + + public void testCherryPickCommit() throws Exception { File f = new File(workDir, "f"); write(f, "init"); add(f); commit(f); - + GitClient client = getClient(workDir); - client.createBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR); + client.createBranch(BRANCH, getDefaultBranch(), NULL_PROGRESS_MONITOR); client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); - + write(f, "change on branch"); add(f); - GitRevisionInfo c = client.commit(new File[] { f }, "on branch", null, null, NULL_PROGRESS_MONITOR); - - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + GitRevisionInfo c = client.commit(new File[]{f}, "on branch", null, null, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); GitRevisionInfo initCommit = client.log("HEAD", NULL_PROGRESS_MONITOR); - + Thread.sleep(1100); - - GitCherryPickResult res = client.cherryPick(GitClient.CherryPickOperation.BEGIN, new String[] { BRANCH }, NULL_PROGRESS_MONITOR); + + GitCherryPickResult res = client.cherryPick(GitClient.CherryPickOperation.BEGIN, new String[]{BRANCH}, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.OK, res.getCherryPickStatus()); assertEquals(initCommit.getRevision(), res.getCurrentHead().getParents()[0]); assertEquals(c.getCommitTime(), res.getCurrentHead().getCommitTime()); @@ -85,32 +83,32 @@ public void testCherryPickCommit () throws Exception { assertFalse(new File(workDir, ".git/sequencer").exists()); } - public void testCherryPickCommits () throws Exception { + public void testCherryPickCommits() throws Exception { File f = new File(workDir, "f"); write(f, "init"); add(f); commit(f); - - File[] roots = new File[] { f }; - + + File[] roots = new File[]{f}; + GitClient client = getClient(workDir); - client.createBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR); + client.createBranch(BRANCH, getDefaultBranch(), NULL_PROGRESS_MONITOR); client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); - + write(f, "change 1 on branch"); add(f); GitRevisionInfo c1 = client.commit(roots, "on branch 1", null, null, NULL_PROGRESS_MONITOR); write(f, "change 2 on branch"); add(f); GitRevisionInfo c2 = client.commit(roots, "on branch 2", null, null, NULL_PROGRESS_MONITOR); - - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); GitRevisionInfo initCommit = client.log("HEAD", NULL_PROGRESS_MONITOR); - + Thread.sleep(1100); - + GitCherryPickResult res = client.cherryPick(GitClient.CherryPickOperation.BEGIN, - new String[] { c1.getRevision(), c2.getRevision() }, NULL_PROGRESS_MONITOR); + new String[]{c1.getRevision(), c2.getRevision()}, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.OK, res.getCherryPickStatus()); SearchCriteria sc = new SearchCriteria(); sc.setRevisionTo("HEAD"); @@ -127,33 +125,33 @@ public void testCherryPickCommits () throws Exception { assertEquals(c2.getRevision(), res.getCherryPickedCommits()[1].getRevision()); assertFalse(new File(workDir, ".git/sequencer").exists()); } - - public void testCherryPickFailure () throws Exception { + + public void testCherryPickFailure() throws Exception { File f1 = new File(workDir, "f1"); File f2 = new File(workDir, "f2"); write(f1, "init"); write(f2, "init"); add(f1, f2); commit(f1, f2); - - File[] roots = new File[] { f1, f2 }; - + + File[] roots = new File[]{f1, f2}; + GitClient client = getClient(workDir); - client.createBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR); + client.createBranch(BRANCH, getDefaultBranch(), NULL_PROGRESS_MONITOR); client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); - + write(f1, "change on branch"); write(f2, "change on branch"); add(f1, f2); GitRevisionInfo c = client.commit(roots, "on branch", null, null, NULL_PROGRESS_MONITOR); - - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); // make modification so cherry-pick cannot start write(f1, "change in master"); write(f2, "change in master"); - + CherryPickCommand cmd = new CherryPickCommand(getRepository(client), ApiUtils.getClassFactory(), - new String[] { BRANCH }, GitClient.CherryPickOperation.BEGIN, NULL_PROGRESS_MONITOR, null); + new String[]{BRANCH}, GitClient.CherryPickOperation.BEGIN, NULL_PROGRESS_MONITOR, null); Field f = CherryPickCommand.class.getDeclaredField("workAroundStrategyIssue"); f.setAccessible(true); f.set(cmd, false); @@ -161,25 +159,25 @@ public void testCherryPickFailure () throws Exception { GitCherryPickResult res = cmd.getResult(); // when starts failing, remove the WA in CherryPickCommand for recursive strategy merger. assertEquals(1, res.getFailures().size()); - - res = client.cherryPick(GitClient.CherryPickOperation.BEGIN, new String[] { BRANCH }, NULL_PROGRESS_MONITOR); + + res = client.cherryPick(GitClient.CherryPickOperation.BEGIN, new String[]{BRANCH}, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.FAILED, res.getCherryPickStatus()); assertEquals(2, res.getFailures().size()); assertEquals(0, res.getCurrentHead().getParents().length); } - - public void testCherryPickCommitsConflictAbort () throws Exception { + + public void testCherryPickCommitsConflictAbort() throws Exception { File f = new File(workDir, "f"); write(f, "init"); add(f); commit(f); - - File[] roots = new File[] { f }; - + + File[] roots = new File[]{f}; + GitClient client = getClient(workDir); - client.createBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR); + client.createBranch(BRANCH, getDefaultBranch(), NULL_PROGRESS_MONITOR); client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); - + write(f, "change 1 on branch"); add(f); GitRevisionInfo c1 = client.commit(roots, "on branch 1", null, null, NULL_PROGRESS_MONITOR); @@ -189,34 +187,34 @@ public void testCherryPickCommitsConflictAbort () throws Exception { write(f, "change 3 on branch"); add(f); GitRevisionInfo c3 = client.commit(roots, "on branch 3", null, null, NULL_PROGRESS_MONITOR); - - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); GitRevisionInfo initCommit = client.log("HEAD", NULL_PROGRESS_MONITOR); GitCherryPickResult res = client.cherryPick(GitClient.CherryPickOperation.BEGIN, - new String[] { c1.getRevision(), c3.getRevision() }, NULL_PROGRESS_MONITOR); + new String[]{c1.getRevision(), c3.getRevision()}, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.CONFLICTING, res.getCherryPickStatus()); assertEquals(1, res.getConflicts().size()); assertEquals(initCommit.getRevision(), res.getCurrentHead().getParents()[0]); - + res = client.cherryPick(GitClient.CherryPickOperation.ABORT, null, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.ABORTED, res.getCherryPickStatus()); assertEquals(initCommit.getRevision(), res.getCurrentHead().getRevision()); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); } - - public void testCherryPickCommitsConflictQuit () throws Exception { + + public void testCherryPickCommitsConflictQuit() throws Exception { File f = new File(workDir, "f"); write(f, "init"); add(f); commit(f); - - File[] roots = new File[] { f }; - + + File[] roots = new File[]{f}; + GitClient client = getClient(workDir); - client.createBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR); + client.createBranch(BRANCH, getDefaultBranch(), NULL_PROGRESS_MONITOR); client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); - + write(f, "change 1 on branch"); add(f); GitRevisionInfo c1 = client.commit(roots, "on branch 1\nblablabla", null, null, NULL_PROGRESS_MONITOR); @@ -226,19 +224,19 @@ public void testCherryPickCommitsConflictQuit () throws Exception { write(f, "change 3 on branch"); add(f); GitRevisionInfo c3 = client.commit(roots, "on branch 3\nBLABLABLA", null, null, NULL_PROGRESS_MONITOR); - - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); GitRevisionInfo initCommit = client.log("HEAD", NULL_PROGRESS_MONITOR); GitCherryPickResult res = client.cherryPick(GitClient.CherryPickOperation.BEGIN, - new String[] { c1.getRevision(), c3.getRevision() }, NULL_PROGRESS_MONITOR); + new String[]{c1.getRevision(), c3.getRevision()}, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.CONFLICTING, res.getCherryPickStatus()); assertEquals(initCommit.getRevision(), res.getCurrentHead().getParents()[0]); - + ObjectReader or = repository.newObjectReader(); RevCommit commit = Utils.findCommit(repository, c3.getRevision()); assertEquals("pick " + or.abbreviate(commit).name() + " " + commit.getShortMessage(), read(new File(repository.getDirectory(), "sequencer/todo"))); - + res = client.cherryPick(GitClient.CherryPickOperation.QUIT, null, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.CONFLICTING, res.getCherryPickStatus()); assertEquals(1, res.getConflicts().size()); @@ -246,72 +244,72 @@ public void testCherryPickCommitsConflictQuit () throws Exception { assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, true); assertEquals(RepositoryState.CHERRY_PICKING, repository.getRepositoryState()); - + res = client.cherryPick(GitClient.CherryPickOperation.ABORT, null, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.ABORTED, res.getCherryPickStatus()); assertEquals(initCommit.getRevision(), res.getCurrentHead().getParents()[0]); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); } - - public void testCherryPickCommitConflictResolve () throws Exception { + + public void testCherryPickCommitConflictResolve() throws Exception { File f = new File(workDir, "f"); write(f, "init"); add(f); commit(f); - - File[] roots = new File[] { f }; - + + File[] roots = new File[]{f}; + GitClient client = getClient(workDir); - client.createBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR); + client.createBranch(BRANCH, getDefaultBranch(), NULL_PROGRESS_MONITOR); client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); - + write(f, "change 1 on branch"); add(f); GitRevisionInfo c1 = client.commit(roots, "on branch 1", null, null, NULL_PROGRESS_MONITOR); write(f, "change 2 on branch"); add(f); GitRevisionInfo c2 = client.commit(roots, "on branch 2", null, null, NULL_PROGRESS_MONITOR); - - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); GitRevisionInfo initCommit = client.log("HEAD", NULL_PROGRESS_MONITOR); GitCherryPickResult res = client.cherryPick(GitClient.CherryPickOperation.BEGIN, - new String[] { c2.getRevision() }, NULL_PROGRESS_MONITOR); + new String[]{c2.getRevision()}, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.CONFLICTING, res.getCherryPickStatus()); assertEquals(1, res.getConflicts().size()); assertEquals(initCommit.getRevision(), res.getCurrentHead().getRevision()); assertFalse(new File(repository.getDirectory(), "sequencer").exists()); - + write(f, "init\nchange 2 on branch"); add(f); - + // try continue, should interrupt and ask for commit res = client.cherryPick(GitClient.CherryPickOperation.CONTINUE, null, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.UNCOMMITTED, res.getCherryPickStatus()); assertEquals(initCommit.getRevision(), res.getCurrentHead().getRevision()); assertFalse(new File(repository.getDirectory(), "sequencer").exists()); - + GitRevisionInfo commit = client.commit(new File[0], c2.getFullMessage(), null, null, NULL_PROGRESS_MONITOR); assertEquals(c2.getCommitTime(), commit.getCommitTime()); assertEquals(RepositoryState.SAFE, repository.getRepositoryState()); assertFalse(new File(repository.getDirectory(), "sequencer").exists()); - + res = client.cherryPick(GitClient.CherryPickOperation.CONTINUE, null, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.OK, res.getCherryPickStatus()); } - - public void testCherryPickCommitsConflictResolve () throws Exception { + + public void testCherryPickCommitsConflictResolve() throws Exception { File f = new File(workDir, "f"); write(f, "init"); add(f); commit(f); - - File[] roots = new File[] { f }; - + + File[] roots = new File[]{f}; + GitClient client = getClient(workDir); - client.createBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR); + client.createBranch(BRANCH, getDefaultBranch(), NULL_PROGRESS_MONITOR); client.checkoutRevision(BRANCH, true, NULL_PROGRESS_MONITOR); - + write(f, "change 1 on branch"); add(f); GitRevisionInfo c1 = client.commit(roots, "on branch 1", null, null, NULL_PROGRESS_MONITOR); @@ -324,33 +322,33 @@ public void testCherryPickCommitsConflictResolve () throws Exception { write(f, "change 4 on branch"); add(f); GitRevisionInfo c4 = client.commit(roots, "on branch 4", null, null, NULL_PROGRESS_MONITOR); - + Thread.sleep(1100); - - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); GitRevisionInfo initCommit = client.log("HEAD", NULL_PROGRESS_MONITOR); GitCherryPickResult res = client.cherryPick(GitClient.CherryPickOperation.BEGIN, - new String[] { c2.getRevision(), c3.getRevision(), c4.getRevision() }, NULL_PROGRESS_MONITOR); + new String[]{c2.getRevision(), c3.getRevision(), c4.getRevision()}, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.CONFLICTING, res.getCherryPickStatus()); assertEquals(1, res.getConflicts().size()); assertEquals(initCommit.getRevision(), res.getCurrentHead().getRevision()); - + write(f, "init\nchange 2 on branch"); add(f); - + GitRevisionInfo commit = client.commit(new File[0], c2.getFullMessage(), null, null, NULL_PROGRESS_MONITOR); assertEquals(c2.getCommitTime(), commit.getCommitTime()); assertEquals(RepositoryState.SAFE, repository.getRepositoryState()); assertTrue(new File(repository.getDirectory(), "sequencer").exists()); - + res = client.cherryPick(GitClient.CherryPickOperation.CONTINUE, null, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.CONFLICTING, res.getCherryPickStatus()); assertEquals(1, res.getConflicts().size()); assertEquals(initCommit.getRevision(), res.getCurrentHead().getParents()[0]); - + write(f, "change 3 on branch"); add(f); - + client.commit(new File[0], c3.getFullMessage(), null, null, NULL_PROGRESS_MONITOR); res = client.cherryPick(GitClient.CherryPickOperation.CONTINUE, null, NULL_PROGRESS_MONITOR); assertEquals(GitCherryPickResult.CherryPickStatus.OK, res.getCherryPickStatus()); diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CommitTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CommitTest.java index 5f0daafd16b0..d4d44bcbda91 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CommitTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CommitTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -51,10 +50,11 @@ * @author ondra */ public class CommitTest extends AbstractGitTestCase { + private Repository repository; private File workDir; - public CommitTest (String testName) throws IOException { + public CommitTest(String testName) throws IOException { super(testName); } @@ -65,17 +65,17 @@ protected void setUp() throws Exception { repository = getRepository(getLocalGitRepository()); } - public void testCommitNoRoots () throws Exception { + public void testCommitNoRoots() throws Exception { File toCommit = new File(workDir, "testnotadd.txt"); write(toCommit, "blablabla"); GitClient client = getClient(workDir); - Map statuses = client.getStatus(new File[] { toCommit }, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{toCommit}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, toCommit, false, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_ADDED, false); - client.add(new File[] { toCommit }, NULL_PROGRESS_MONITOR); - statuses = client.getStatus(new File[] { toCommit }, NULL_PROGRESS_MONITOR); + client.add(new File[]{toCommit}, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{toCommit}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, toCommit, true, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, false); GitRevisionInfo info = client.commit(new File[0], "initial commit", null, null, NULL_PROGRESS_MONITOR); - statuses = client.getStatus(new File[] { toCommit }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{toCommit}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, toCommit, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); Git git = new Git(repository); @@ -88,7 +88,7 @@ public void testCommitNoRoots () throws Exception { assertTrue(modifiedFiles.get(toCommit).getStatus().equals(Status.ADDED)); } - public void testSingleFileCommit () throws Exception { + public void testSingleFileCommit() throws Exception { repository.getConfig().setString("user", null, "name", "John"); repository.getConfig().setString("user", null, "email", "john@git.com"); repository.getConfig().save(); @@ -96,17 +96,17 @@ public void testSingleFileCommit () throws Exception { File toCommit = new File(workDir, "testnotadd.txt"); write(toCommit, "blablabla"); GitClient client = getClient(workDir); - Map statuses = client.getStatus(new File[] { toCommit }, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{toCommit}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, toCommit, false, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_ADDED, false); - client.add(new File[] { toCommit }, NULL_PROGRESS_MONITOR); - statuses = client.getStatus(new File[] { toCommit }, NULL_PROGRESS_MONITOR); + client.add(new File[]{toCommit}, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{toCommit}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, toCommit, true, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, false); long t1 = System.currentTimeMillis(); Thread.sleep(1000); - GitRevisionInfo info = client.commit(new File[] { toCommit }, "initial commit", null, null, NULL_PROGRESS_MONITOR); + GitRevisionInfo info = client.commit(new File[]{toCommit}, "initial commit", null, null, NULL_PROGRESS_MONITOR); Thread.sleep(1000); long t2 = System.currentTimeMillis(); - statuses = client.getStatus(new File[] { toCommit }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{toCommit}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, toCommit, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertTrue(t1 <= info.getCommitTime() && t2 >= info.getCommitTime()); @@ -115,14 +115,14 @@ public void testSingleFileCommit () throws Exception { RevCommit com = log.call().iterator().next(); assertEquals("initial commit", info.getFullMessage()); assertEquals("initial commit", com.getFullMessage()); - assertEquals( "john@git.com", info.getAuthor().getEmailAddress()); - assertEquals( "john@git.com", com.getAuthorIdent().getEmailAddress()); + assertEquals("john@git.com", info.getAuthor().getEmailAddress()); + assertEquals("john@git.com", com.getAuthorIdent().getEmailAddress()); assertEquals(ObjectId.toString(com.getId()), info.getRevision()); Map modifiedFiles = info.getModifiedFiles(); assertTrue(modifiedFiles.get(toCommit).getStatus().equals(Status.ADDED)); } - public void testMultipleFileCommit () throws Exception { + public void testMultipleFileCommit() throws Exception { repository.getConfig().setString("user", null, "name", "John"); repository.getConfig().setString("user", null, "email", "john@git.com"); repository.getConfig().save(); @@ -135,12 +135,12 @@ public void testMultipleFileCommit () throws Exception { write(another, "this is another test!"); GitClient client = getClient(workDir); - client.add(new File[] { newOne, another }, NULL_PROGRESS_MONITOR); - Map statuses = client.getStatus(new File[] { newOne, another }, NULL_PROGRESS_MONITOR); + client.add(new File[]{newOne, another}, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{newOne, another}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, false); assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, false); - GitRevisionInfo info = client.commit(new File[] { newOne, another }, "initial commit", null, null, NULL_PROGRESS_MONITOR); - statuses = client.getStatus(new File[] { newOne, another }, NULL_PROGRESS_MONITOR); + GitRevisionInfo info = client.commit(new File[]{newOne, another}, "initial commit", null, null, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{newOne, another}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); Map modifiedFiles = info.getModifiedFiles(); @@ -151,17 +151,17 @@ public void testMultipleFileCommit () throws Exception { LogCommand log = git.log(); RevCommit com = log.call().iterator().next(); assertEquals("initial commit", com.getFullMessage()); - assertEquals( "john@git.com", com.getAuthorIdent().getEmailAddress()); + assertEquals("john@git.com", com.getAuthorIdent().getEmailAddress()); write(newOne, "!modification!"); write(another, "another modification!"); - client.add(new File[] { workDir }, NULL_PROGRESS_MONITOR); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + client.add(new File[]{workDir}, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); - info = client.commit(new File[] { newOne, another }, "second commit", null, null, NULL_PROGRESS_MONITOR); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + info = client.commit(new File[]{newOne, another}, "second commit", null, null, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); modifiedFiles = info.getModifiedFiles(); @@ -171,18 +171,18 @@ public void testMultipleFileCommit () throws Exception { log = git.log(); com = log.call().iterator().next(); assertEquals("second commit", com.getFullMessage()); - assertEquals( "john@git.com", com.getAuthorIdent().getEmailAddress()); + assertEquals("john@git.com", com.getAuthorIdent().getEmailAddress()); } - public void testCommitOnlySomeOfAllFiles () throws Exception { + public void testCommitOnlySomeOfAllFiles() throws Exception { File file1 = new File(workDir, "file1"); write(file1, "file1 content"); File file2 = new File(workDir, "file2"); write(file2, "file2 content"); - File[] files = new File[] { file1, file2 }; + File[] files = new File[]{file1, file2}; GitClient client = getClient(workDir); client.add(files, NULL_PROGRESS_MONITOR); - GitRevisionInfo info = client.commit(new File[] { file1 }, "initial commit", null, null, NULL_PROGRESS_MONITOR); + GitRevisionInfo info = client.commit(new File[]{file1}, "initial commit", null, null, NULL_PROGRESS_MONITOR); Map modifiedFiles = info.getModifiedFiles(); assertEquals(1, modifiedFiles.size()); assertTrue(modifiedFiles.get(file1).getStatus().equals(Status.ADDED)); @@ -191,18 +191,18 @@ public void testCommitOnlySomeOfAllFiles () throws Exception { assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); // but file2 should still be staged for commit assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, false); - info = client.commit(new File[] { file2 }, "initial commit", null, null, NULL_PROGRESS_MONITOR); + info = client.commit(new File[]{file2}, "initial commit", null, null, NULL_PROGRESS_MONITOR); modifiedFiles = info.getModifiedFiles(); assertEquals(1, modifiedFiles.size()); assertTrue(modifiedFiles.get(file2).getStatus().equals(Status.ADDED)); write(file1, "file1 content changed"); write(file2, "file2 content changed"); - client.add(new File[] { file1 }, NULL_PROGRESS_MONITOR); + client.add(new File[]{file1}, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); - info = client.commit(new File[] { file1 }, "change in content", null, null, NULL_PROGRESS_MONITOR); + info = client.commit(new File[]{file1}, "change in content", null, null, NULL_PROGRESS_MONITOR); modifiedFiles = info.getModifiedFiles(); assertEquals(1, modifiedFiles.size()); assertTrue(modifiedFiles.get(file1).getStatus().equals(Status.MODIFIED)); @@ -214,12 +214,12 @@ public void testCommitOnlySomeOfAllFiles () throws Exception { write(file1, "file1 content changed again"); write(file2, "file2 content changed again"); - client.add(new File[] { file1, file2 }, NULL_PROGRESS_MONITOR); + client.add(new File[]{file1, file2}, NULL_PROGRESS_MONITOR); write(file2, "file2 content changed again and again"); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); - info = client.commit(new File[] { file1 }, "another change in content", null, null, NULL_PROGRESS_MONITOR); + info = client.commit(new File[]{file1}, "another change in content", null, null, NULL_PROGRESS_MONITOR); modifiedFiles = info.getModifiedFiles(); assertEquals(1, modifiedFiles.size()); assertTrue(modifiedFiles.get(file1).getStatus().equals(Status.MODIFIED)); @@ -230,12 +230,12 @@ public void testCommitOnlySomeOfAllFiles () throws Exception { assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); write(file1, "file1 content changed again and again"); - client.add(new File[] { file1 }, NULL_PROGRESS_MONITOR); - client.remove(new File[] { file2 }, true, NULL_PROGRESS_MONITOR); + client.add(new File[]{file1}, NULL_PROGRESS_MONITOR); + client.remove(new File[]{file2}, true, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_REMOVED, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_MODIFIED, false); - info = client.commit(new File[] { file1 }, "another change in content", null, null, NULL_PROGRESS_MONITOR); + info = client.commit(new File[]{file1}, "another change in content", null, null, NULL_PROGRESS_MONITOR); modifiedFiles = info.getModifiedFiles(); assertEquals(1, modifiedFiles.size()); assertTrue(modifiedFiles.get(file1).getStatus().equals(Status.MODIFIED)); @@ -246,10 +246,10 @@ public void testCommitOnlySomeOfAllFiles () throws Exception { assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_REMOVED, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_MODIFIED, false); } - public void testCommitRemoval () throws Exception { + public void testCommitRemoval() throws Exception { File file = new File(workDir, "file"); write(file, "file1 content"); - File[] files = new File[] { file }; + File[] files = new File[]{file}; GitClient client = getClient(workDir); client.add(files, NULL_PROGRESS_MONITOR); GitRevisionInfo info = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR); @@ -274,7 +274,7 @@ public void testCommitRemoval () throws Exception { assertNull(statuses.get(file)); } - public void testSingleTreeCommit () throws Exception { + public void testSingleTreeCommit() throws Exception { File folder = new File(workDir, "folder"); File subfolder1 = new File(folder, "subfolder"); File subfolder11 = new File(subfolder1, "subfolder1"); @@ -285,7 +285,7 @@ public void testSingleTreeCommit () throws Exception { File file2 = new File(subfolder12, "file2"); write(file1, "file1 content"); write(file2, "file2 content"); - File[] files = new File[] { folder }; + File[] files = new File[]{folder}; GitClient client = getClient(workDir); client.add(files, NULL_PROGRESS_MONITOR); GitRevisionInfo info = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR); @@ -304,7 +304,7 @@ public void testSingleTreeCommit () throws Exception { assertEquals("initial commit", com.getFullMessage()); } - public void testMultipleTreesCommit () throws Exception { + public void testMultipleTreesCommit() throws Exception { File folder1 = new File(workDir, "folder1"); File subfolder11 = new File(folder1, "subfolder1"); File subfolder12 = new File(folder1, "subfolder2"); @@ -323,7 +323,7 @@ public void testMultipleTreesCommit () throws Exception { File file22 = new File(subfolder22, "file2"); write(file21, "file1 content"); write(file22, "file2 content"); - File[] files = new File[] { folder1, folder2 }; + File[] files = new File[]{folder1, folder2}; GitClient client = getClient(workDir); client.add(files, NULL_PROGRESS_MONITOR); GitRevisionInfo info = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR); @@ -364,7 +364,7 @@ public void testMultipleTreesCommit () throws Exception { assertEquals("second commit", com.getFullMessage()); } - public void testCommitOnlySomeOfAllFilesFromMultipleTrees () throws Exception { + public void testCommitOnlySomeOfAllFilesFromMultipleTrees() throws Exception { File folder1 = new File(workDir, "folder1"); File subfolder11 = new File(folder1, "subfolder1"); File subfolder12 = new File(folder1, "subfolder2"); @@ -383,9 +383,9 @@ public void testCommitOnlySomeOfAllFilesFromMultipleTrees () throws Exception { File file22 = new File(subfolder22, "file2"); write(file21, "file1 content"); write(file22, "file2 content"); - File[] trees = new File[] { folder1, folder2 }; - File[] filesToCommit = new File[] { folder1, subfolder21 }; - File[] filesSingleFolder = new File[] { subfolder21 }; + File[] trees = new File[]{folder1, folder2}; + File[] filesToCommit = new File[]{folder1, subfolder21}; + File[] filesSingleFolder = new File[]{subfolder21}; GitClient client = getClient(workDir); client.add(trees, NULL_PROGRESS_MONITOR); @@ -446,7 +446,7 @@ public void testCommitOnlySomeOfAllFilesFromMultipleTrees () throws Exception { assertStatus(statuses, workDir, file22, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); } - public void testCommitRemovalTree () throws Exception { + public void testCommitRemovalTree() throws Exception { File folder = new File(workDir, "folder"); File subfolder1 = new File(folder, "subfolder"); File subfolder11 = new File(subfolder1, "subfolder1"); @@ -457,7 +457,7 @@ public void testCommitRemovalTree () throws Exception { File file2 = new File(subfolder12, "file2"); write(file1, "file1 content"); write(file2, "file2 content"); - File[] files = new File[] { folder }; + File[] files = new File[]{folder}; GitClient client = getClient(workDir); client.add(files, NULL_PROGRESS_MONITOR); GitRevisionInfo info = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR); @@ -486,7 +486,7 @@ public void testCommitRemovalTree () throws Exception { assertNull(statuses.get(file2)); } - public void testNeverCommitConflicts () throws Exception { + public void testNeverCommitConflicts() throws Exception { File f = new File(workDir, "conflict"); DirCache cache = repository.lockDirCache(); try { @@ -504,7 +504,7 @@ public void testNeverCommitConflicts () throws Exception { File mergeFile = new File(new File(workDir, Constants.DOT_GIT), "MERGE_HEAD"); mergeFile.createNewFile(); try { - getClient(workDir).commit(new File[] { f }, "nothing", null, null, NULL_PROGRESS_MONITOR); + getClient(workDir).commit(new File[]{f}, "nothing", null, null, NULL_PROGRESS_MONITOR); fail(); } catch (GitException ex) { assertEquals("Index contains files in conflict, please resolve them before commit", ex.getMessage()); @@ -519,7 +519,7 @@ public void testNeverCommitConflicts () throws Exception { cache.unlock(); } try { - getClient(workDir).commit(new File[] { f }, "nothing", null, null, NULL_PROGRESS_MONITOR); + getClient(workDir).commit(new File[]{f}, "nothing", null, null, NULL_PROGRESS_MONITOR); fail(); } catch (GitException ex) { assertEquals("Cannot do a partial commit during a merge.", ex.getMessage()); @@ -527,8 +527,8 @@ public void testNeverCommitConflicts () throws Exception { //TODO try to commit the whole WT, for that we need to create the real conflict, not just this fake ones } - - public void testLineEndingsWindows () throws Exception { + + public void testLineEndingsWindows() throws Exception { if (!isWindows()) { return; } @@ -536,11 +536,11 @@ public void testLineEndingsWindows () throws Exception { StoredConfig cfg = repository.getConfig(); cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true"); cfg.save(); - + File f = new File(workDir, "f"); write(f, "a\r\nb\r\n"); - File[] roots = new File[] { f }; - + File[] roots = new File[]{f}; + GitClient client = getClient(workDir); client.add(roots, NULL_PROGRESS_MONITOR); DirCacheEntry e1 = repository.readDirCache().getEntry("f"); @@ -549,12 +549,12 @@ public void testLineEndingsWindows () throws Exception { List res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("A f"), res); GitRevisionInfo info = client.commit(roots, "aaa", null, null, NULL_PROGRESS_MONITOR); - + assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(0, res.size()); - + RevCommit commit = Utils.findCommit(repository, info.getRevision()); TreeWalk walk = new TreeWalk(repository); walk.reset(); @@ -567,39 +567,38 @@ public void testLineEndingsWindows () throws Exception { assertEquals(4, loader.getSize()); assertEquals("a\nb\n", new String(loader.getBytes())); assertEquals(e1.getObjectId(), walk.getObjectId(0)); - - + File f2 = new File(workDir, "f2"); write(f2, "a\r\nb\r\n"); - roots = new File[] { f2 }; - + roots = new File[]{f2}; + client.add(roots, NULL_PROGRESS_MONITOR); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f2, true, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, false); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("A f2"), res); info = client.commit(roots, "bbb", null, null, NULL_PROGRESS_MONITOR); - + assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f2, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(0, res.size()); - + commit = Utils.findCommit(repository, info.getRevision()); walk = new TreeWalk(repository); walk.reset(); walk.addTree(commit.getTree()); walk.setFilter(PathFilter.create("f")); walk.setRecursive(true); - while(walk.next()) { + while (walk.next()) { loader = repository.getObjectDatabase().open(walk.getObjectId(0)); assertEquals(4, loader.getSize()); assertEquals("a\nb\n", new String(loader.getBytes())); assertEquals(e1.getObjectId(), walk.getObjectId(0)); } } - - public void testAmendCommit () throws Exception { + + public void testAmendCommit() throws Exception { repository.getConfig().setString("user", null, "name", "John"); repository.getConfig().setString("user", null, "email", "john@git.com"); repository.getConfig().save(); @@ -612,18 +611,18 @@ public void testAmendCommit () throws Exception { write(another, "content2"); GitClient client = getClient(workDir); - client.add(new File[] { newOne, another }, NULL_PROGRESS_MONITOR); - GitRevisionInfo info = client.commit(new File[] { newOne, another }, "initial commit", null, null, NULL_PROGRESS_MONITOR); - Map statuses = client.getStatus(new File[] { newOne, another }, NULL_PROGRESS_MONITOR); + client.add(new File[]{newOne, another}, NULL_PROGRESS_MONITOR); + GitRevisionInfo info = client.commit(new File[]{newOne, another}, "initial commit", null, null, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{newOne, another}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); - + write(newOne, "modification1"); write(another, "modification2"); - client.add(new File[] { newOne, another }, NULL_PROGRESS_MONITOR); - GitRevisionInfo lastCommit = client.commit(new File[] { newOne }, "second commit", null, null, false, NULL_PROGRESS_MONITOR); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + client.add(new File[]{newOne, another}, NULL_PROGRESS_MONITOR); + GitRevisionInfo lastCommit = client.commit(new File[]{newOne}, "second commit", null, null, false, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); Map modifiedFiles = lastCommit.getModifiedFiles(); @@ -632,21 +631,21 @@ public void testAmendCommit () throws Exception { assertEquals(1, lastCommit.getParents().length); assertEquals(info.getRevision(), lastCommit.getParents()[0]); - assertEquals(lastCommit.getRevision(), client.getBranches(false, NULL_PROGRESS_MONITOR).get("master").getId()); - + assertEquals(lastCommit.getRevision(), client.getBranches(false, NULL_PROGRESS_MONITOR).get(getDefaultBranch()).getId()); + Thread.sleep(1100); - + long time = lastCommit.getCommitTime(); RevWalk walk = new RevWalk(repository); RevCommit originalCommit = walk.parseCommit(repository.resolve(lastCommit.getRevision())); - lastCommit = client.commit(new File[] { newOne, another }, "second commit, modified message", + lastCommit = client.commit(new File[]{newOne, another}, "second commit, modified message", new GitUser("user2", "user2.email"), new GitUser("committer2", "committer2.email"), true, NULL_PROGRESS_MONITOR); RevCommit amendedCommit = walk.parseCommit(repository.resolve(lastCommit.getRevision())); assertEquals("Commit time should not change after amend", time, lastCommit.getCommitTime()); assertEquals(originalCommit.getAuthorIdent().getWhenAsInstant(), amendedCommit.getAuthorIdent().getWhenAsInstant()); // commit time should not equal. assertFalse(originalCommit.getCommitterIdent().getWhenAsInstant().equals(amendedCommit.getCommitterIdent().getWhenAsInstant())); - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, newOne, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, another, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); modifiedFiles = lastCommit.getModifiedFiles(); @@ -655,31 +654,31 @@ public void testAmendCommit () throws Exception { assertEquals(1, lastCommit.getParents().length); assertEquals(info.getRevision(), lastCommit.getParents()[0]); - assertEquals(lastCommit.getRevision(), client.getBranches(false, NULL_PROGRESS_MONITOR).get("master").getId()); + assertEquals(lastCommit.getRevision(), client.getBranches(false, NULL_PROGRESS_MONITOR).get(getDefaultBranch()).getId()); } - - public void testCherryPickCommit () throws Exception { + + public void testCherryPickCommit() throws Exception { repository.getConfig().setString("user", null, "name", "John"); repository.getConfig().setString("user", null, "email", "john@git.com"); repository.getConfig().save(); - + File f = new File(workDir, "f"); write(f, "init"); - File[] files = new File[] { f }; - + File[] files = new File[]{f}; + add(f); commit(f); - + GitClient client = getClient(workDir); write(f, "change"); add(f); GitRevisionInfo info = client.commit(files, "change to CherryPick", null, null, NULL_PROGRESS_MONITOR); - + Thread.sleep(1100); - + client.reset("HEAD~1", GitClient.ResetType.MIXED, NULL_PROGRESS_MONITOR); repository.writeCherryPickHead(repository.resolve(info.getRevision())); - + // now we are cherry-picking // amend is not allowed try { @@ -688,14 +687,14 @@ public void testCherryPickCommit () throws Exception { } catch (GitException ex) { assertEquals(Utils.getBundle(CommitCommand.class).getString("MSG_Error_Commit_CannotAmend"), ex.getMessage()); } - + // doing commit should preserve authorship of the original commit (info) GitRevisionInfo commit = client.commit(new File[0], info.getFullMessage(), null, null, NULL_PROGRESS_MONITOR); assertEquals(info.getAuthor(), commit.getAuthor()); assertEquals(info.getCommitTime(), commit.getCommitTime()); assertEquals( - Utils.findCommit(repository, info.getRevision()).getAuthorIdent().getWhenAsInstant(), - Utils.findCommit(repository, commit.getRevision()).getAuthorIdent().getWhenAsInstant() + Utils.findCommit(repository, info.getRevision()).getAuthorIdent().getWhenAsInstant(), + Utils.findCommit(repository, commit.getRevision()).getAuthorIdent().getWhenAsInstant() ); } } diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CompareCommitTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CompareCommitTest.java index 5b15bcd1c105..345b8086555f 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CompareCommitTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/CompareCommitTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -34,10 +33,11 @@ * @author ondra */ public class CompareCommitTest extends AbstractGitTestCase { + private Repository repository; private File workDir; - public CompareCommitTest (String testName) throws IOException { + public CompareCommitTest(String testName) throws IOException { super(testName); } @@ -47,104 +47,104 @@ protected void setUp() throws Exception { workDir = getWorkingDirectory(); repository = getRepository(getLocalGitRepository()); } - - public void testCompareSimple () throws Exception { + + public void testCompareSimple() throws Exception { File file = new File(workDir, "file"); - File[] files = new File[] { file }; + File[] files = new File[]{file}; write(file, "init\n"); add(files); commit(files); - + GitClient client = getClient(workDir); - String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(Constants.MASTER).getId(); + String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(getDefaultBranch()).getId(); write(file, "modification\n"); add(files); GitRevisionInfo revision2 = client.commit(files, "my commit message", null, null, NULL_PROGRESS_MONITOR); Map statuses = client.getStatus(files, Constants.HEAD, revision1, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertEquals(Status.MODIFIED, statuses.get(file).getStatus()); - + write(file, "modification 2\n"); add(files); GitRevisionInfo revision3 = client.commit(files, "my commit 3 message", null, null, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, revision1, Constants.HEAD, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertEquals(Status.MODIFIED, statuses.get(file).getStatus()); - + statuses = client.getStatus(files, revision1, revision3.getRevision(), NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertEquals(Status.MODIFIED, statuses.get(file).getStatus()); - + statuses = client.getStatus(files, revision2.getRevision(), revision3.getRevision(), NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertEquals(Status.MODIFIED, statuses.get(file).getStatus()); } - - public void testCompareRevertModification () throws Exception { + + public void testCompareRevertModification() throws Exception { File file = new File(workDir, "file"); - File[] files = new File[] { file }; + File[] files = new File[]{file}; write(file, "init\n"); add(files); commit(files); - + GitClient client = getClient(workDir); - String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(Constants.MASTER).getId(); + String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(getDefaultBranch()).getId(); write(file, "modification\n"); add(files); GitRevisionInfo revision2 = client.commit(files, "my commit message", null, null, NULL_PROGRESS_MONITOR); - + write(file, "init\n"); add(files); GitRevisionInfo revision3 = client.commit(files, "my commit 3 message", null, null, NULL_PROGRESS_MONITOR); Map statuses = client.getStatus(files, revision1, Constants.HEAD, NULL_PROGRESS_MONITOR); assertTrue(statuses.isEmpty()); } - - public void testCompareSelection () throws Exception { + + public void testCompareSelection() throws Exception { File file = new File(workDir, "file"); File file2 = new File(workDir, "file2"); - File[] files = new File[] { file, file2 }; + File[] files = new File[]{file, file2}; write(file, "init\n"); add(files); commit(files); - + GitClient client = getClient(workDir); - String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(Constants.MASTER).getId(); + String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(getDefaultBranch()).getId(); write(file, "modification\n"); add(files); GitRevisionInfo revision2 = client.commit(files, "my commit message", null, null, NULL_PROGRESS_MONITOR); - + write(file2, "adding file 2\n"); add(files); GitRevisionInfo revision3 = client.commit(files, "adding file 2", null, null, NULL_PROGRESS_MONITOR); - Map statuses = client.getStatus(new File[] { file }, revision1, revision3.getRevision(), NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{file}, revision1, revision3.getRevision(), NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertEquals(Status.MODIFIED, statuses.get(file).getStatus()); - - statuses = client.getStatus(new File[] { file2 }, revision1, revision3.getRevision(), NULL_PROGRESS_MONITOR); + + statuses = client.getStatus(new File[]{file2}, revision1, revision3.getRevision(), NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertEquals(Status.ADDED, statuses.get(file2).getStatus()); - + statuses = client.getStatus(files, revision1, revision3.getRevision(), NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertEquals(Status.MODIFIED, statuses.get(file).getStatus()); assertEquals(Status.ADDED, statuses.get(file2).getStatus()); } - - public void testCompareRename () throws Exception { + + public void testCompareRename() throws Exception { File file = new File(workDir, "file"); File file2 = new File(workDir, "file2"); - File[] files = new File[] { file, file2 }; + File[] files = new File[]{file, file2}; write(file, "files content\n"); add(files); commit(files); - + GitClient client = getClient(workDir); - String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(Constants.MASTER).getId(); + String revision1 = client.getBranches(false, NULL_PROGRESS_MONITOR).get(getDefaultBranch()).getId(); remove(false, file); - + client.commit(files, "removing file", null, null, NULL_PROGRESS_MONITOR); - + write(file2, "files content\n"); add(files); GitRevisionInfo revision3 = client.commit(files, "adding file as file2", null, null, NULL_PROGRESS_MONITOR); diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/ExportCommitTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/ExportCommitTest.java index 1d61331fc09a..c67e3c3b946c 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/ExportCommitTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/ExportCommitTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.BufferedOutputStream; @@ -40,10 +39,11 @@ * @author ondra */ public class ExportCommitTest extends AbstractGitTestCase { + private Repository repository; private File workDir; - public ExportCommitTest (String testName) throws IOException { + public ExportCommitTest(String testName) throws IOException { super(testName); } @@ -53,15 +53,15 @@ protected void setUp() throws Exception { workDir = getWorkingDirectory(); repository = getRepository(getLocalGitRepository()); } - - public void testExportCommit () throws Exception { + + public void testExportCommit() throws Exception { File patchFile = new File(workDir.getParentFile(), "diff.patch"); File file = new File(workDir, "file"); - File[] files = new File[] { file }; + File[] files = new File[]{file}; write(file, "init\n"); add(files); commit(files); - + GitClient client = getClient(workDir); write(file, "modification\n"); add(files); @@ -69,65 +69,65 @@ public void testExportCommit () throws Exception { exportDiff(commit.getRevision(), patchFile); assertPatchFile(commit, getGoldenFile("exportCommit.patch"), patchFile); } - - public void testExportCommitMultiLine () throws Exception { + + public void testExportCommitMultiLine() throws Exception { File patchFile = new File(workDir.getParentFile(), "diff.patch"); File file = new File(workDir, "file"); File file2 = new File(workDir, "file2"); - File[] files = new File[] { file, file2 }; + File[] files = new File[]{file, file2}; write(file, "init\n"); write(file2, "init\n"); add(files); commit(files); - + GitClient client = getClient(workDir); write(file, "modification 1\n"); write(file2, "modification 2\n"); add(files); GitRevisionInfo commit = client.commit(files, "first\nsecond\nthird", null, null, NULL_PROGRESS_MONITOR); - + exportDiff(commit.getRevision(), patchFile); assertPatchFile(commit, getGoldenFile("exportCommitMultiLine.patch"), patchFile); } - - public void testExportMergeFail () throws Exception { + + public void testExportMergeFail() throws Exception { File patchFile = new File(workDir.getParentFile(), "diff.patch"); File file = new File(workDir, "file"); - File[] files = new File[] { file }; + File[] files = new File[]{file}; write(file, "a\nb\nc\n"); add(files); commit(files); - + GitClient client = getClient(workDir); - client.createBranch("branch", "master", NULL_PROGRESS_MONITOR); + client.createBranch("branch", getDefaultBranch(), NULL_PROGRESS_MONITOR); client.checkoutRevision("branch", true, NULL_PROGRESS_MONITOR); write(file, "modification on branch\nb\nc\n"); add(files); GitRevisionInfo branchCommit = client.commit(files, "branch modified", null, null, NULL_PROGRESS_MONITOR); - - client.checkoutRevision("master", true, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); write(file, "a\nb\nmodification on master\n"); add(files); GitRevisionInfo commit = client.commit(files, "master modified", null, null, NULL_PROGRESS_MONITOR); - + assertEquals(GitMergeResult.MergeStatus.MERGED, client.merge("branch", NULL_PROGRESS_MONITOR).getMergeStatus()); try { - exportDiff("master", patchFile); + exportDiff(getDefaultBranch(), patchFile); fail(); } catch (GitException ex) { assertEquals("Unable to export a merge commit", ex.getMessage()); } } - public void testExportCommitRename () throws Exception { + public void testExportCommitRename() throws Exception { File patchFile = new File(workDir.getParentFile(), "diff.patch"); File file = new File(workDir, "file"); File renamed = new File(workDir, "renamed"); - File[] files = new File[] { file, renamed }; + File[] files = new File[]{file, renamed}; write(file, "first\nsecond\nthrirrd\n"); add(files); commit(files); - + GitClient client = getClient(workDir); client.rename(file, renamed, false, NULL_PROGRESS_MONITOR); write(renamed, "first\nsecond\nthird\n"); @@ -136,31 +136,31 @@ public void testExportCommitRename () throws Exception { exportDiff(commit.getRevision(), patchFile); assertPatchFile(commit, getGoldenFile("exportCommitRename.patch"), patchFile); } - - public void testExportInitialCommit () throws Exception { + + public void testExportInitialCommit() throws Exception { File patchFile = new File(workDir.getParentFile(), "diff.patch"); File file = new File(workDir, "file"); - File[] files = new File[] { file }; + File[] files = new File[]{file}; write(file, "init\n"); add(files); GitClient client = getClient(workDir); GitRevisionInfo commit = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR); - exportDiff("master", patchFile); + exportDiff(getDefaultBranch(), patchFile); assertPatchFile(commit, getGoldenFile("exportInitialCommit.patch"), patchFile); } - private void exportDiff (String commit, File patchFile) throws Exception { + private void exportDiff(String commit, File patchFile) throws Exception { OutputStream out = new BufferedOutputStream(new FileOutputStream(patchFile)); getClient(workDir).exportCommit(commit, out, NULL_PROGRESS_MONITOR); out.close(); } - private void assertPatchFile (GitRevisionInfo commit, File goldenFile, File patchFile) throws Exception { + private void assertPatchFile(GitRevisionInfo commit, File goldenFile, File patchFile) throws Exception { String expectedContent = read(goldenFile); - expectedContent = MessageFormat.format(expectedContent, new Object[] { commit.getRevision(), + expectedContent = MessageFormat.format(expectedContent, new Object[]{commit.getRevision(), commit.getAuthor(), - DateFormat.getDateTimeInstance().format(new Date(commit.getCommitTime())), - commit.getFullMessage() }); + DateFormat.getDateTimeInstance().format(new Date(commit.getCommitTime())), + commit.getFullMessage()}); assertEquals(expectedContent, read(patchFile)); } } diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/ExportDiffTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/ExportDiffTest.java index f375d5efaa88..1da7065681be 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/ExportDiffTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/ExportDiffTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.BufferedOutputStream; @@ -40,10 +39,11 @@ * @author ondra */ public class ExportDiffTest extends AbstractGitTestCase { + private Repository repository; private File workDir; - public ExportDiffTest (String testName) throws IOException { + public ExportDiffTest(String testName) throws IOException { super(testName); } @@ -53,56 +53,56 @@ protected void setUp() throws Exception { workDir = getWorkingDirectory(); repository = getRepository(getLocalGitRepository()); } - - public void testSkipIgnores () throws Exception { + + public void testSkipIgnores() throws Exception { File file = new File(workDir, "file"); File patchFile = new File(workDir.getParentFile(), "diff.patch"); - File[] files = new File[] { file }; - + File[] files = new File[]{file}; + file.createNewFile(); getClient(workDir).ignore(files, NULL_PROGRESS_MONITOR); add(new File(workDir, Constants.GITIGNORE_FILENAME)); commit(new File(workDir, Constants.GITIGNORE_FILENAME)); - + exportDiff(files, patchFile, GitClient.DiffMode.INDEX_VS_WORKINGTREE); assertTrue(patchFile.exists()); assertEquals("", read(patchFile)); } - - public void testDiffSelectedPaths () throws Exception { + + public void testDiffSelectedPaths() throws Exception { File file1 = new File(workDir, "file1"); File file2 = new File(workDir, "file2"); File patchFile = new File(workDir.getParentFile(), "diff.patch"); - File[] files = new File[] { file1, file2 }; - + File[] files = new File[]{file1, file2}; + file1.createNewFile(); file2.createNewFile(); - + // export diff for both f1 and f2 exportDiff(files, patchFile, GitClient.DiffMode.INDEX_VS_WORKINGTREE); assertTrue(patchFile.exists()); assertTrue(read(patchFile).contains("file1")); assertTrue(read(patchFile).contains("file2")); - + // export diff only for f1 - files = new File[] { file1 }; + files = new File[]{file1}; exportDiff(files, patchFile, GitClient.DiffMode.INDEX_VS_WORKINGTREE); assertTrue(patchFile.exists()); assertTrue(read(patchFile).contains("file1")); assertFalse(read(patchFile).contains("file2")); } - public void testDiffChanges () throws Exception { + public void testDiffChanges() throws Exception { makeInitialCommit(); File file = new File(workDir, "file"); File patchFile = new File(workDir.getParentFile(), "diff.patch"); GitClient client = getClient(workDir); - File[] files = new File[] { file }; + File[] files = new File[]{file}; // no changes exportDiff(files, patchFile, GitClient.DiffMode.INDEX_VS_WORKINGTREE); assertTrue(patchFile.exists()); assertEquals("", read(patchFile)); - + // ******* add ******* write(file, "hello\n"); // index vs wt @@ -115,9 +115,9 @@ public void testDiffChanges () throws Exception { add(file); exportDiff(files, patchFile, GitClient.DiffMode.HEAD_VS_INDEX); assertFile(patchFile, getGoldenFile("diffChanges-head-index-add.patch")); - + commit(file); - + // ******* modify ******* write(file, "modification\n"); // index vs wt @@ -136,7 +136,7 @@ public void testDiffChanges () throws Exception { add(file); exportDiff(files, patchFile, GitClient.DiffMode.HEAD_VS_INDEX); assertFile(patchFile, getGoldenFile("diffChanges-head-index-modify2.patch")); - + commit(file); // ******* delete ******* // index vs wt @@ -154,31 +154,31 @@ public void testDiffChanges () throws Exception { exportDiff(files, patchFile, GitClient.DiffMode.HEAD_VS_WORKINGTREE); assertFile(patchFile, getGoldenFile("diffChanges-head-wt-delete.patch")); } - - public void testDiffRename () throws Exception { + + public void testDiffRename() throws Exception { File file = new File(workDir, "file"); File renamed = new File(workDir, "renamed"); File patchFile = new File(workDir.getParentFile(), "diff.patch"); - File[] files = new File[] { file }; - + File[] files = new File[]{file}; + write(file, "hey, i will be renamed\n"); add(file); commit(file); - + getClient(workDir).rename(file, renamed, false, NULL_PROGRESS_MONITOR); exportDiff(files, patchFile, GitClient.DiffMode.HEAD_VS_WORKINGTREE); assertFile(patchFile, getGoldenFile("diffRename.patch")); - exportDiff(new File[] { file, renamed }, patchFile, GitClient.DiffMode.HEAD_VS_WORKINGTREE); + exportDiff(new File[]{file, renamed}, patchFile, GitClient.DiffMode.HEAD_VS_WORKINGTREE); assertFile(patchFile, getGoldenFile("diffRename2.patch")); write(renamed, "hey, i will be renamed\nand now i am\n"); // add(renamed); - exportDiff(new File[] { file, renamed }, patchFile, GitClient.DiffMode.HEAD_VS_WORKINGTREE); + exportDiff(new File[]{file, renamed}, patchFile, GitClient.DiffMode.HEAD_VS_WORKINGTREE); assertFile(patchFile, getGoldenFile("diffRename3.patch")); } - + // issue in JGit prevents us from calling DiffFormater.format directly // change the source code when it's fixed - public void testDiffRenameDetectionProblem () throws Exception { + public void testDiffRenameDetectionProblem() throws Exception { File file = new File(workDir, "file"); File renamed = new File(workDir, "renamed"); write(file, "hey, i will be renamed\n"); @@ -188,8 +188,7 @@ public void testDiffRenameDetectionProblem () throws Exception { file.renameTo(renamed); write(renamed, "hey, i will be renamed\nand now i am\n"); ByteArrayOutputStream baos = new ByteArrayOutputStream(10240); - try (OutputStream out = new BufferedOutputStream(baos); - DiffFormatter formatter = new DiffFormatter(out);) { + try (OutputStream out = new BufferedOutputStream(baos); DiffFormatter formatter = new DiffFormatter(out);) { formatter.setRepository(repository); formatter.setDetectRenames(true); AbstractTreeIterator firstTree = new DirCacheIterator(repository.readDirCache()); @@ -198,45 +197,45 @@ public void testDiffRenameDetectionProblem () throws Exception { formatter.flush(); } assertFalse( - "Fixed in JGit, modify and simplify the sources in ExportDiff command", - baos.toString().contains("similarity index ") + "Fixed in JGit, modify and simplify the sources in ExportDiff command", + baos.toString().contains("similarity index ") ); } - - public void testDiffTwoCommits () throws Exception { + + public void testDiffTwoCommits() throws Exception { File file = new File(workDir, "file"); File file2 = new File(workDir, "folder/file2"); file2.getParentFile().mkdirs(); File patchFile = new File(workDir.getParentFile(), "diff.patch"); - File[] files = new File[] { file, file2 }; - + File[] files = new File[]{file, file2}; + write(file, "FILE 1\n"); write(file2, "FILE 2\n"); add(); commit(); - + write(file, "FILE 1 CHANGE\n"); write(file2, "FILE 2 CHANGE\n"); add(); commit(); - - exportDiff(files, patchFile, "master~1", "master"); + + exportDiff(files, patchFile, getDefaultBranch() + "~1", getDefaultBranch()); assertFile(patchFile, getGoldenFile("diffTwoCommits.patch")); } - private void exportDiff (File[] files, File patchFile, DiffMode diffMode) throws Exception { + private void exportDiff(File[] files, File patchFile, DiffMode diffMode) throws Exception { try (OutputStream out = new BufferedOutputStream(new FileOutputStream(patchFile))) { getClient(workDir).exportDiff(files, diffMode, out, NULL_PROGRESS_MONITOR); } } - private void exportDiff (File[] files, File patchFile, String base, String to) throws Exception { + private void exportDiff(File[] files, File patchFile, String base, String to) throws Exception { try (OutputStream out = new BufferedOutputStream(new FileOutputStream(patchFile))) { getClient(workDir).exportDiff(files, base, to, out, NULL_PROGRESS_MONITOR); } } - private void makeInitialCommit () throws Exception { + private void makeInitialCommit() throws Exception { File f = new File(workDir, "dummy"); f.createNewFile(); add(f); diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/FetchTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/FetchTest.java index 7bfb6f259ed7..9839e6f3a72d 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/FetchTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/FetchTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -26,7 +25,6 @@ import java.util.Map; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.TagCommand; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryBuilder; @@ -34,7 +32,6 @@ import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RemoteConfig; -import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.URIish; import org.netbeans.libs.git.GitBranch; import org.netbeans.libs.git.GitClient; @@ -44,7 +41,6 @@ import org.netbeans.libs.git.GitTransportUpdate; import org.netbeans.libs.git.GitTransportUpdate.Type; import org.netbeans.libs.git.jgit.AbstractGitTestCase; -import org.netbeans.libs.git.jgit.DelegatingProgressMonitor; import org.netbeans.libs.git.progress.ProgressMonitor; /** @@ -52,6 +48,7 @@ * @author ondra */ public class FetchTest extends AbstractGitTestCase { + private Repository repository; private File workDir; private static final String BRANCH_NAME = "new_branch"; @@ -60,7 +57,7 @@ public class FetchTest extends AbstractGitTestCase { private GitRevisionInfo masterInfo; private GitBranch branch; - public FetchTest (String testName) throws IOException { + public FetchTest(String testName) throws IOException { super(testName); } @@ -69,22 +66,22 @@ protected void setUp() throws Exception { super.setUp(); workDir = getWorkingDirectory(); repository = getRepository(getLocalGitRepository()); - + otherWT = new File(workDir.getParentFile(), "repo2"); GitClient client = getClient(otherWT); client.init(NULL_PROGRESS_MONITOR); f = new File(otherWT, "f"); write(f, "init"); - client.add(new File[] { f }, NULL_PROGRESS_MONITOR); - masterInfo = client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR); - branch = client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR); + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + masterInfo = client.commit(new File[]{f}, "init commit", null, null, NULL_PROGRESS_MONITOR); + branch = client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin"); cfg.addURI(new URIish(otherWT.toURI().toURL().toString())); cfg.update(repository.getConfig()); repository.getConfig().save(); } - public void testFetchAllBranches () throws Exception { + public void testFetchAllBranches() throws Exception { setupRemoteSpec("origin", "+refs/heads/*:refs/remotes/origin/*"); GitClient client = getClient(workDir); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); @@ -92,31 +89,31 @@ public void testFetchAllBranches () throws Exception { Map updates = client.fetch("origin", NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); - assertTrue(branches.get("origin/master").isRemote()); + assertTrue(branches.get("origin/" + getDefaultBranch()).isRemote()); assertTrue(branches.get("origin/" + BRANCH_NAME).isRemote()); assertEquals(branch.getId(), branches.get("origin/" + BRANCH_NAME).getId()); assertEquals(2, updates.size()); - assertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); + assertUpdate(updates.get("origin/" + getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); assertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, branch.getId(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); } - public void testFetchAllBranchesUrl () throws Exception { + public void testFetchAllBranchesUrl() throws Exception { GitClient client = getClient(workDir); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(0, branches.size()); - Map updates = client.fetch(otherWT.toURI().toURL().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), NULL_PROGRESS_MONITOR); + Map updates = client.fetch(otherWT.toURI().toURL().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); - assertTrue(branches.get("origin/master").isRemote()); + assertTrue(branches.get("origin/" + getDefaultBranch()).isRemote()); assertTrue(branches.get("origin/" + BRANCH_NAME).isRemote()); assertEquals(branch.getId(), branches.get("origin/" + BRANCH_NAME).getId()); assertEquals(2, updates.size()); - assertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); + assertUpdate(updates.get("origin/" + getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); assertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, branch.getId(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); } - - public void testFetchNamedBranches () throws Exception { - setupRemoteSpec("origin", "+refs/heads/master:refs/remotes/origin/master"); + + public void testFetchNamedBranches() throws Exception { + setupRemoteSpec("origin", "+refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch()); setupRemoteSpec("origin", "+refs/heads/" + BRANCH_NAME + ":refs/remotes/origin/" + BRANCH_NAME); GitClient client = getClient(workDir); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); @@ -124,29 +121,29 @@ public void testFetchNamedBranches () throws Exception { Map updates = client.fetch("origin", NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); - assertTrue(branches.get("origin/master").isRemote()); + assertTrue(branches.get("origin/" + getDefaultBranch()).isRemote()); assertTrue(branches.get("origin/" + BRANCH_NAME).isRemote()); assertEquals(branch.getId(), branches.get("origin/" + BRANCH_NAME).getId()); assertEquals(2, updates.size()); - assertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); + assertUpdate(updates.get("origin/" + getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); assertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, branch.getId(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); } - - public void testFetchMaster () throws Exception { - setupRemoteSpec("origin", "+refs/heads/master:refs/remotes/origin/master"); + + public void testFetchMaster() throws Exception { + setupRemoteSpec("origin", "+refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch()); GitClient client = getClient(workDir); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(0, branches.size()); Map updates = client.fetch("origin", NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(1, branches.size()); - assertTrue(branches.get("origin/master").isRemote()); - assertEquals(masterInfo.getRevision(), branches.get("origin/master").getId()); + assertTrue(branches.get("origin/" + getDefaultBranch()).isRemote()); + assertEquals(masterInfo.getRevision(), branches.get("origin/" + getDefaultBranch()).getId()); assertEquals(1, updates.size()); - assertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); + assertUpdate(updates.get("origin/" + getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); } - - public void testFetchNothingToFetch () throws Exception { + + public void testFetchNothingToFetch() throws Exception { GitClient client = getClient(workDir); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(0, branches.size()); @@ -157,33 +154,33 @@ public void testFetchNothingToFetch () throws Exception { assertEquals("Nothing to fetch.", ex.getMessage()); } } - - public void testFetchMasterExplicitely () throws Exception { + + public void testFetchMasterExplicitely() throws Exception { GitClient client = getClient(workDir); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(0, branches.size()); setupRemoteSpec("origin", "+refs/heads/*:refs/remotes/origin/*"); - Map updates = client.fetch("origin", Arrays.asList(new String[] { "+refs/heads/master:refs/remotes/origin/master" }), NULL_PROGRESS_MONITOR); + Map updates = client.fetch("origin", Arrays.asList(new String[]{"+refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch()}), NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(1, branches.size()); - assertTrue(branches.get("origin/master").isRemote()); - assertEquals(masterInfo.getRevision(), branches.get("origin/master").getId()); + assertTrue(branches.get("origin/" + getDefaultBranch()).isRemote()); + assertEquals(masterInfo.getRevision(), branches.get("origin/" + getDefaultBranch()).getId()); assertEquals(1, updates.size()); - assertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); + assertUpdate(updates.get("origin/" + getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); } - - public void testFetchAllExplicitely () throws Exception { + + public void testFetchAllExplicitely() throws Exception { GitClient client = getClient(workDir); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(0, branches.size()); - Map updates = client.fetch("origin", Arrays.asList(new String[] { "+refs/heads/master:refs/remotes/origin/master", "+refs/heads/" + BRANCH_NAME + ":refs/remotes/origin/" + BRANCH_NAME }), NULL_PROGRESS_MONITOR); + Map updates = client.fetch("origin", Arrays.asList(new String[]{"+refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch(), "+refs/heads/" + BRANCH_NAME + ":refs/remotes/origin/" + BRANCH_NAME}), NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); - assertTrue(branches.get("origin/master").isRemote()); + assertTrue(branches.get("origin/" + getDefaultBranch()).isRemote()); assertTrue(branches.get("origin/" + BRANCH_NAME).isRemote()); assertEquals(branch.getId(), branches.get("origin/" + BRANCH_NAME).getId()); assertEquals(2, updates.size()); - assertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); + assertUpdate(updates.get("origin/" + getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); assertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, branch.getId(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); } @@ -217,14 +214,13 @@ public void testFetchAllExplicitely () throws Exception { // assertEquals(1, updates.size()); // assertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, null, branch.getId(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FORCED); // } - - public void testFetchTags () throws Exception { - setupRemoteSpec("origin", "+refs/heads/master:refs/remotes/origin/master"); + public void testFetchTags() throws Exception { + setupRemoteSpec("origin", "+refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch()); GitClient client = getClient(workDir); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(0, branches.size()); client.fetch("origin", NULL_PROGRESS_MONITOR); - + Repository repo = new RepositoryBuilder().setGitDir(new File(otherWT, ".git")).build(); TagCommand cmd = new Git(repo).tag(); cmd.setMessage("new tag message"); @@ -232,7 +228,7 @@ public void testFetchTags () throws Exception { cmd.setObjectId(new RevWalk(repo).parseCommit(repo.resolve(masterInfo.getRevision()))); Ref ref = cmd.call(); RevTag tag = new RevWalk(repo).parseTag(ref.getObjectId()); - + Map updates = client.fetch("origin", NULL_PROGRESS_MONITOR); Ref tagRef = repository.getRefDatabase().findRef(tag.getTagName()); assertEquals(tag.getId(), tagRef.getTarget().getObjectId()); @@ -240,7 +236,7 @@ public void testFetchTags () throws Exception { assertUpdate(updates.get(tag.getTagName()), tag.getTagName(), tag.getTagName(), tag.getId().getName(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.TAG, GitRefUpdateResult.NEW); } - public void testFetchProgress () throws Exception { + public void testFetchProgress() throws Exception { setupRemoteSpec("origin", "+refs/heads/*:refs/remotes/origin/*"); GitClient client = getClient(workDir); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); @@ -249,7 +245,7 @@ public void testFetchProgress () throws Exception { ProgressMonitor pm = new ProgressMonitor.DefaultProgressMonitor() { @Override - public void beginTask (String taskName, int totalWorkUnits) { + public void beginTask(String taskName, int totalWorkUnits) { sb.append("START: ").append(taskName); if (totalWorkUnits > 0) { sb.append(" - ").append(totalWorkUnits).append("\n"); @@ -257,15 +253,15 @@ public void beginTask (String taskName, int totalWorkUnits) { } @Override - public void updateTaskState (int completed) { + public void updateTaskState(int completed) { sb.append("UPDATE: ").append(completed).append("\n"); } @Override - public void endTask () { + public void endTask() { sb.append("ENDED\n"); } - + }; client.fetch("origin", pm); String messages = sb.toString(); @@ -275,7 +271,7 @@ public void endTask () { assertTrue(messages, messages.contains("START: Receiving objects - ")); } - private void setupRemoteSpec (String remote, String fetchSpec) throws URISyntaxException, IOException { + private void setupRemoteSpec(String remote, String fetchSpec) throws URISyntaxException, IOException { RemoteConfig cfg = new RemoteConfig(repository.getConfig(), remote); cfg.addFetchRefSpec(new RefSpec(fetchSpec)); cfg.update(repository.getConfig()); diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/GetCommonAncestorTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/GetCommonAncestorTest.java index e6863d382ec7..8d2850df2e60 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/GetCommonAncestorTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/GetCommonAncestorTest.java @@ -16,12 +16,10 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; import java.io.IOException; -import org.eclipse.jgit.lib.Constants; import org.netbeans.libs.git.GitClient; import org.netbeans.libs.git.GitException; import org.netbeans.libs.git.GitMergeResult; @@ -33,10 +31,11 @@ * @author ondra */ public class GetCommonAncestorTest extends AbstractGitTestCase { + private File workDir; private static final String BRANCH_NAME = "new_branch"; - public GetCommonAncestorTest (String testName) throws IOException { + public GetCommonAncestorTest(String testName) throws IOException { super(testName); } @@ -46,10 +45,10 @@ protected void setUp() throws Exception { workDir = getWorkingDirectory(); } - public void testGetBaseRevisionMerge () throws Exception { + public void testGetBaseRevisionMerge() throws Exception { File f = new File(workDir, "f"); write(f, "a\nb\nc"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); commit(files); @@ -57,28 +56,28 @@ public void testGetBaseRevisionMerge () throws Exception { write(f, "a\nb\nc\n"); add(files); GitRevisionInfo revisionBase = client.commit(files, "base revision", null, null, NULL_PROGRESS_MONITOR); - - client.createBranch("b", "master", NULL_PROGRESS_MONITOR); + + client.createBranch("b", getDefaultBranch(), NULL_PROGRESS_MONITOR); client.checkoutRevision("b", true, NULL_PROGRESS_MONITOR); - + write(f, "modification on branch\nb\nc\n"); add(files); - - client.checkoutRevision("master", true, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); write(f, "a\nb\nmodification on master\n"); add(files); 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); - + GitRevisionInfo revision = client.getCommonAncestor(revisionMerge.getParents(), NULL_PROGRESS_MONITOR); assertRevisions(revisionBase, revision); } - - public void testGetBaseRevisionSimpleCommit () throws Exception { + + public void testGetBaseRevisionSimpleCommit() throws Exception { File f = new File(workDir, "f"); write(f, "init"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); commit(files); @@ -86,14 +85,14 @@ public void testGetBaseRevisionSimpleCommit () throws Exception { write(f, "modification"); add(files); GitRevisionInfo commit = client.commit(files, "modification", null, null, NULL_PROGRESS_MONITOR); - GitRevisionInfo revision = client.getCommonAncestor(new String[] { commit.getRevision() }, NULL_PROGRESS_MONITOR); + GitRevisionInfo revision = client.getCommonAncestor(new String[]{commit.getRevision()}, NULL_PROGRESS_MONITOR); assertRevisions(commit, revision); } - - public void testGetBaseRevisionCommitsInRow () throws Exception { + + public void testGetBaseRevisionCommitsInRow() throws Exception { File f = new File(workDir, "f"); write(f, "init"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); commit(files); @@ -101,100 +100,100 @@ public void testGetBaseRevisionCommitsInRow () throws Exception { write(f, "modification 1"); add(files); GitRevisionInfo commit1 = client.commit(files, "modification 1", null, null, NULL_PROGRESS_MONITOR); - + write(f, "modification 2"); add(files); GitRevisionInfo commit2 = client.commit(files, "modification 2", null, null, NULL_PROGRESS_MONITOR); - + write(f, "modification 3"); add(files); GitRevisionInfo commit3 = client.commit(files, "modification 3", null, null, NULL_PROGRESS_MONITOR); - GitRevisionInfo revision = client.getCommonAncestor(new String[] { commit1.getRevision(), commit2.getRevision(), commit3.getRevision() }, NULL_PROGRESS_MONITOR); + GitRevisionInfo revision = client.getCommonAncestor(new String[]{commit1.getRevision(), commit2.getRevision(), commit3.getRevision()}, NULL_PROGRESS_MONITOR); assertRevisions(commit1, revision); } - - public void testGetBaseCrissCross_232904 () throws Exception { + + public void testGetBaseCrissCross_232904() throws Exception { File f1 = new File(workDir, "f1"); File f2 = new File(workDir, "f2"); File f3 = new File(workDir, "f3"); write(f1, "initial content"); GitClient client = getClient(workDir); - File[] files = new File[] { f1, f2, f3 }; + File[] files = new File[]{f1, f2, f3}; client.add(files, NULL_PROGRESS_MONITOR); GitRevisionInfo initial = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR); - - client.createBranch(BRANCH_NAME, "master", NULL_PROGRESS_MONITOR); - + + client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); + // change on master - write(f1, Constants.MASTER); + write(f1, getDefaultBranch()); client.add(files, NULL_PROGRESS_MONITOR); client.commit(files, "master commit", null, null, NULL_PROGRESS_MONITOR); - GitRevisionInfo masterCommit = client.log("master", NULL_PROGRESS_MONITOR); - + GitRevisionInfo masterCommit = client.log(getDefaultBranch(), NULL_PROGRESS_MONITOR); + // change on branch client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); write(f2, BRANCH_NAME); client.add(files, NULL_PROGRESS_MONITOR); client.commit(files, "branch commit", null, null, NULL_PROGRESS_MONITOR); GitRevisionInfo branchCommit = client.log(BRANCH_NAME, NULL_PROGRESS_MONITOR); - + // merge last master commit (not merge) into branch client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); client.merge(masterCommit.getRevision(), NULL_PROGRESS_MONITOR); - + // merge last branch commit (not merge) into master - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); client.merge(branchCommit.getRevision(), NULL_PROGRESS_MONITOR); - - GitRevisionInfo ancestor = client.getCommonAncestor(new String[] { Constants.MASTER, BRANCH_NAME }, NULL_PROGRESS_MONITOR); + + GitRevisionInfo ancestor = client.getCommonAncestor(new String[]{getDefaultBranch(), BRANCH_NAME}, NULL_PROGRESS_MONITOR); assertEquals(initial.getRevision(), ancestor.getRevision()); } - - public void testGetBaseCrissCrossConflict_244222 () throws Exception { + + public void testGetBaseCrissCrossConflict_244222() throws Exception { File f1 = new File(workDir, "f1"); File f2 = new File(workDir, "f2"); File f3 = new File(workDir, "f3"); write(f1, "initial content"); GitClient client = getClient(workDir); - File[] files = new File[] { f1, f2, f3 }; + File[] files = new File[]{f1, f2, f3}; client.add(files, NULL_PROGRESS_MONITOR); GitRevisionInfo initial = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR); - - client.createBranch(BRANCH_NAME, "master", NULL_PROGRESS_MONITOR); - + + client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); + // change on master - write(f1, Constants.MASTER); + write(f1, getDefaultBranch()); client.add(files, NULL_PROGRESS_MONITOR); client.commit(files, "master commit", null, null, NULL_PROGRESS_MONITOR); - GitRevisionInfo masterCommit = client.log("master", NULL_PROGRESS_MONITOR); - + GitRevisionInfo masterCommit = client.log(getDefaultBranch(), NULL_PROGRESS_MONITOR); + // change on branch client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); write(f1, BRANCH_NAME); client.add(files, NULL_PROGRESS_MONITOR); client.commit(files, "branch commit", null, null, NULL_PROGRESS_MONITOR); GitRevisionInfo branchCommit = client.log(BRANCH_NAME, NULL_PROGRESS_MONITOR); - + // merge last master commit (not merge) into branch GitMergeResult res = client.merge(masterCommit.getRevision(), NULL_PROGRESS_MONITOR); assertEquals(GitMergeResult.MergeStatus.CONFLICTING, res.getMergeStatus()); write(f1, BRANCH_NAME); client.add(files, NULL_PROGRESS_MONITOR); client.commit(new File[0], "Merge master into branch", null, null, NULL_PROGRESS_MONITOR); - + // merge last branch commit (not merge) into master - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); res = client.merge(branchCommit.getRevision(), NULL_PROGRESS_MONITOR); assertEquals(GitMergeResult.MergeStatus.CONFLICTING, res.getMergeStatus()); - write(f1, Constants.MASTER); + write(f1, getDefaultBranch()); client.add(files, NULL_PROGRESS_MONITOR); client.commit(new File[0], "Merge branch into master", null, null, NULL_PROGRESS_MONITOR); - - GitRevisionInfo ancestor = client.getCommonAncestor(new String[] { Constants.MASTER, BRANCH_NAME }, NULL_PROGRESS_MONITOR); + + GitRevisionInfo ancestor = client.getCommonAncestor(new String[]{getDefaultBranch(), BRANCH_NAME}, NULL_PROGRESS_MONITOR); assertEquals(initial.getRevision(), ancestor.getRevision()); } - private void assertRevisions (GitRevisionInfo expected, GitRevisionInfo info) throws GitException { + private void assertRevisions(GitRevisionInfo expected, GitRevisionInfo info) throws GitException { assertEquals(expected.getRevision(), info.getRevision()); assertEquals(expected.getAuthor().toString(), info.getAuthor().toString()); assertEquals(expected.getCommitTime(), info.getCommitTime()); diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/InitTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/InitTest.java index 6d93d239d1fd..2a272f55d5bb 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/InitTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/InitTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -40,7 +39,7 @@ public class InitTest extends AbstractGitTestCase { private File workDir; - public InitTest (String testName) throws IOException { + public InitTest(String testName) throws IOException { super(testName); } @@ -50,7 +49,7 @@ protected void setUp() throws Exception { workDir = getWorkingDirectory(); } - public void testInit () throws Exception { + public void testInit() throws Exception { File repo2 = new File(workDir.getParentFile(), "other"); GitClient client = GitRepository.getInstance(repo2).createClient(); Field f = GitClient.class.getDeclaredField("gitRepository"); @@ -59,7 +58,7 @@ public void testInit () throws Exception { f = JGitRepository.class.getDeclaredField("repository"); f.setAccessible(true); Repository repo = (Repository) f.get(jgitRepo); - + assertFalse(repo.getDirectory().exists()); assertFalse(repo.getIndexFile().exists()); assertNull(repo.getBranch()); @@ -69,7 +68,7 @@ public void testInit () throws Exception { DirCache index = repo.readDirCache(); assertEquals(0, index.getEntryCount()); assertTrue(repo.getDirectory().exists()); - assertEquals("master", repo.getBranch()); + assertEquals(getDefaultBranch(), repo.getBranch()); assertConfig(new FileBasedConfig(new File(repo.getDirectory(), "config"), repo.getFS())); // test failure when repository already exists @@ -81,7 +80,7 @@ public void testInit () throws Exception { } } - private void assertConfig (FileBasedConfig config) throws Exception { + private void assertConfig(FileBasedConfig config) throws Exception { config.load(); // filemode assertEquals(isWindows() ? "false" : "true", config.getString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE)); diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/LogTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/LogTest.java index ddef2eda4b08..a9c32b6e4bb6 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/LogTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/LogTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -46,10 +45,11 @@ * @author ondra */ public class LogTest extends AbstractGitTestCase { + private Repository repository; private File workDir; - public LogTest (String testName) throws IOException { + public LogTest(String testName) throws IOException { super(testName); } @@ -69,10 +69,10 @@ public void testMaxApplicationFlagCount() throws Exception { assertEquals(LogCommand.MAX_REVWALK_FLAGS, available); // if this fails, adjust the value } - public void testLogRevision () throws Exception { + public void testLogRevision() throws Exception { File f = new File(workDir, "testcat1"); write(f, "initial content"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); GitClient client = getClient(workDir); @@ -90,10 +90,10 @@ public void testLogRevision () throws Exception { assertRevisions(revision2, revision); } - public void testLogRevisionTo () throws Exception { + public void testLogRevisionTo() throws Exception { File f = new File(workDir, "testcat1"); write(f, "initial content"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); GitClient client = getClient(workDir); GitRevisionInfo revision0 = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR); @@ -102,11 +102,11 @@ public void testLogRevisionTo () throws Exception { 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); @@ -124,11 +124,11 @@ public void testLogRevisionTo () throws Exception { assertRevisions(revision1, revisions[3]); assertRevisions(revision0, revisions[4]); } - - public void testLogRevisionRange () throws Exception { + + public void testLogRevisionRange() throws Exception { File f = new File(workDir, "testcat1"); write(f, "initial content"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); commit(files); @@ -138,11 +138,10 @@ public void testLogRevisionRange () throws Exception { 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); @@ -166,11 +165,11 @@ public void testLogRevisionRange () throws Exception { assertRevisions(revision3, revisions[1]); assertRevisions(revision2, revisions[2]); } - - public void testLogSingleBranch () throws Exception { + + public void testLogSingleBranch() throws Exception { File f = new File(workDir, "file"); write(f, "initial content"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); GitClient client = getClient(workDir); GitRevisionInfo revision0 = client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR); @@ -179,7 +178,7 @@ public void testLogSingleBranch () throws Exception { 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"); @@ -194,7 +193,7 @@ public void testLogSingleBranch () throws Exception { 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); @@ -218,7 +217,7 @@ public void testLogSingleBranch () throws Exception { assertRevisions(revisionA1, revisions[1]); assertRevisions(revision1, revisions[2]); assertRevisions(revision0, revisions[3]); - + crit = new SearchCriteria(); crit.setRevisionTo("B"); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); @@ -227,7 +226,7 @@ public void testLogSingleBranch () throws Exception { assertRevisions(revisionB1, revisions[1]); assertRevisions(revision1, revisions[2]); assertRevisions(revision0, revisions[3]); - + // try both branches, how are the revisions sorted? revisions = client.log(new SearchCriteria(), true, NULL_PROGRESS_MONITOR); assertEquals(6, revisions.length); @@ -238,11 +237,11 @@ public void testLogSingleBranch () throws Exception { assertRevisions(revision1, revisions[4]); assertRevisions(revision0, revisions[5]); } - - public void testLogLimit () throws Exception { + + public void testLogLimit() throws Exception { File f = new File(workDir, "testcat1"); write(f, "initial content"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); commit(files); @@ -251,11 +250,11 @@ public void testLogLimit () throws Exception { 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); @@ -271,7 +270,7 @@ public void testLogLimit () throws Exception { assertRevisions(revision4, revisions[0]); assertRevisions(revision3, revisions[1]); assertRevisions(revision2, revisions[2]); - + crit = new SearchCriteria(); crit.setRevisionFrom(revision2.getRevision()); crit.setRevisionTo(revision4.getRevision()); @@ -281,14 +280,14 @@ public void testLogLimit () throws Exception { assertRevisions(revision4, revisions[0]); assertRevisions(revision3, revisions[1]); } - - public void testLogFiles () throws Exception { + + 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 }; + File[] files = new File[]{f1, f2}; add(files); GitClient client = getClient(workDir); commit(files); @@ -297,36 +296,36 @@ public void testLogFiles () throws Exception { 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); - + 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.setFiles(new File[]{f1}); crit.setRevisionFrom(revision1.getRevision()); GitRevisionInfo[] revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(2, revisions.length); assertRevisions(revision3, revisions[0]); assertRevisions(revision1, revisions[1]); - + crit = new SearchCriteria(); - crit.setFiles(new File[] { f2 }); + crit.setFiles(new File[]{f2}); crit.setRevisionFrom(revision1.getRevision()); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(2, revisions.length); assertRevisions(revision3, revisions[0]); assertRevisions(revision2, revisions[1]); - + crit = new SearchCriteria(); crit.setFiles(files); crit.setRevisionFrom(revision1.getRevision()); @@ -335,9 +334,9 @@ public void testLogFiles () throws Exception { assertRevisions(revision3, revisions[0]); assertRevisions(revision2, revisions[1]); assertRevisions(revision1, revisions[2]); - + crit = new SearchCriteria(); - crit.setFiles(new File[] { f1, f2, f3 }); + crit.setFiles(new File[]{f1, f2, f3}); crit.setRevisionFrom(revision1.getRevision()); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(4, revisions.length); @@ -345,9 +344,9 @@ public void testLogFiles () throws Exception { assertRevisions(revision3, revisions[1]); assertRevisions(revision2, revisions[2]); assertRevisions(revision1, revisions[3]); - + crit = new SearchCriteria(); - crit.setFiles(new File[] { workDir }); + crit.setFiles(new File[]{workDir}); crit.setRevisionFrom(revision1.getRevision()); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(4, revisions.length); @@ -356,11 +355,11 @@ public void testLogFiles () throws Exception { assertRevisions(revision2, revisions[2]); assertRevisions(revision1, revisions[3]); } - - public void testLogUsername () throws Exception { + + public void testLogUsername() throws Exception { File f = new File(workDir, "f"); write(f, "initial content"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); commit(files); @@ -374,37 +373,37 @@ public void testLogUsername () throws Exception { 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); assertEquals(3, revisions.length); - + crit = new SearchCriteria(); crit.setUsername("git-test-user"); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(2, revisions.length); assertRevisions(revision2, revisions[0]); assertRevisions(revision1, revisions[1]); - + crit = new SearchCriteria(); crit.setUsername("git-test-user@domain.com"); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(2, revisions.length); assertRevisions(revision2, revisions[0]); assertRevisions(revision1, revisions[1]); - + crit = new SearchCriteria(); crit.setUsername("test-user"); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(2, revisions.length); assertRevisions(revision2, revisions[0]); assertRevisions(revision1, revisions[1]); - + crit = new SearchCriteria(); crit.setUsername("git-test-user222@domain.com"); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(0, revisions.length); - + crit = new SearchCriteria(); crit.setUsername("git-test-user "); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); @@ -412,11 +411,11 @@ public void testLogUsername () throws Exception { assertRevisions(revision2, revisions[0]); assertRevisions(revision1, revisions[1]); } - - public void testLogMessage () throws Exception { + + public void testLogMessage() throws Exception { File f = new File(workDir, "f"); write(f, "initial content"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); commit(files); @@ -425,28 +424,28 @@ public void testLogMessage () throws Exception { 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); assertEquals(2, revisions.length); - + crit = new SearchCriteria(); crit.setMessage("blablabla"); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(0, revisions.length); - + crit = new SearchCriteria(); crit.setMessage("modification"); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(1, revisions.length); assertRevisions(revision1, revisions[0]); - + crit = new SearchCriteria(); crit.setMessage("modification1\non master"); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(1, revisions.length); assertRevisions(revision1, revisions[0]); - + // see bug #228905 crit = new SearchCriteria(); crit.setMessage("on master"); @@ -454,8 +453,8 @@ public void testLogMessage () throws Exception { assertEquals(1, revisions.length); assertRevisions(revision1, revisions[0]); } - - public void testSubstringFilter () throws Exception { + + public void testSubstringFilter() throws Exception { Git git = new Git(repository); RevCommit c = git.commit().setMessage("abcd").call(); @@ -510,43 +509,43 @@ public void testSubstringFilter () throws Exception { assertEquals(1, log.length); } } - - public void testLogShowMerges () throws Exception { + + public void testLogShowMerges() throws Exception { File f = new File(workDir, "f"); write(f, "a\nb\nc"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); commit(files); GitClient client = getClient(workDir); - client.createBranch("b", "master", NULL_PROGRESS_MONITOR); + client.createBranch("b", getDefaultBranch(), 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); + + client.checkoutRevision(getDefaultBranch(), 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"); + crit.setRevisionTo(getDefaultBranch()); GitRevisionInfo[] revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(4, revisions.length); assertRevisions(revisionMerge, revisions[0]); - + crit = new SearchCriteria(); crit.setIncludeMerges(true); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(4, revisions.length); assertRevisions(revisionMerge, revisions[0]); - + crit = new SearchCriteria(); crit.setIncludeMerges(false); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); @@ -554,11 +553,11 @@ public void testLogShowMerges () throws Exception { assertRevisions(revisionMaster, revisions[0]); assertRevisions(revisionBranch, revisions[1]); } - - public void testLogDateCriteria () throws Exception { + + public void testLogDateCriteria() throws Exception { File f = new File(workDir, "f"); write(f, "initial content"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); commit(files); @@ -569,7 +568,7 @@ public void testLogDateCriteria () throws Exception { 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); @@ -599,7 +598,7 @@ public void testLogDateCriteria () throws Exception { assertEquals(2, revisions.length); assertRevisions(revision3, revisions[0]); assertRevisions(revision2, revisions[1]); - + crit = new SearchCriteria(); crit.setFrom(new Date(revision2.getCommitTime())); crit.setTo(new Date(revision4.getCommitTime())); @@ -608,7 +607,7 @@ public void testLogDateCriteria () throws Exception { assertRevisions(revision4, revisions[0]); assertRevisions(revision3, revisions[1]); assertRevisions(revision2, revisions[2]); - + crit = new SearchCriteria(); crit.setFrom(new Date(revision2.getCommitTime())); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); @@ -617,12 +616,12 @@ public void testLogDateCriteria () throws Exception { assertRevisions(revision3, revisions[1]); assertRevisions(revision2, revisions[2]); } - - public void testLogFollowRename () throws Exception { + + public void testLogFollowRename() throws Exception { File f = new File(workDir, "f"); File to = new File(workDir, "renamed"); write(f, "initial content"); - File[] files = new File[] { f, to }; + File[] files = new File[]{f, to}; add(files); commit(files); @@ -631,16 +630,16 @@ public void testLogFollowRename () throws Exception { GitClient client = getClient(workDir); GitRevisionInfo revision1 = client.commit(files, "modification1", null, null, NULL_PROGRESS_MONITOR); - + client.rename(f, to, false, NULL_PROGRESS_MONITOR); GitRevisionInfo revision2 = client.commit(files, "rename", null, null, NULL_PROGRESS_MONITOR); write(to, "modification2"); add(files); GitRevisionInfo revision3 = client.commit(files, "modification2", null, null, NULL_PROGRESS_MONITOR); - + SearchCriteria crit = new SearchCriteria(); - crit.setFiles(new File[] { to }); + crit.setFiles(new File[]{to}); GitRevisionInfo[] revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(2, revisions.length); assertRevisions(revision3, revisions[0]); @@ -649,9 +648,9 @@ public void testLogFollowRename () throws Exception { assertEquals(2, modifiedFiles.size()); assertEquals(GitFileInfo.Status.RENAMED, modifiedFiles.get(to).getStatus()); assertEquals(GitFileInfo.Status.REMOVED, modifiedFiles.get(f).getStatus()); - + crit = new SearchCriteria(); - crit.setFiles(new File[] { to }); + crit.setFiles(new File[]{to}); crit.setFollowRenames(true); revisions = client.log(crit, true, NULL_PROGRESS_MONITOR); assertEquals(4, revisions.length); @@ -660,117 +659,117 @@ public void testLogFollowRename () throws Exception { assertRevisions(revision1, revisions[2]); } - public void testLogMergeFilesFromAllParents () throws Exception { + public void testLogMergeFilesFromAllParents() 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 }; + File[] files = new File[]{f, f2}; add(files); commit(files); GitClient client = getClient(workDir); - client.createBranch("b", "master", NULL_PROGRESS_MONITOR); + client.createBranch("b", getDefaultBranch(), NULL_PROGRESS_MONITOR); client.checkoutRevision("b", true, NULL_PROGRESS_MONITOR); - + write(f, "modification on branch"); add(files); client.commit(files, "modification on branch", null, null, NULL_PROGRESS_MONITOR); - - client.checkoutRevision("master", true, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); write(f2, "modification"); add(files); 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); Map modifiedFiles = revisionMerge.getModifiedFiles(); assertEquals(2, modifiedFiles.size()); assertEquals(GitFileInfo.Status.MODIFIED, modifiedFiles.get(f).getStatus()); assertEquals(GitFileInfo.Status.MODIFIED, modifiedFiles.get(f2).getStatus()); } - - public void testLogWithBranchInfo () throws Exception { + + public void testLogWithBranchInfo() 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 }; + File[] files = new File[]{f, f2}; add(files); commit(files); - + write(f, "modification"); add(files); commit(files); - + GitClient client = getClient(workDir); - client.createBranch("BRANCH", "master", NULL_PROGRESS_MONITOR); + client.createBranch("BRANCH", getDefaultBranch(), NULL_PROGRESS_MONITOR); SearchCriteria crit = new SearchCriteria(); - crit.setRevisionTo("master"); + crit.setRevisionTo(getDefaultBranch()); GitRevisionInfo[] log = client.log(crit, NULL_PROGRESS_MONITOR); for (GitRevisionInfo info : log) { // no branch info fetched by this version of the command assertEquals(0, info.getBranches().size()); } - + log = client.log(crit, true, NULL_PROGRESS_MONITOR); for (GitRevisionInfo info : log) { // all commits are from master assertEquals(2, info.getBranches().size()); - assertNotNull(info.getBranches().get("master")); + assertNotNull(info.getBranches().get(getDefaultBranch())); assertNotNull(info.getBranches().get("BRANCH")); } } - + // commit in the middle of a named branch - public void testLogWithBranchInfoMiddleCommit () throws Exception { + 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 }; + 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); - + + client.createBranch("newbranch", getDefaultBranch(), 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 }); + 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 assertNotNull(info.getBranches().get("newbranch")); assertEquals(2, info.getBranches().size()); } - - public void testLogWithBranchInfoMoreBranches () throws Exception { + + public void testLogWithBranchInfoMoreBranches() 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 }; + File[] files = new File[]{f, f2}; add(files); commit(files); - + write(f, "modification"); add(files); commit(files); - + GitClient client = getClient(workDir); - client.createBranch("newbranch", "master", NULL_PROGRESS_MONITOR); + client.createBranch("newbranch", getDefaultBranch(), NULL_PROGRESS_MONITOR); write(f, "modification on trunk"); add(files); commit(files); - + client.checkoutRevision("newbranch", true, NULL_PROGRESS_MONITOR); write(f, "modification on branch"); // git commit timestamp resolution is one second. @@ -780,7 +779,7 @@ public void testLogWithBranchInfoMoreBranches () throws Exception { Thread.sleep(1100); add(files); commit(files); - + SearchCriteria crit = new SearchCriteria(); // log across all branches GitRevisionInfo[] log = client.log(crit, true, NULL_PROGRESS_MONITOR); @@ -789,65 +788,65 @@ public void testLogWithBranchInfoMoreBranches () throws Exception { assertNotNull(log[0].getBranches().get("newbranch")); // master commit assertEquals(1, log[1].getBranches().size()); - assertNotNull(log[1].getBranches().get("master")); + assertNotNull(log[1].getBranches().get(getDefaultBranch())); // common commit assertEquals(2, log[2].getBranches().size()); - assertNotNull(log[2].getBranches().get("master")); + assertNotNull(log[2].getBranches().get(getDefaultBranch())); assertNotNull(log[2].getBranches().get("newbranch")); // initial commit assertEquals(2, log[3].getBranches().size()); - assertNotNull(log[3].getBranches().get("master")); + assertNotNull(log[3].getBranches().get(getDefaultBranch())); assertNotNull(log[3].getBranches().get("newbranch")); } - - public void testShortMessages () throws Exception { + + public void testShortMessages() throws Exception { File f = new File(workDir, "f"); write(f, "init"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; add(files); GitClient client = getClient(workDir); client.commit(files, "short message", null, null, NULL_PROGRESS_MONITOR); assertEquals("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); assertEquals("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); assertEquals("short message", client.log("HEAD", NULL_PROGRESS_MONITOR).getShortMessage()); } - - public void testLimit () throws Exception { + + 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 }; + + 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); - assertEquals(c1.getRevision(), log[0].getRevision()); + assertEquals(c1.getRevision(), log[0].getRevision()); } - private void assertRevisions (GitRevisionInfo expected, GitRevisionInfo info) throws GitException { + private void assertRevisions(GitRevisionInfo expected, GitRevisionInfo info) throws GitException { assertEquals(expected.getRevision(), info.getRevision()); assertEquals(expected.getAuthor().toString(), info.getAuthor().toString()); assertEquals(expected.getCommitTime(), info.getCommitTime()); diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/MergeTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/MergeTest.java index 1088f9d6c9ef..a6582942b5b1 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/MergeTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/MergeTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -24,7 +23,6 @@ import java.util.Arrays; import java.util.Map; import org.eclipse.jgit.lib.ConfigConstants; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; @@ -45,11 +43,12 @@ * @author ondra */ public class MergeTest extends AbstractGitTestCase { + private File workDir; private static final String BRANCH_NAME = "new_branch"; private Repository repo; - public MergeTest (String testName) throws IOException { + public MergeTest(String testName) throws IOException { super(testName); } @@ -60,156 +59,156 @@ protected void setUp() throws Exception { repo = getRepository(getLocalGitRepository()); } - public void testMergeNoChange () throws Exception { + public void testMergeNoChange() throws Exception { File f = new File(workDir, "file"); write(f, "init"); add(f); commit(f); - + GitClient client = getClient(workDir); - GitBranch branch = client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR); - + GitBranch branch = client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); + GitMergeResult result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); result = client.merge(branch.getId(), NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); } - - public void testMergeFastForward () throws Exception { + + 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.createBranch(BRANCH_NAME, getDefaultBranch(), 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); - + GitRevisionInfo info = client.commit(new File[]{f}, "change on branch", null, null, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); + assertEquals("init", read(f)); - + GitMergeResult result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals(BRANCH_NAME, read(f)); - + SearchCriteria crit = new SearchCriteria(); - crit.setRevisionTo(Constants.MASTER); + crit.setRevisionTo(getDefaultBranch()); GitRevisionInfo[] logs = client.log(crit, NULL_PROGRESS_MONITOR); assertEquals(2, logs.length); assertEquals(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); - + info = client.commit(new File[]{f}, "delete on branch", null, null, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); + assertEquals(BRANCH_NAME, read(f)); - + result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertFalse(f.exists()); - + crit = new SearchCriteria(); - crit.setRevisionTo(Constants.MASTER); + crit.setRevisionTo(getDefaultBranch()); logs = client.log(crit, NULL_PROGRESS_MONITOR); assertEquals(3, logs.length); assertEquals(logs[0].getRevision(), info.getRevision()); } - - public void testMergeRevision () throws Exception { + + 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.createBranch(BRANCH_NAME, getDefaultBranch(), 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); + 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); - + GitRevisionInfo info2 = client.commit(new File[]{f}, "change on branch", null, null, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); + assertEquals("init", read(f)); - + GitMergeResult result = client.merge(info.getRevision(), NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals(BRANCH_NAME, read(f)); - + SearchCriteria crit = new SearchCriteria(); - crit.setRevisionTo(Constants.MASTER); + crit.setRevisionTo(getDefaultBranch()); GitRevisionInfo[] logs = client.log(crit, NULL_PROGRESS_MONITOR); assertEquals(2, logs.length); assertEquals(logs[0].getRevision(), info.getRevision()); - + // merge the rest result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals("another change", read(f)); - + crit = new SearchCriteria(); - crit.setRevisionTo(Constants.MASTER); + crit.setRevisionTo(getDefaultBranch()); logs = client.log(crit, NULL_PROGRESS_MONITOR); assertEquals(3, logs.length); assertEquals(logs[0].getRevision(), info2.getRevision()); } - - public void testConflicts () throws Exception { + + public void testConflicts() 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); + client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); + write(f, getDefaultBranch()); add(f); - GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR); + 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); - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); - - assertEquals(Constants.MASTER, read(f)); - + GitRevisionInfo branchInfo = client.commit(new File[]{f}, "change on branch", null, null, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); + + assertEquals(getDefaultBranch(), read(f)); + GitMergeResult result = client.merge(branchInfo.getRevision(), NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); - assertEquals("<<<<<<< HEAD\nmaster\n=======\nnew_branch\n>>>>>>> " + branchInfo.getRevision(), read(f)); + assertEquals("<<<<<<< HEAD\n" + getDefaultBranch() + "\n=======\nnew_branch\n>>>>>>> " + branchInfo.getRevision(), read(f)); assertNull(result.getNewHead()); assertEquals(Arrays.asList(f), result.getConflicts()); - + SearchCriteria crit = new SearchCriteria(); - crit.setRevisionTo(Constants.MASTER); + crit.setRevisionTo(getDefaultBranch()); GitRevisionInfo[] logs = client.log(crit, NULL_PROGRESS_MONITOR); assertEquals(2, logs.length); assertEquals(logs[0].getRevision(), masterInfo.getRevision()); - + // try merge with branch as revision - client.reset(Constants.MASTER, GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); + client.reset(getDefaultBranch(), GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); - assertEquals("<<<<<<< HEAD\nmaster\n=======\nnew_branch\n>>>>>>> " + BRANCH_NAME, read(f)); + assertEquals("<<<<<<< HEAD\n" + getDefaultBranch() + "\n=======\nnew_branch\n>>>>>>> " + BRANCH_NAME, read(f)); assertNull(result.getNewHead()); assertEquals(Arrays.asList(f), result.getConflicts()); // @TODO message checking is brittle //assertEquals("Merge new_branch\n\nConflicts:\n\tfile\n", repo.readMergeCommitMsg()); - + crit = new SearchCriteria(); - crit.setRevisionTo(Constants.MASTER); + crit.setRevisionTo(getDefaultBranch()); logs = client.log(crit, NULL_PROGRESS_MONITOR); assertEquals(2, logs.length); assertEquals(logs[0].getRevision(), masterInfo.getRevision()); - + // test obstructing paths - client.reset(Constants.MASTER, GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); + client.reset(getDefaultBranch(), GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); write(f, "local change"); result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.FAILED, result.getMergeStatus()); @@ -218,53 +217,53 @@ public void testConflicts () throws Exception { assertEquals(Arrays.asList(f), result.getFailures()); assertNull(repo.readMergeCommitMsg()); } - - public void testResolveConflicts () throws Exception { + + public void testResolveConflicts() throws Exception { File f = new File(workDir, "file"); - String[] contents = { "aaaaa\nbbbbb\nccccc", "xxxxx\nbbbbb\nccccc", "aaaaa\nbbbbb\nyyyyy", "xxxxx\nbbbbb\nyyyyy" }; + String[] contents = {"aaaaa\nbbbbb\nccccc", "xxxxx\nbbbbb\nccccc", "aaaaa\nbbbbb\nyyyyy", "xxxxx\nbbbbb\nyyyyy"}; write(f, contents[0]); add(f); commit(f); - + GitClient client = getClient(workDir); - client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR); + client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); write(f, contents[1]); add(f); - GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR); + GitRevisionInfo masterInfo = client.commit(new File[]{f}, "change on master", null, null, NULL_PROGRESS_MONITOR); client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); Thread.sleep(1100); write(f, contents[2]); add(f); - GitRevisionInfo branchInfo = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR); - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); - + GitRevisionInfo branchInfo = client.commit(new File[]{f}, "change on branch", null, null, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); + assertEquals(contents[1], read(f)); - + GitMergeResult result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.MERGED, result.getMergeStatus()); assertEquals(contents[3], read(f)); assertEquals(0, result.getConflicts().size()); - assertEquals(Arrays.asList(new String[] { masterInfo.getRevision(), branchInfo.getRevision() }), Arrays.asList(result.getMergedCommits())); - + assertEquals(Arrays.asList(new String[]{masterInfo.getRevision(), branchInfo.getRevision()}), Arrays.asList(result.getMergedCommits())); + SearchCriteria crit = new SearchCriteria(); - crit.setRevisionTo(Constants.MASTER); + crit.setRevisionTo(getDefaultBranch()); GitRevisionInfo[] logs = client.log(crit, NULL_PROGRESS_MONITOR); assertEquals(logs[0].getRevision(), result.getNewHead()); assertEquals(logs[1].getRevision(), branchInfo.getRevision()); assertEquals(logs[2].getRevision(), masterInfo.getRevision()); String logFileContent[] = read(new File(workDir, ".git/logs/HEAD")).split("\\n"); - assertEquals("merge new_branch: Merge made by recursive.", + assertEquals("merge new_branch: Merge made by recursive.", logFileContent[logFileContent.length - 1].substring(logFileContent[logFileContent.length - 1].indexOf("merge new_branch"))); - - client.reset("master~1", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); + + client.reset(getDefaultBranch() + "~1", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); result = client.merge(branchInfo.getRevision(), NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.MERGED, result.getMergeStatus()); assertEquals(contents[3], read(f)); assertEquals(0, result.getConflicts().size()); - assertEquals(Arrays.asList(new String[] { masterInfo.getRevision(), branchInfo.getRevision() }), Arrays.asList(result.getMergedCommits())); - + assertEquals(Arrays.asList(new String[]{masterInfo.getRevision(), branchInfo.getRevision()}), Arrays.asList(result.getMergedCommits())); + crit = new SearchCriteria(); - crit.setRevisionTo(Constants.MASTER); + crit.setRevisionTo(getDefaultBranch()); logs = client.log(crit, NULL_PROGRESS_MONITOR); assertEquals(logs[0].getRevision(), result.getNewHead()); assertEquals(logs[1].getRevision(), branchInfo.getRevision()); @@ -272,42 +271,42 @@ public void testResolveConflicts () throws Exception { logFileContent = read(new File(workDir, ".git/logs/HEAD")).split("\\n"); assertEquals("merge " + branchInfo.getRevision() + ": Merge made by recursive.", logFileContent[logFileContent.length - 1].substring(logFileContent[logFileContent.length - 1].indexOf("merge "))); } - - public void testMergeFailOnLocalChanges () throws Exception { + + 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 }; + File[] files = {f, f2}; add(files); commit(files); - + GitClient client = getClient(workDir); - client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR); + client.createBranch(BRANCH_NAME, getDefaultBranch(), 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); - + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); + assertEquals("init", read(f)); assertEquals("init", read(f2)); - - write(f, Constants.MASTER); - write(f2, Constants.MASTER); - + + write(f, getDefaultBranch()); + write(f2, getDefaultBranch()); + try { client.merge(branchInfo.getRevision(), NULL_PROGRESS_MONITOR); fail("Should fail"); } catch (GitException.CheckoutConflictException ex) { // OK - assertEquals(Arrays.asList(new String[] { f.getName(), f2.getName() }), Arrays.asList(ex.getConflicts())); + assertEquals(Arrays.asList(new String[]{f.getName(), f2.getName()}), Arrays.asList(ex.getConflicts())); } } - - public void testMergeBranchNoHeadYet_196837 () throws Exception { + + public void testMergeBranchNoHeadYet_196837() throws Exception { StoredConfig cfg = getRemoteRepository().getConfig(); cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_BARE, false); cfg.save(); @@ -315,160 +314,160 @@ public void testMergeBranchNoHeadYet_196837 () throws Exception { File original = new File(otherRepo, "f"); GitClient clientOtherRepo = getClient(otherRepo); write(original, "initial content"); - clientOtherRepo.add(new File[] { original }, NULL_PROGRESS_MONITOR); - clientOtherRepo.commit(new File[] { original }, "initial commit", null, null, NULL_PROGRESS_MONITOR); - + clientOtherRepo.add(new File[]{original}, NULL_PROGRESS_MONITOR); + clientOtherRepo.commit(new File[]{original}, "initial commit", null, null, NULL_PROGRESS_MONITOR); + GitClient client = getClient(workDir); - Map updates = client.fetch(otherRepo.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/master:refs/remotes/origin/master" }), NULL_PROGRESS_MONITOR); + Map updates = client.fetch(otherRepo.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/master:refs/remotes/origin/master"}), NULL_PROGRESS_MONITOR); GitMergeResult result = client.merge("origin/master", NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); - assertEquals(Arrays.asList(new String[] { ObjectId.zeroId().getName(), updates.get("origin/master").getNewObjectId() }), Arrays.asList(result.getMergedCommits())); + assertEquals(Arrays.asList(new String[]{ObjectId.zeroId().getName(), updates.get("origin/master").getNewObjectId()}), Arrays.asList(result.getMergedCommits())); } - - public void testMergeCrissCross_232904 () throws Exception { + + public void testMergeCrissCross_232904() throws Exception { File f1 = new File(workDir, "f1"); File f2 = new File(workDir, "f2"); File f3 = new File(workDir, "f3"); write(f1, "initial content"); GitClient client = getClient(workDir); - File[] files = new File[] { f1, f2, f3 }; + File[] files = new File[]{f1, f2, f3}; client.add(files, NULL_PROGRESS_MONITOR); client.commit(files, "initial commit", null, null, NULL_PROGRESS_MONITOR); - - client.createBranch(BRANCH_NAME, "master", NULL_PROGRESS_MONITOR); - + + client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); + // change on master - write(f1, Constants.MASTER); + write(f1, getDefaultBranch()); client.add(files, NULL_PROGRESS_MONITOR); client.commit(files, "master commit", null, null, NULL_PROGRESS_MONITOR); - GitRevisionInfo masterCommit = client.log("master", NULL_PROGRESS_MONITOR); - + GitRevisionInfo masterCommit = client.log(getDefaultBranch(), NULL_PROGRESS_MONITOR); + // change on branch client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); write(f2, BRANCH_NAME); client.add(files, NULL_PROGRESS_MONITOR); client.commit(files, "branch commit", null, null, NULL_PROGRESS_MONITOR); GitRevisionInfo branchCommit = client.log(BRANCH_NAME, NULL_PROGRESS_MONITOR); - + // merge last master commit (not merge) into branch client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); client.merge(masterCommit.getRevision(), NULL_PROGRESS_MONITOR); - + // merge last branch commit (not merge) into master - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); client.merge(branchCommit.getRevision(), NULL_PROGRESS_MONITOR); - - client.checkoutRevision(Constants.MASTER, true, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); } - - public void testMergeNoFastForward () throws Exception { + + 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.createBranch(BRANCH_NAME, getDefaultBranch(), 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); - + GitRevisionInfo info = client.commit(new File[]{f}, "change on branch", null, null, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); + assertEquals("init", read(f)); - + GitMergeResult result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals(BRANCH_NAME, read(f)); - + SearchCriteria crit = new SearchCriteria(); - crit.setRevisionTo(Constants.MASTER); + crit.setRevisionTo(getDefaultBranch()); GitRevisionInfo[] logs = client.log(crit, NULL_PROGRESS_MONITOR); assertEquals(2, logs.length); assertEquals(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); - + client.commit(new File[]{f}, "delete on branch", null, null, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); + assertEquals(BRANCH_NAME, read(f)); - + result = client.merge(BRANCH_NAME, GitRepository.FastForwardOption.NO_FAST_FORWARD, NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.MERGED, result.getMergeStatus()); assertFalse(f.exists()); - + crit = new SearchCriteria(); - crit.setRevisionTo(Constants.MASTER); + crit.setRevisionTo(getDefaultBranch()); logs = client.log(crit, NULL_PROGRESS_MONITOR); assertEquals(4, logs.length); assertEquals(2, logs[0].getParents().length); } - - public void testMergeFFOnly () throws Exception { + + 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.createBranch(BRANCH_NAME, getDefaultBranch(), 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); + client.commit(new File[]{f1}, "change on branch", null, null, NULL_PROGRESS_MONITOR); + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); write(f2, "another change"); add(f2); - client.commit(new File[] { f2 }, "change on master", null, null, NULL_PROGRESS_MONITOR); - + 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 assertEquals(MergeStatus.ABORTED, result.getMergeStatus()); - + // test also config files assertEquals(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); + ConfigConstants.CONFIG_KEY_FF, org.eclipse.jgit.api.MergeCommand.FastForwardMode.Merge.ONLY); cfg.save(); assertEquals(GitRepository.FastForwardOption.FAST_FORWARD_ONLY, GitRepository.getInstance(workDir).getDefaultFastForwardOption()); result = client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); // no merge commits allowed => FAIL assertEquals(MergeStatus.ABORTED, result.getMergeStatus()); - + result = client.merge(BRANCH_NAME, GitRepository.FastForwardOption.FAST_FORWARD, NULL_PROGRESS_MONITOR); // merge commits allowed => OK assertEquals(MergeStatus.MERGED, result.getMergeStatus()); } - - public void testMergeCommitFails250370 () throws Exception { + + 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.createBranch(BRANCH_NAME, getDefaultBranch(), 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); + client.commit(new File[]{f1}, "change on branch", null, null, NULL_PROGRESS_MONITOR); + + client.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); write(f2, "master"); add(f2); - client.commit(new File[] { f2 }, "change on master", null, null, NULL_PROGRESS_MONITOR); - + client.commit(new File[]{f2}, "change on master", null, null, NULL_PROGRESS_MONITOR); + try { client.merge(BRANCH_NAME, NULL_PROGRESS_MONITOR); fail(); @@ -477,5 +476,5 @@ public void testMergeCommitFails250370 () throws Exception { assertEquals(Utils.getBundle(MergeCommand.class).getString("MSG_MergeCommand.commitErr.wrongRepoState"), ex.getLocalizedMessage()); } } - + } diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/PullTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/PullTest.java index 2c5c34069998..b4fb0ad19910 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/PullTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/PullTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -25,7 +24,6 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Map; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.RemoteConfig; @@ -49,6 +47,7 @@ * @author ondra */ public class PullTest extends AbstractGitTestCase { + private Repository repository; private File workDir; private static final String BRANCH_NAME = "new_branch"; @@ -57,7 +56,7 @@ public class PullTest extends AbstractGitTestCase { private GitRevisionInfo masterInfo; private GitBranch branch; - public PullTest (String testName) throws IOException { + public PullTest(String testName) throws IOException { super(testName); } @@ -66,7 +65,7 @@ protected void setUp() throws Exception { super.setUp(); workDir = getWorkingDirectory(); repository = getRepository(getLocalGitRepository()); - + otherWT = new File(workDir.getParentFile(), "repo2"); GitClient client = getClient(otherWT); client.init(NULL_PROGRESS_MONITOR); @@ -74,26 +73,26 @@ protected void setUp() throws Exception { write(f, "init"); f2 = new File(otherWT, "f2"); write(f2, "init"); - client.add(new File[] { f, f2 }, NULL_PROGRESS_MONITOR); - masterInfo = client.commit(new File[] { f, f2 }, "init commit", null, null, NULL_PROGRESS_MONITOR); - branch = client.createBranch(BRANCH_NAME, Constants.MASTER, NULL_PROGRESS_MONITOR); + client.add(new File[]{f, f2}, NULL_PROGRESS_MONITOR); + masterInfo = client.commit(new File[]{f, f2}, "init commit", null, null, NULL_PROGRESS_MONITOR); + branch = client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); RemoteConfig cfg = new RemoteConfig(repository.getConfig(), "origin"); cfg.addURI(new URIish(otherWT.toURI().toURL().toString())); cfg.update(repository.getConfig()); repository.getConfig().save(); } - public void testPullNotExistingBranch () throws Exception { + public void testPullNotExistingBranch() throws Exception { GitClient client = getClient(workDir); try { - GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/idontexistbranch", NULL_PROGRESS_MONITOR); + GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/idontexistbranch", NULL_PROGRESS_MONITOR); fail("Must fail"); } catch (GitException.MissingObjectException ex) { // OK } } - public void testPullNoLocalHead () throws Exception { + public void testPullNoLocalHead() throws Exception { GitClient client = getClient(workDir); File f = new File(workDir, "local"); write(f, "aaa"); @@ -101,142 +100,142 @@ public void testPullNoLocalHead () throws Exception { Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(0, branches.size()); assertTrue(f.exists()); - GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR); + GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(3, branches.size()); - assertTrue(branches.get("origin/master").isRemote()); + assertTrue(branches.get("origin/" + getDefaultBranch()).isRemote()); assertTrue(branches.get("origin/" + BRANCH_NAME).isRemote()); assertEquals(branch.getId(), branches.get("origin/" + BRANCH_NAME).getId()); Map updates = result.getFetchResult(); assertEquals(2, updates.size()); - assertUpdate(updates.get("origin/master"), "origin/master", "master", masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); + assertUpdate(updates.get("origin/" + getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), masterInfo.getRevision(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); assertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, branch.getId(), null, new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.NEW); - + assertEquals(MergeStatus.FAST_FORWARD, result.getMergeResult().getMergeStatus()); - + // we should be on master branch - assertTrue(branches.get("master").isActive()); + assertTrue(branches.get(getDefaultBranch()).isActive()); // the old file should be deleted assertFalse(f.exists()); // and replaced with a new file assertTrue(new File(workDir, this.f.getName()).exists()); } - public void testPullIntoDetached () throws Exception { + public void testPullIntoDetached() 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); + client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); File f = new File(workDir, this.f.getName()); write(f, "blabla"); add(f); commit(f); - client.checkoutRevision("origin/master", true, NULL_PROGRESS_MONITOR); + client.checkoutRevision("origin/" + getDefaultBranch(), true, NULL_PROGRESS_MONITOR); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertTrue(branches.get(GitBranch.NO_BRANCH).isActive()); - - 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); + + String commitId = makeRemoteChange(getDefaultBranch()); + + GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(4, branches.size()); - assertTrue(branches.get("origin/master").isRemote()); - assertEquals(commitId, branches.get("origin/master").getId()); + assertTrue(branches.get("origin/" + getDefaultBranch()).isRemote()); + assertEquals(commitId, branches.get("origin/" + getDefaultBranch()).getId()); assertTrue(branches.get(GitBranch.NO_BRANCH).isActive()); assertEquals(commitId, branches.get(GitBranch.NO_BRANCH).getId()); Map updates = result.getFetchResult(); assertEquals(1, updates.size()); - assertUpdate(updates.get("origin/master"), "origin/master", "master", commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD); - + assertUpdate(updates.get("origin/" + getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD); + assertEquals(MergeStatus.FAST_FORWARD, result.getMergeResult().getMergeStatus()); assertEquals(commitId, result.getMergeResult().getNewHead()); } - public void testPullChangesInSameBranch () throws Exception { + public void testPullChangesInSameBranch() 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); + client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); Map 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); + + String commitId = makeRemoteChange(getDefaultBranch()); + + GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); - assertTrue(branches.get("master").isActive()); - assertEquals(commitId, branches.get("origin/master").getId()); - assertEquals(commitId, branches.get("master").getId()); + assertTrue(branches.get(getDefaultBranch()).isActive()); + assertEquals(commitId, branches.get("origin/" + getDefaultBranch()).getId()); + assertEquals(commitId, branches.get(getDefaultBranch()).getId()); Map updates = result.getFetchResult(); assertEquals(1, updates.size()); - assertUpdate(updates.get("origin/master"), "origin/master", "master", commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD); + assertUpdate(updates.get("origin/" + getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD); assertEquals(MergeStatus.FAST_FORWARD, result.getMergeResult().getMergeStatus()); assertEquals(commitId, result.getMergeResult().getNewHead()); } - public void testPullChangesInSameBranchPlusMerge () throws Exception { + 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); + client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), 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(); + String localCommitId = client.commit(new File[]{f2}, "local change", null, null, NULL_PROGRESS_MONITOR).getRevision(); Map 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); + + String commitId = makeRemoteChange(getDefaultBranch()); + + GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); - assertTrue(branches.get("master").isActive()); - assertEquals(commitId, branches.get("origin/master").getId()); - assertFalse(commitId.equals(branches.get("master").getId())); + assertTrue(branches.get(getDefaultBranch()).isActive()); + assertEquals(commitId, branches.get("origin/" + getDefaultBranch()).getId()); + assertFalse(commitId.equals(branches.get(getDefaultBranch()).getId())); Map updates = result.getFetchResult(); assertEquals(1, updates.size()); - assertUpdate(updates.get("origin/master"), "origin/master", "master", commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD); + assertUpdate(updates.get("origin/" + getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD); assertEquals(MergeStatus.MERGED, result.getMergeResult().getMergeStatus()); assertEquals(new HashSet(Arrays.asList(commitId, localCommitId)), new HashSet(Arrays.asList(result.getMergeResult().getMergedCommits()))); assertTrue(f.exists()); assertTrue(f2.exists()); } - public void testPullChangesMergeConflict () throws Exception { + public void testPullChangesMergeConflict() 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); + client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); File f = new File(workDir, this.f.getName()); write(f, "hi, i am new"); add(f); - client.commit(new File[] { f }, "local change", null, null, NULL_PROGRESS_MONITOR).getRevision(); + client.commit(new File[]{f}, "local change", null, null, NULL_PROGRESS_MONITOR).getRevision(); Map 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); + + String commitId = makeRemoteChange(getDefaultBranch()); + + GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); - assertTrue(branches.get("master").isActive()); - assertEquals(commitId, branches.get("origin/master").getId()); - assertFalse(commitId.equals(branches.get("master").getId())); + assertTrue(branches.get(getDefaultBranch()).isActive()); + assertEquals(commitId, branches.get("origin/" + getDefaultBranch()).getId()); + assertFalse(commitId.equals(branches.get(getDefaultBranch()).getId())); Map updates = result.getFetchResult(); assertEquals(1, updates.size()); - assertUpdate(updates.get("origin/master"), "origin/master", "master", commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD); + assertUpdate(updates.get("origin/" + getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), commitId, masterInfo.getRevision(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD); assertEquals(MergeStatus.CONFLICTING, result.getMergeResult().getMergeStatus()); assertEquals(new HashSet(Arrays.asList(f)), new HashSet(result.getMergeResult().getConflicts())); - assertEquals("<<<<<<< HEAD\nhi, i am new\n=======\nremote change\n>>>>>>> branch 'master' of " + new URIish(otherWT.toURI().toString()).toString(), read(f)); // this should be fixed in JGit + assertEquals("<<<<<<< HEAD\nhi, i am new\n=======\nremote change\n>>>>>>> branch '" + getDefaultBranch() + "' of " + new URIish(otherWT.toURI().toString()).toString(), read(f)); // this should be fixed in JGit } - public void testPullChangesInOtherBranchPlusMerge () throws Exception { + public void testPullChangesInOtherBranchPlusMerge() 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); + client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), 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(); + String localCommitId = client.commit(new File[]{f2}, "local change", null, null, NULL_PROGRESS_MONITOR).getRevision(); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); - + String commitId = makeRemoteChange(BRANCH_NAME); - - GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/" + BRANCH_NAME, NULL_PROGRESS_MONITOR); + + GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + BRANCH_NAME, NULL_PROGRESS_MONITOR); branches = client.getBranches(true, NULL_PROGRESS_MONITOR); - assertTrue(branches.get("master").isActive()); + assertTrue(branches.get(getDefaultBranch()).isActive()); assertEquals(commitId, branches.get("origin/" + BRANCH_NAME).getId()); - assertFalse(commitId.equals(branches.get("master").getId())); - assertFalse(localCommitId.equals(branches.get("master").getId())); + assertFalse(commitId.equals(branches.get(getDefaultBranch()).getId())); + assertFalse(localCommitId.equals(branches.get(getDefaultBranch()).getId())); Map updates = result.getFetchResult(); assertEquals(1, updates.size()); assertUpdate(updates.get("origin/" + BRANCH_NAME), "origin/" + BRANCH_NAME, BRANCH_NAME, commitId, branch.getId(), new URIish(otherWT.toURI().toURL()).toString(), Type.BRANCH, GitRefUpdateResult.FAST_FORWARD); @@ -246,49 +245,53 @@ public void testPullChangesInOtherBranchPlusMerge () throws Exception { assertTrue(f2.exists()); } - public void testPullFailOnLocalChanges () throws Exception { + public void testPullFailOnLocalChanges() 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); + client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); File f = new File(workDir, this.f.getName()); write(f, "local change"); add(f); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); - - makeRemoteChange("master"); + + makeRemoteChange(getDefaultBranch()); try { - GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR); + GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); fail("Should fail"); } catch (GitException.CheckoutConflictException ex) { // OK } - client.reset("master", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); + client.reset(getDefaultBranch(), GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); File f2 = new File(workDir, "f2"); write(f2, "hi, i am new"); add(f2); - GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR); + GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(MergeStatus.FAST_FORWARD, result.getMergeResult().getMergeStatus()); - assertStatus(client.getStatus(new File[] { f2 }, NULL_PROGRESS_MONITOR), workDir, f2, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); + assertStatus(client.getStatus(new File[]{f2}, NULL_PROGRESS_MONITOR), workDir, f2, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); } - public void testPullCommitMessages () throws Exception { + public void testPullCommitMessages() 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); + client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); File f = new File(workDir, "localFile"); - + makeLocalChange(f, "1"); - makeRemoteChange("master"); - GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR); + makeRemoteChange(getDefaultBranch()); + GitPullResult result = client.pull(otherWT.toURI().toString(), Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(GitMergeResult.MergeStatus.MERGED, result.getMergeResult().getMergeStatus()); - assertEquals("Merge branch 'master' of " + new URIish(otherWT.toURI().toString()).toString(), client.log(result.getMergeResult().getNewHead(), NULL_PROGRESS_MONITOR).getFullMessage()); - + // into branchname added on non default git config: test begining to the commit message only + String truncatedMessageChange1 = "Merge branch '" + getDefaultBranch() + "' of " + new URIish(otherWT.toURI().toString()).toString(); + assertEquals(truncatedMessageChange1, client.log(result.getMergeResult().getNewHead(), NULL_PROGRESS_MONITOR).getFullMessage().substring(0, truncatedMessageChange1.length())); + makeLocalChange(f, "2"); - makeRemoteChange("master", "2"); - result = client.pull("origin", Arrays.asList(new String[] { "+refs/heads/*:refs/remotes/origin/*" }), "origin/master", NULL_PROGRESS_MONITOR); + makeRemoteChange(getDefaultBranch(), "2"); + result = client.pull("origin", Arrays.asList(new String[]{"+refs/heads/*:refs/remotes/origin/*"}), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(GitMergeResult.MergeStatus.MERGED, result.getMergeResult().getMergeStatus()); - assertEquals("Merge branch 'master' of " + new URIish(otherWT.toURI().toString()).toString(), client.log(result.getMergeResult().getNewHead(), NULL_PROGRESS_MONITOR).getFullMessage()); + // into branchname added on non default git config: test begining to the commit message only + String truncatedMessageChange2 = "Merge branch '" + getDefaultBranch() + "' of " + new URIish(otherWT.toURI().toString()).toString(); + assertEquals(truncatedMessageChange2, client.log(result.getMergeResult().getNewHead(), NULL_PROGRESS_MONITOR).getFullMessage().substring(0, truncatedMessageChange2.length())); } - private void setupRemoteSpec (String remote, String fetchSpec) throws URISyntaxException, IOException { + private void setupRemoteSpec(String remote, String fetchSpec) throws URISyntaxException, IOException { RemoteConfig cfg = new RemoteConfig(repository.getConfig(), remote); cfg.addFetchRefSpec(new RefSpec(fetchSpec)); cfg.update(repository.getConfig()); @@ -305,23 +308,23 @@ private void assertUpdate(GitTransportUpdate update, String localName, String re assertEquals(result, update.getResult()); } - private String makeRemoteChange (String branch) throws Exception { + private String makeRemoteChange(String branch) throws Exception { return makeRemoteChange(branch, "remote change"); } - - private String makeRemoteChange (String branch, String content) throws Exception { + + private String makeRemoteChange(String branch, String content) throws Exception { GitClient client = getClient(otherWT); client.checkoutRevision(branch, true, NULL_PROGRESS_MONITOR); write(f, content); - File[] roots = new File[] { f }; + File[] roots = new File[]{f}; client.add(roots, NULL_PROGRESS_MONITOR); return client.commit(roots, "remote change", null, null, NULL_PROGRESS_MONITOR).getRevision(); } - private String makeLocalChange (File f, String content) throws Exception { + private String makeLocalChange(File f, String content) throws Exception { GitClient client = getClient(workDir); write(f, content); - File[] roots = new File[] { f }; + File[] roots = new File[]{f}; client.add(roots, NULL_PROGRESS_MONITOR); return client.commit(roots, "local change: " + content, null, null, NULL_PROGRESS_MONITOR).getRevision(); } diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/PushTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/PushTest.java index 3d61d138db76..8d485e227b23 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/PushTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/PushTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -48,6 +47,7 @@ * @author ondra */ public class PushTest extends AbstractGitTestCase { + private Repository repository; private File workDir; private File otherWT; @@ -55,7 +55,7 @@ public class PushTest extends AbstractGitTestCase { private GitRevisionInfo masterInfo; private GitBranch branch; - public PushTest (String testName) throws IOException { + public PushTest(String testName) throws IOException { super(testName); } @@ -65,102 +65,102 @@ protected void setUp() throws Exception { workDir = getWorkingDirectory(); repository = getRepository(getLocalGitRepository()); } - - public void testPushNewBranch () throws Exception { + + public void testPushNewBranch() throws Exception { String remoteUri = getRemoteRepository().getWorkTree().toURI().toString(); assertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size()); File f = new File(workDir, "f"); add(f); - String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); - Map updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + String id = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + Map updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); Map remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(1, remoteBranches.size()); - assertEquals(id, remoteBranches.get("master").getId()); + assertEquals(id, remoteBranches.get(getDefaultBranch()).getId()); assertEquals(1, updates.size()); - assertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); + assertUpdate(updates.get(getDefaultBranch()), getDefaultBranch(), getDefaultBranch(), id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); // adding another branch write(f, "huhu"); add(f); - String newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); - updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/anotherBranch" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + String newid = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/anotherBranch"}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(2, remoteBranches.size()); - assertEquals(id, remoteBranches.get("master").getId()); + assertEquals(id, remoteBranches.get(getDefaultBranch()).getId()); assertEquals(newid, remoteBranches.get("anotherBranch").getId()); - assertUpdate(updates.get("anotherBranch"), "master", "anotherBranch", newid, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); + assertUpdate(updates.get("anotherBranch"), getDefaultBranch(), "anotherBranch", newid, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); } - - public void testPushDeleteBranch () throws Exception { + + public void testPushDeleteBranch() throws Exception { String remoteUri = getRemoteRepository().getWorkTree().toURI().toString(); assertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size()); File f = new File(workDir, "f"); add(f); - String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); - Map updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master", "refs/heads/master:refs/heads/newbranch" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + String id = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + Map updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch(), "refs/heads/" + getDefaultBranch() + ":refs/heads/newbranch"}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); Map remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(2, remoteBranches.size()); - assertEquals(id, remoteBranches.get("master").getId()); + assertEquals(id, remoteBranches.get(getDefaultBranch()).getId()); assertEquals(2, updates.size()); - assertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); - assertUpdate(updates.get("newbranch"), "master", "newbranch", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); + assertUpdate(updates.get(getDefaultBranch()), getDefaultBranch(), getDefaultBranch(), id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); + assertUpdate(updates.get("newbranch"), getDefaultBranch(), "newbranch", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); // deleting branch - updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { ":refs/heads/newbranch" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{":refs/heads/newbranch"}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(1, remoteBranches.size()); - assertEquals(id, remoteBranches.get("master").getId()); + assertEquals(id, remoteBranches.get(getDefaultBranch()).getId()); assertUpdate(updates.get("newbranch"), null, "newbranch", null, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); } - - public void testPushChange () throws Exception { + + public void testPushChange() throws Exception { String remoteUri = getRemoteRepository().getWorkTree().toURI().toString(); assertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size()); File f = new File(workDir, "f"); add(f); - String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); - Map updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + String id = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + Map updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); Map remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(1, remoteBranches.size()); - assertEquals(id, remoteBranches.get("master").getId()); + assertEquals(id, remoteBranches.get(getDefaultBranch()).getId()); assertEquals(1, updates.size()); - assertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); + assertUpdate(updates.get(getDefaultBranch()), getDefaultBranch(), getDefaultBranch(), id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); // modification write(f, "huhu"); add(f); - String newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); - updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + String newid = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(1, remoteBranches.size()); - assertEquals(newid, remoteBranches.get("master").getId()); + assertEquals(newid, remoteBranches.get(getDefaultBranch()).getId()); assertEquals(1, updates.size()); - assertUpdate(updates.get("master"), "master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); + assertUpdate(updates.get(getDefaultBranch()), getDefaultBranch(), getDefaultBranch(), newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); } - - public void testPushUpdateInRemotes () throws Exception { + + public void testPushUpdateInRemotes() throws Exception { String remoteUri = getRemoteRepository().getWorkTree().toURI().toString(); assertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size()); File f = new File(workDir, "f"); add(f); - String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); - Map updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + String id = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + Map updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); Map remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(1, remoteBranches.size()); - assertEquals(id, remoteBranches.get("master").getId()); + assertEquals(id, remoteBranches.get(getDefaultBranch()).getId()); assertEquals(1, updates.size()); - assertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); - - getClient(workDir).pull(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/remotes/origin/master" }), "master", NULL_PROGRESS_MONITOR); + assertUpdate(updates.get(getDefaultBranch()), getDefaultBranch(), getDefaultBranch(), id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); + + getClient(workDir).pull(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch()}), getDefaultBranch(), NULL_PROGRESS_MONITOR); Map branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); - assertEquals(id, branches.get("origin/master").getId()); + assertEquals(id, branches.get("origin/" + getDefaultBranch()).getId()); // modification write(f, "huhu"); add(f); - String newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); - GitPushResult result = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.emptyList(), NULL_PROGRESS_MONITOR); + String newid = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + GitPushResult result = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()}), Collections.emptyList(), NULL_PROGRESS_MONITOR); updates = result.getRemoteRepositoryUpdates(); Map localUpdates = result.getLocalRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); @@ -168,48 +168,48 @@ public void testPushUpdateInRemotes () throws Exception { assertEquals(2, branches.size()); // not yet updated, tracking branches has not been set assertEquals(0, localUpdates.size()); - assertEquals(id, branches.get("origin/master").getId()); - + assertEquals(id, branches.get("origin/" + getDefaultBranch()).getId()); + // another modification write(f, "huhu2"); add(f); - newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); - result = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Arrays.asList(new String[] { "refs/heads/master:refs/remotes/origin/master" }), NULL_PROGRESS_MONITOR); + newid = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + result = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()}), Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch()}), NULL_PROGRESS_MONITOR); updates = result.getRemoteRepositoryUpdates(); localUpdates = result.getLocalRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); assertEquals(1, localUpdates.size()); - assertUpdate(localUpdates.get("master"), "origin/master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, EnumSet.of(GitRefUpdateResult.FAST_FORWARD, GitRefUpdateResult.FORCED)); - assertEquals(newid, branches.get("origin/master").getId()); - + assertUpdate(localUpdates.get(getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), newid, id, new URIish(remoteUri).toString(), Type.BRANCH, EnumSet.of(GitRefUpdateResult.FAST_FORWARD, GitRefUpdateResult.FORCED)); + assertEquals(newid, branches.get("origin/" + getDefaultBranch()).getId()); + //let's set tracking branch StoredConfig cfg = repository.getConfig(); cfg.setString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", ConfigConstants.CONFIG_KEY_URL, new URIish(remoteUri).toString()); - cfg.setString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "fetch", "+refs/heads/master:refs/remotes/origin/master"); - cfg.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE, "origin"); - cfg.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE, "refs/heads/master"); + cfg.setString(ConfigConstants.CONFIG_REMOTE_SECTION, "origin", "fetch", "+refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch()); + cfg.setString(ConfigConstants.CONFIG_BRANCH_SECTION, getDefaultBranch(), ConfigConstants.CONFIG_KEY_REMOTE, "origin"); + cfg.setString(ConfigConstants.CONFIG_BRANCH_SECTION, getDefaultBranch(), ConfigConstants.CONFIG_KEY_MERGE, "refs/heads/" + getDefaultBranch()); cfg.save(); - + // what about now??? write(f, "huhu3"); add(f); id = newid; - newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); - result = getClient(workDir).push("origin", Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.emptyList(), NULL_PROGRESS_MONITOR); + newid = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + result = getClient(workDir).push("origin", Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()}), Collections.emptyList(), NULL_PROGRESS_MONITOR); updates = result.getRemoteRepositoryUpdates(); localUpdates = result.getLocalRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); - assertUpdate(updates.get("master"), "master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); + assertUpdate(updates.get(getDefaultBranch()), getDefaultBranch(), getDefaultBranch(), newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); branches = getClient(workDir).getBranches(true, NULL_PROGRESS_MONITOR); assertEquals(2, branches.size()); assertEquals(1, localUpdates.size()); - assertUpdate(localUpdates.get("master"), "origin/master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, EnumSet.of(GitRefUpdateResult.FAST_FORWARD, GitRefUpdateResult.FORCED)); - assertEquals(newid, branches.get("origin/master").getId()); - + assertUpdate(localUpdates.get(getDefaultBranch()), "origin/" + getDefaultBranch(), getDefaultBranch(), newid, id, new URIish(remoteUri).toString(), Type.BRANCH, EnumSet.of(GitRefUpdateResult.FAST_FORWARD, GitRefUpdateResult.FORCED)); + assertEquals(newid, branches.get("origin/" + getDefaultBranch()).getId()); + // and what about adding a new branch, does it show among remotes? - result = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/newbranch" }), Arrays.asList(new String[] { "refs/heads/newbranch:refs/remotes/origin/newbranch" }), NULL_PROGRESS_MONITOR); + result = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/newbranch"}), Arrays.asList(new String[]{"refs/heads/newbranch:refs/remotes/origin/newbranch"}), NULL_PROGRESS_MONITOR); updates = result.getRemoteRepositoryUpdates(); localUpdates = result.getLocalRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); @@ -220,49 +220,49 @@ public void testPushUpdateInRemotes () throws Exception { assertUpdate(localUpdates.get("newbranch"), "origin/newbranch", "newbranch", newid, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.NEW); assertEquals(newid, branches.get("origin/newbranch").getId()); } - - public void testPushRejectNonFastForward () throws Exception { + + public void testPushRejectNonFastForward() throws Exception { String remoteUri = getRemoteRepository().getWorkTree().toURI().toString(); assertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size()); File f = new File(workDir, "f"); add(f); - String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); - Map updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + String id = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + Map updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); Map remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(1, remoteBranches.size()); - assertEquals(id, remoteBranches.get("master").getId()); + assertEquals(id, remoteBranches.get(getDefaultBranch()).getId()); assertEquals(1, updates.size()); - assertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); + assertUpdate(updates.get(getDefaultBranch()), getDefaultBranch(), getDefaultBranch(), id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); // modification write(f, "huhu"); add(f); - String newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); - updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + String newid = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(1, remoteBranches.size()); - assertEquals(newid, remoteBranches.get("master").getId()); + assertEquals(newid, remoteBranches.get(getDefaultBranch()).getId()); assertEquals(1, updates.size()); - assertUpdate(updates.get("master"), "master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); - + assertUpdate(updates.get(getDefaultBranch()), getDefaultBranch(), getDefaultBranch(), newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); + getClient(workDir).createBranch("localbranch", id, NULL_PROGRESS_MONITOR); getClient(workDir).checkoutRevision("localbranch", true, NULL_PROGRESS_MONITOR); write(f, "huhu2"); add(f); - id = getClient(workDir).commit(new File[] { f }, "some change before merge", null, null, NULL_PROGRESS_MONITOR).getRevision(); - updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/localbranch:refs/heads/master" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + id = getClient(workDir).commit(new File[]{f}, "some change before merge", null, null, NULL_PROGRESS_MONITOR).getRevision(); + updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/localbranch:refs/heads/" + getDefaultBranch()}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(1, remoteBranches.size()); - assertEquals(newid, remoteBranches.get("master").getId()); + assertEquals(newid, remoteBranches.get(getDefaultBranch()).getId()); assertEquals(1, updates.size()); - assertUpdate(updates.get("master"), "localbranch", "master", id, newid, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.REJECTED_NONFASTFORWARD); - - updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/localbranch:refs/heads/master" }), Arrays.asList(new String[] { "+refs/heads/master:refs/remotes/origin/master" }), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + assertUpdate(updates.get(getDefaultBranch()), "localbranch", getDefaultBranch(), id, newid, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.REJECTED_NONFASTFORWARD); + + updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/localbranch:refs/heads/" + getDefaultBranch()}), Arrays.asList(new String[]{"+refs/heads/master:refs/remotes/origin/master"}), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); remoteBranches = getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(1, remoteBranches.size()); - assertEquals(newid, remoteBranches.get("master").getId()); + assertEquals(newid, remoteBranches.get(getDefaultBranch()).getId()); assertEquals(1, updates.size()); - assertUpdate(updates.get("master"), "localbranch", "master", id, newid, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.REJECTED_NONFASTFORWARD); + assertUpdate(updates.get(getDefaultBranch()), "localbranch", getDefaultBranch(), id, newid, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.REJECTED_NONFASTFORWARD); // if starts failing, the WA at GitTransportUpdate.(URIish uri, TrackingRefUpdate update) should be removed // this.result = GitRefUpdateResult.valueOf((update.getResult() == null ? RefUpdate.Result.NOT_ATTEMPTED : update.getResult()).name()); @@ -271,8 +271,8 @@ public void testPushRejectNonFastForward () throws Exception { transport.setPushThin(true); PushResult pushResult = transport.push(new DelegatingProgressMonitor(NULL_PROGRESS_MONITOR), Transport.findRemoteRefUpdatesFor(getRepository(getClient(workDir)), - Collections.singletonList(new RefSpec("refs/heads/localbranch:refs/heads/master")), - Collections.singletonList(new RefSpec("refs/heads/master:refs/remotes/origin/master")))); + Collections.singletonList(new RefSpec("refs/heads/localbranch:refs/heads/" + getDefaultBranch())), + Collections.singletonList(new RefSpec("refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch())))); assertEquals(1, pushResult.getTrackingRefUpdates().size()); for (TrackingRefUpdate update : pushResult.getTrackingRefUpdates()) { // null but not NOT_ATTEMPTED, probably a bug @@ -281,46 +281,45 @@ public void testPushRejectNonFastForward () throws Exception { } } - public void testPushTag () throws Exception { + public void testPushTag() throws Exception { String remoteUri = getRemoteRepository().getWorkTree().toURI().toString(); assertEquals(0, getClient(workDir).listRemoteBranches(remoteUri, NULL_PROGRESS_MONITOR).size()); File f = new File(workDir, "f"); add(f); - String id = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + String id = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); GitTag tag = getClient(workDir).createTag("my-tag", id, "tag message", false, false, NULL_PROGRESS_MONITOR); - Map updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master", "refs/tags/my-tag:refs/tags/my-tag" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + Map updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch(), "refs/tags/my-tag:refs/tags/my-tag"}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); Map remoteTags = getClient(workDir).listRemoteTags(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(1, remoteTags.size()); assertEquals(tag.getTagId(), remoteTags.get("my-tag")); assertEquals(2, updates.size()); - assertUpdate(updates.get("master"), "master", "master", id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); + assertUpdate(updates.get(getDefaultBranch()), getDefaultBranch(), getDefaultBranch(), id, null, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); assertUpdate(updates.get("my-tag"), "my-tag", "my-tag", tag.getTagId(), null, new URIish(remoteUri).toString(), Type.TAG, GitRefUpdateResult.OK); - + // modification, updating tag fails when not force update write(f, "huhu"); add(f); - String newid = getClient(workDir).commit(new File[] { f }, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); + String newid = getClient(workDir).commit(new File[]{f}, "bbb", null, null, NULL_PROGRESS_MONITOR).getRevision(); GitTag newTag = getClient(workDir).createTag("my-tag", newid, "tag message", false, true, NULL_PROGRESS_MONITOR); - updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "refs/heads/master:refs/heads/master", "refs/tags/my-tag:refs/tags/my-tag" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch(), "refs/tags/my-tag:refs/tags/my-tag"}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); remoteTags = getClient(workDir).listRemoteTags(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(tag.getTagId(), remoteTags.get("my-tag")); assertEquals(2, updates.size()); - assertUpdate(updates.get("master"), "master", "master", newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); + assertUpdate(updates.get(getDefaultBranch()), getDefaultBranch(), getDefaultBranch(), newid, id, new URIish(remoteUri).toString(), Type.BRANCH, GitRefUpdateResult.OK); // @TODO // assertUpdate(updates.get("my-tag"), "my-tag", "my-tag", newTag.getTagId(), null, new URIish(remoteUri).toString(), Type.TAG, GitRefUpdateResult.REJECTED_NONFASTFORWARD); - // modification, updating tag now works write(f, "huhu"); add(f); - updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[] { "+refs/tags/my-tag:refs/tags/my-tag" }), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); + updates = getClient(workDir).push(remoteUri, Arrays.asList(new String[]{"+refs/tags/my-tag:refs/tags/my-tag"}), Collections.emptyList(), NULL_PROGRESS_MONITOR).getRemoteRepositoryUpdates(); remoteTags = getClient(workDir).listRemoteTags(remoteUri, NULL_PROGRESS_MONITOR); assertEquals(newTag.getTagId(), remoteTags.get("my-tag")); assertEquals(1, updates.size()); // @TODO // assertUpdate(updates.get("my-tag"), "my-tag", "my-tag", newTag.getTagId(), null, new URIish(remoteUri).toString(), Type.TAG, GitRefUpdateResult.OK); -} + } private void assertUpdate(GitTransportUpdate update, String localName, String remoteName, String newObjectId, String oldObjectId, String remoteUri, Type type, GitRefUpdateResult result) { assertUpdate(update, localName, remoteName, newObjectId, oldObjectId, remoteUri, type, EnumSet.of(result)); diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/RebaseTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/RebaseTest.java index d9650925fbc2..65acd3e4ead1 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/RebaseTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/RebaseTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -40,11 +39,12 @@ * @author ondra */ public class RebaseTest extends AbstractGitTestCase { + private File workDir; private static final String BRANCH_NAME = "new_branch"; private Repository repo; - public RebaseTest (String testName) throws IOException { + public RebaseTest(String testName) throws IOException { super(testName); } @@ -54,72 +54,72 @@ protected void setUp() throws Exception { workDir = getWorkingDirectory(); repo = getRepository(getLocalGitRepository()); } - - public void testRebaseOperationMapping () { + + public void testRebaseOperationMapping() { for (RebaseOperationType operation : RebaseOperationType.values()) { assertNotNull(RebaseCommand.getOperation(operation)); } } - public void testRebaseNoChange () throws Exception { + 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); + GitBranch branch = client.createBranch(BRANCH_NAME, getDefaultBranch(), 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); + GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.UP_TO_DATE, result.getRebaseStatus()); assertEquals(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); - + 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); + result = client.rebase(RebaseOperationType.BEGIN, getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.UP_TO_DATE, result.getRebaseStatus()); assertEquals(commit.getRevision(), result.getCurrentHead()); } - - public void testRebaseSimple () throws Exception { + + 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); + write(f2, getDefaultBranch()); 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); - + GitRevisionInfo master = client.commit(new File[]{f2}, "change on master", null, null, NULL_PROGRESS_MONITOR); + client.createBranch(BRANCH_NAME, getDefaultBranch() + "^1", NULL_PROGRESS_MONITOR); + client.checkoutRevision(BRANCH_NAME, true, NULL_PROGRESS_MONITOR); assertFalse(f2.exists()); write(f, BRANCH_NAME); add(f); - GitRevisionInfo info = client.commit(new File[] { f }, "change on branch", null, null, NULL_PROGRESS_MONITOR); + 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); - + 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); + + GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.OK, result.getRebaseStatus()); assertEquals("another change", read(f)); - assertEquals(Constants.MASTER, read(f2)); - + assertEquals(getDefaultBranch(), read(f2)); + SearchCriteria crit = new SearchCriteria(); - crit.setRevisionFrom(Constants.MASTER); + crit.setRevisionFrom(getDefaultBranch()); crit.setRevisionTo(result.getCurrentHead()); GitRevisionInfo[] logs = client.log(crit, NULL_PROGRESS_MONITOR); assertEquals(3, logs.length); @@ -129,228 +129,228 @@ public void testRebaseSimple () throws Exception { assertEquals(info.getCommitTime(), logs[1].getCommitTime()); assertEquals(master.getRevision(), logs[2].getRevision()); } - - public void testConflicts () throws Exception { + + 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); + client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); + write(f, getDefaultBranch()); add(f); - GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR); + 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); + GitRevisionInfo branchInfo = client.commit(new File[]{f, f2}, "change on branch", null, null, NULL_PROGRESS_MONITOR); + + GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.STOPPED, result.getRebaseStatus()); - assertEquals("<<<<<<< Upstream, based on master\nmaster\n=======\nnew_branch\n>>>>>>> " + assertEquals("<<<<<<< Upstream, based on " + getDefaultBranch() + "\n" + getDefaultBranch() + "\n=======\nnew_branch\n>>>>>>> " + branchInfo.getRevision().substring(0, 7) + " " + branchInfo.getShortMessage(), read(f)); assertEquals(Arrays.asList(f), result.getConflicts()); - Map statuses = client.getStatus(new File[] { f, f2 }, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{f, f2}, NULL_PROGRESS_MONITOR); assertTrue(statuses.get(f).isConflict()); assertStatus(statuses, workDir, f2, true, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, false); assertEquals(branchInfo.getRevision(), result.getCurrentCommit()); assertEquals(masterInfo.getRevision(), result.getCurrentHead()); } - - public void testRebaseAbort () throws Exception { + + 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); + client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); + write(f, getDefaultBranch()); add(f); - GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR); + 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); + GitRevisionInfo branchInfo = client.commit(new File[]{f}, "change on branch", null, null, NULL_PROGRESS_MONITOR); + + GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.STOPPED, result.getRebaseStatus()); assertEquals(Arrays.asList(f), result.getConflicts()); assertEquals(branchInfo.getRevision(), result.getCurrentCommit()); assertEquals(masterInfo.getRevision(), result.getCurrentHead()); - + result = client.rebase(RebaseOperationType.ABORT, null, NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.ABORTED, result.getRebaseStatus()); assertTrue(result.getConflicts().isEmpty()); // resets to original state assertEquals(branchInfo.getRevision(), result.getCurrentHead()); assertEquals(branchInfo.getRevision(), getRepository(client).resolve(BRANCH_NAME).name()); - assertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name()); + assertEquals(masterInfo.getRevision(), getRepository(client).resolve(getDefaultBranch()).name()); } - - public void testRebaseSkip () throws Exception { + + 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); + client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); + write(f, getDefaultBranch()); add(f); - GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR); + 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); + GitRevisionInfo branchInfo = client.commit(new File[]{f}, "change on branch", null, null, NULL_PROGRESS_MONITOR); + + GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.STOPPED, result.getRebaseStatus()); assertEquals(Arrays.asList(f), result.getConflicts()); assertEquals(branchInfo.getRevision(), result.getCurrentCommit()); assertEquals(masterInfo.getRevision(), result.getCurrentHead()); - + result = client.rebase(RebaseOperationType.SKIP, null, NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.OK, result.getRebaseStatus()); assertTrue(result.getConflicts().isEmpty()); assertEquals(masterInfo.getRevision(), result.getCurrentHead()); assertEquals(masterInfo.getRevision(), getRepository(client).resolve(BRANCH_NAME).name()); - assertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name()); + assertEquals(masterInfo.getRevision(), getRepository(client).resolve(getDefaultBranch()).name()); } - - public void testResolveConflictsNoCommit () throws Exception { + + 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); + client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); + write(f, getDefaultBranch()); add(f); - GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR); + 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); + GitRevisionInfo branchInfo = client.commit(new File[]{f}, "change on branch", null, null, NULL_PROGRESS_MONITOR); + + GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.STOPPED, result.getRebaseStatus()); - assertEquals("<<<<<<< Upstream, based on master\nmaster\n=======\nnew_branch\n>>>>>>> " + assertEquals("<<<<<<< Upstream, based on " + getDefaultBranch() + "\n" + getDefaultBranch() + "\n=======\nnew_branch\n>>>>>>> " + branchInfo.getRevision().substring(0, 7) + " " + branchInfo.getShortMessage(), read(f)); assertEquals(Arrays.asList(f), result.getConflicts()); - Map statuses = client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{f}, NULL_PROGRESS_MONITOR); assertTrue(statuses.get(f).isConflict()); assertEquals(branchInfo.getRevision(), result.getCurrentCommit()); assertEquals(masterInfo.getRevision(), result.getCurrentHead()); - write(f, Constants.MASTER); + write(f, getDefaultBranch()); add(f); - + result = client.rebase(RebaseOperationType.CONTINUE, null, NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.NOTHING_TO_COMMIT, result.getRebaseStatus()); assertTrue(result.getConflicts().isEmpty()); assertEquals(masterInfo.getRevision(), result.getCurrentHead()); assertEquals(branchInfo.getRevision(), getRepository(client).resolve(BRANCH_NAME).name()); - assertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name()); - + assertEquals(masterInfo.getRevision(), getRepository(client).resolve(getDefaultBranch()).name()); + // still have to finish rebase result = client.rebase(RebaseOperationType.SKIP, null, NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.OK, result.getRebaseStatus()); assertTrue(result.getConflicts().isEmpty()); assertEquals(masterInfo.getRevision(), result.getCurrentHead()); assertEquals(masterInfo.getRevision(), getRepository(client).resolve(BRANCH_NAME).name()); - assertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name()); + assertEquals(masterInfo.getRevision(), getRepository(client).resolve(getDefaultBranch()).name()); } - - public void testResolveConflicts () throws Exception { + + 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); + client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); + write(f, getDefaultBranch()); add(f); - GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR); + 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); + GitRevisionInfo branchInfo = client.commit(new File[]{f}, "change on branch", null, null, NULL_PROGRESS_MONITOR); + + GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.STOPPED, result.getRebaseStatus()); assertEquals(Arrays.asList(f), result.getConflicts()); assertEquals(branchInfo.getRevision(), result.getCurrentCommit()); assertEquals(masterInfo.getRevision(), result.getCurrentHead()); - + write(f, "resolving conflict"); add(f); - + result = client.rebase(RebaseOperationType.CONTINUE, null, NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.OK, result.getRebaseStatus()); assertEquals(getRepository(client).resolve(Constants.HEAD).name(), result.getCurrentHead()); assertEquals(getRepository(client).resolve(Constants.HEAD).name(), getRepository(client).resolve(BRANCH_NAME).name()); - assertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name()); + assertEquals(masterInfo.getRevision(), getRepository(client).resolve(getDefaultBranch()).name()); } - - public void testRebaseFailCheckoutLocalChanges () throws Exception { + + 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); + client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); + write(f, getDefaultBranch()); add(f); - GitRevisionInfo masterInfo = client.commit(new File[] { f }, "change on master", null, null, NULL_PROGRESS_MONITOR); + 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); - + 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); + + GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.FAILED, result.getRebaseStatus()); assertEquals(Arrays.asList(f), result.getFailures()); assertEquals(branchInfo.getRevision(), getRepository(client).resolve(BRANCH_NAME).name()); - assertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name()); + assertEquals(masterInfo.getRevision(), getRepository(client).resolve(getDefaultBranch()).name()); // resets HEAD assertEquals(branchInfo.getRevision(), getRepository(client).resolve(Constants.HEAD).name()); } - - public void testRebaseFailMergeLocalChanges () throws Exception { + + 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); + client.createBranch(BRANCH_NAME, getDefaultBranch(), NULL_PROGRESS_MONITOR); + write(f, getDefaultBranch()); add(f); - GitRevisionInfo masterInfo = client.commit(new File[] { f, f2 }, "change on master", null, null, NULL_PROGRESS_MONITOR); + 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); - + 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); + + GitRebaseResult result = client.rebase(RebaseOperationType.BEGIN, getDefaultBranch(), NULL_PROGRESS_MONITOR); assertEquals(RebaseStatus.FAILED, result.getRebaseStatus()); assertEquals(Arrays.asList(f2), result.getFailures()); assertEquals(branchInfo.getRevision(), getRepository(client).resolve(BRANCH_NAME).name()); - assertEquals(masterInfo.getRevision(), getRepository(client).resolve(Constants.MASTER).name()); + assertEquals(masterInfo.getRevision(), getRepository(client).resolve(getDefaultBranch()).name()); // resets HEAD assertEquals(branchInfo.getRevision(), getRepository(client).resolve(Constants.HEAD).name()); } diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/RemotesTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/RemotesTest.java index 9acdc1fadc66..4790f69a5f56 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/RemotesTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/RemotesTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -38,63 +37,64 @@ * @author ondra */ public class RemotesTest extends AbstractGitTestCase { + private Repository repository; private File workDir; - - public RemotesTest (String name) throws IOException { + + public RemotesTest(String name) throws IOException { super(name); } - + @Override protected void setUp() throws Exception { super.setUp(); workDir = getWorkingDirectory(); repository = getRepository(getLocalGitRepository()); } - - public void testRemoveRemote () throws Exception { + + 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); - + 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); - + client.createBranch(getDefaultBranch(), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); + client.createBranch("nova", "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); + StoredConfig config = repository.getConfig(); assertEquals("+refs/heads/*:refs/remotes/origin/*", config.getString("remote", "origin", "fetch")); - assertEquals("origin", config.getString("branch", "master", "remote")); - assertEquals("refs/heads/master", config.getString("branch", "master", "merge")); + assertEquals("origin", config.getString("branch", getDefaultBranch(), "remote")); + assertEquals("refs/heads/" + getDefaultBranch(), config.getString("branch", getDefaultBranch(), "merge")); assertEquals("origin", config.getString("branch", "nova", "remote")); - assertEquals("refs/heads/master", config.getString("branch", "nova", "merge")); - + assertEquals("refs/heads/" + getDefaultBranch(), 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? assertEquals(0, config.getSubsections("remote").size()); - assertNull(config.getString("branch", "master", "remote")); - assertNull(config.getString("branch", "master", "merge")); + assertNull(config.getString("branch", getDefaultBranch(), "remote")); + assertNull(config.getString("branch", getDefaultBranch(), "merge")); assertNull(config.getString("branch", "nova", "remote")); assertNull(config.getString("branch", "nova", "merge")); } - - public void testAddRemote () throws Exception { + + public void testAddRemote() throws Exception { StoredConfig config = repository.getConfig(); assertEquals(0, config.getSubsections("remote").size()); - + GitClient client = getClient(workDir); GitRemoteConfig remoteConfig = new GitRemoteConfig("origin", Arrays.asList(new File(workDir.getParentFile(), "repo2").toURI().toString()), @@ -102,7 +102,7 @@ public void testAddRemote () throws Exception { Arrays.asList("+refs/heads/*:refs/remotes/origin/*"), Arrays.asList("refs/remotes/origin/*:+refs/heads/*")); client.setRemote(remoteConfig, NULL_PROGRESS_MONITOR); - + config.load(); RemoteConfig cfg = new RemoteConfig(config, "origin"); assertEquals(Arrays.asList(new URIish(new File(workDir.getParentFile(), "repo2").toURI().toString())), cfg.getURIs()); @@ -110,8 +110,8 @@ public void testAddRemote () throws Exception { assertEquals(Arrays.asList(new RefSpec("+refs/heads/*:refs/remotes/origin/*")), cfg.getFetchRefSpecs()); assertEquals(Arrays.asList(new RefSpec("refs/remotes/origin/*:+refs/heads/*")), cfg.getPushRefSpecs()); } - - public void testUpdateRemote () throws Exception { + + public void testUpdateRemote() throws Exception { StoredConfig config = repository.getConfig(); RemoteConfig cfg = new RemoteConfig(config, "origin"); cfg.addURI(new URIish("blablabla")); @@ -119,8 +119,8 @@ public void testUpdateRemote () throws Exception { cfg.update(config); config.save(); config.load(); - assertEquals(1, config.getSubsections("remote").size()); - + assertEquals(1, config.getSubsections("remote").size()); + GitClient client = getClient(workDir); GitRemoteConfig remoteConfig = new GitRemoteConfig("origin", Arrays.asList(new File(workDir.getParentFile(), "repo2").toURI().toString()), @@ -128,7 +128,7 @@ public void testUpdateRemote () throws Exception { Arrays.asList("+refs/heads/*:refs/remotes/origin/*"), Arrays.asList("refs/remotes/origin/*:+refs/heads/*")); client.setRemote(remoteConfig, NULL_PROGRESS_MONITOR); - + config.load(); cfg = new RemoteConfig(config, "origin"); assertEquals(Arrays.asList(new URIish(new File(workDir.getParentFile(), "repo2").toURI().toString())), cfg.getURIs()); @@ -136,8 +136,8 @@ public void testUpdateRemote () throws Exception { assertEquals(Arrays.asList(new RefSpec("+refs/heads/*:refs/remotes/origin/*")), cfg.getFetchRefSpecs()); assertEquals(Arrays.asList(new RefSpec("refs/remotes/origin/*:+refs/heads/*")), cfg.getPushRefSpecs()); } - - public void testUpdateRemoteRollback () throws Exception { + + public void testUpdateRemoteRollback() throws Exception { StoredConfig config = repository.getConfig(); RemoteConfig cfg = new RemoteConfig(config, "origin"); cfg.addURI(new URIish("blablabla")); @@ -145,8 +145,8 @@ public void testUpdateRemoteRollback () throws Exception { cfg.update(config); config.save(); config.load(); - assertEquals(1, config.getSubsections("remote").size()); - + assertEquals(1, config.getSubsections("remote").size()); + GitClient client = getClient(workDir); GitRemoteConfig remoteConfig = new GitRemoteConfig("origin", Arrays.asList(new File(workDir.getParentFile(), "repo2").toURI().toString()), @@ -157,7 +157,7 @@ public void testUpdateRemoteRollback () throws Exception { try { client.setRemote(remoteConfig, NULL_PROGRESS_MONITOR); } catch (GitException ex) { - + } cfg = new RemoteConfig(config, "origin"); assertEquals(Arrays.asList(new URIish("blablabla")), cfg.getURIs()); diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/ResetTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/ResetTest.java index d04ab2b5f319..d2f599229dae 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/ResetTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/ResetTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -50,7 +49,7 @@ public class ResetTest extends AbstractGitTestCase { private File workDir; private Repository repository; - public ResetTest (String testName) throws IOException { + public ResetTest(String testName) throws IOException { super(testName); } @@ -61,17 +60,17 @@ protected void setUp() throws Exception { repository = getRepository(getLocalGitRepository()); } - public void testResetSoft () throws Exception { + public void testResetSoft() throws Exception { File file1 = new File(workDir, "file1"); write(file1, "blablablabla"); File file2 = new File(workDir, "file2"); write(file2, "blablablabla in file2"); - File[] files = new File[] { file1, file2 }; + File[] files = new File[]{file1, file2}; add(files); commit(files); GitClient client = getClient(workDir); - Map statuses = client.getStatus(files,NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, file1, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); @@ -92,17 +91,17 @@ public void testResetSoft () throws Exception { assertStatus(statuses, workDir, file2, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); } - public void testResetMixed () throws Exception { + public void testResetMixed() throws Exception { File file1 = new File(workDir, "file1"); write(file1, "blablablabla"); File file2 = new File(workDir, "file2"); write(file2, "blablablabla in file2"); - File[] files = new File[] { file1, file2 }; + File[] files = new File[]{file1, file2}; add(files); commit(files); GitClient client = getClient(workDir); - Map statuses = client.getStatus(files,NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, file1, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); @@ -123,17 +122,17 @@ public void testResetMixed () throws Exception { assertStatus(statuses, workDir, file2, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); } - public void testResetHard () throws Exception { + public void testResetHard() throws Exception { File file1 = new File(workDir, "file1"); write(file1, "blablablabla"); File file2 = new File(workDir, "file2"); write(file2, "blablablabla in file2"); - File[] files = new File[] { file1, file2 }; + File[] files = new File[]{file1, file2}; add(files); commit(files); GitClient client = getClient(workDir); - Map statuses = client.getStatus(files,NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, file1, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); @@ -157,16 +156,16 @@ public void testResetHard () throws Exception { assertStatus(statuses, workDir, file2, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); } - public void testResetHardTypeConflict () throws Exception { + public void testResetHardTypeConflict() throws Exception { File file1 = new File(workDir, "file1"); write(file1, "blablablabla"); File file2 = new File(file1, "f"); - File[] files = new File[] { file1, file2 }; + File[] files = new File[]{file1, file2}; add(files); commit(files); GitClient client = getClient(workDir); - Map statuses = client.getStatus(files,NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, workDir, file1, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); client.remove(files, false, NULL_PROGRESS_MONITOR); @@ -198,15 +197,15 @@ public void testResetHardTypeConflict () throws Exception { assertTrue(file1.isDirectory()); } - public void testResetHardOverwritesModification () throws Exception { + public void testResetHardOverwritesModification() throws Exception { File file1 = new File(workDir, "file1"); write(file1, "blablablabla"); - File[] files = new File[] { file1 }; + File[] files = new File[]{file1}; add(files); commit(files); GitClient client = getClient(workDir); - Map statuses = client.getStatus(files,NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, workDir, file1, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); write(file1, "change in content"); @@ -227,18 +226,18 @@ public void testResetHardOverwritesModification () throws Exception { assertEquals("blablablabla", read(file1)); } - public void testResetHardRemoveFile () throws Exception { + public void testResetHardRemoveFile() throws Exception { File file1 = new File(workDir, "file1"); write(file1, "blablablabla"); File file2 = new File(workDir, "file2"); write(file2, "blablablabla"); - File[] files = new File[] { file1 }; + File[] files = new File[]{file1}; add(files); commit(files); GitClient client = getClient(workDir); add(file2); - files = new File[] { file1, file2 }; + files = new File[]{file1, file2}; commit(files); Iterator logs = new Git(repository).log().call().iterator(); @@ -255,7 +254,7 @@ public void testResetHardRemoveFile () throws Exception { assertFalse(file2.exists()); } - public void testResetPaths () throws Exception { + public void testResetPaths() throws Exception { File file1 = new File(workDir, "file1"); // index entry will be modified write(file1, "blablablabla"); File file2 = new File(workDir, "file2"); // index entry will be left alone @@ -263,7 +262,7 @@ public void testResetPaths () throws Exception { File file3 = new File(workDir, "file3"); // index entry will be added write(file3, "blablablabla in file3"); File file4 = new File(workDir, "file4"); // index entry will be removed - File[] files = new File[] { file1, file2, file3, file4 }; + File[] files = new File[]{file1, file2, file3, file4}; add(files); commit(files); @@ -280,21 +279,20 @@ public void testResetPaths () throws Exception { client.add(files, NULL_PROGRESS_MONITOR); commit(files); write(file2, "change in content in file 2"); - client.add(new File[] { file2 }, NULL_PROGRESS_MONITOR); - client.remove(new File[] { file3 }, false,NULL_PROGRESS_MONITOR); + client.add(new File[]{file2}, NULL_PROGRESS_MONITOR); + client.remove(new File[]{file3}, false, NULL_PROGRESS_MONITOR); LogCommand cmd = new Git(repository).log(); Iterator logs = cmd.call().iterator(); logs.next(); RevCommit commit = logs.next(); String revision = commit.getId().getName(); - client.reset(new File[] { file1, file3, file4 }, revision, true, NULL_PROGRESS_MONITOR); + client.reset(new File[]{file1, file3, file4}, revision, true, NULL_PROGRESS_MONITOR); // file1: modified HEAD-INDEX // file2: stays modified HEAD-INDEX // file3: removed in WT, normal HEAD-INDEX // file4: removed in index, normal in WT - statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(4, statuses.size()); assertStatus(statuses, workDir, file1, true, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, false); @@ -303,8 +301,8 @@ public void testResetPaths () throws Exception { assertStatus(statuses, workDir, file4, true, Status.STATUS_REMOVED, Status.STATUS_ADDED, Status.STATUS_NORMAL, false); assertEquals(content, read(file1)); } - - public void testResetPaths_NonRecursive () throws Exception { + + public void testResetPaths_NonRecursive() throws Exception { File folder = new File(workDir, "folder"); folder.mkdirs(); File file1 = new File(folder, "file1"); // index entry will be modified @@ -313,7 +311,7 @@ public void testResetPaths_NonRecursive () throws Exception { subfolder.mkdirs(); File file2 = new File(subfolder, "file2"); // index entry will be left alone write(file2, "blablablabla in file2"); - File[] files = new File[] { file1, file2 }; + File[] files = new File[]{file1, file2}; add(files); commit(files); @@ -326,9 +324,9 @@ public void testResetPaths_NonRecursive () throws Exception { write(file1, content); write(file2, content); client.add(files, NULL_PROGRESS_MONITOR); - + // children - client.reset(new File[] { folder }, "HEAD", false, NULL_PROGRESS_MONITOR); + client.reset(new File[]{folder}, "HEAD", false, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, file1, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); @@ -336,26 +334,26 @@ public void testResetPaths_NonRecursive () throws Exception { write(file1, content); // recursive - client.reset(new File[] { folder }, "HEAD", true, NULL_PROGRESS_MONITOR); + client.reset(new File[]{folder}, "HEAD", true, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, file1, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); - + write(file1, content); add(file1); // non recursive on file - client.reset(new File[] { file1 }, "HEAD", false, NULL_PROGRESS_MONITOR); + client.reset(new File[]{file1}, "HEAD", false, NULL_PROGRESS_MONITOR); statuses = client.getStatus(files, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, file1, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); } - public void testResetPathsChangeType () throws Exception { + public void testResetPathsChangeType() throws Exception { File file = new File(workDir, "f"); // index entry will be modified File file2 = new File(file, "file"); write(file, "blablablabla"); - File[] files = new File[] { file, file2 }; + File[] files = new File[]{file, file2}; add(files); commit(files); @@ -385,49 +383,49 @@ public void testResetPathsChangeType () throws Exception { } // must not checkout from nested repositories - public void testResetNested () throws Exception { + public void testResetNested() throws Exception { File f = new File(workDir, "f"); write(f, "file"); - + GitClient client = getClient(workDir); - client.add(new File[] { f }, NULL_PROGRESS_MONITOR); - client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR); - + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + client.commit(new File[]{f}, "init commit", null, null, NULL_PROGRESS_MONITOR); + File nested = new File(workDir, "nested"); nested.mkdirs(); File f2 = new File(nested, "f"); write(f2, "file"); GitClient clientNested = getClient(nested); clientNested.init(NULL_PROGRESS_MONITOR); - clientNested.add(new File[] { f2 }, NULL_PROGRESS_MONITOR); - clientNested.commit(new File[] { f2 }, "init commit", null, null, NULL_PROGRESS_MONITOR); - + clientNested.add(new File[]{f2}, NULL_PROGRESS_MONITOR); + clientNested.commit(new File[]{f2}, "init commit", null, null, NULL_PROGRESS_MONITOR); + write(f, "change"); add(f); write(f2, "change"); - clientNested.add(new File[] { f2 }, NULL_PROGRESS_MONITOR); - - client.reset(new File[] { workDir, nested }, "HEAD", true, NULL_PROGRESS_MONITOR); - Map statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + clientNested.add(new File[]{f2}, NULL_PROGRESS_MONITOR); + + client.reset(new File[]{workDir, nested}, "HEAD", true, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, nested, false, Status.STATUS_NORMAL, Status.STATUS_ADDED, Status.STATUS_ADDED, false); - statuses = clientNested.getStatus(new File[] { nested }, NULL_PROGRESS_MONITOR); + statuses = clientNested.getStatus(new File[]{nested}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, nested, f2, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); - - client.reset("master", ResetType.MIXED, NULL_PROGRESS_MONITOR); - statuses = clientNested.getStatus(new File[] { nested }, NULL_PROGRESS_MONITOR); + + client.reset(getDefaultBranch(), ResetType.MIXED, NULL_PROGRESS_MONITOR); + statuses = clientNested.getStatus(new File[]{nested}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, nested, f2, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); - - client.reset("master", ResetType.HARD, NULL_PROGRESS_MONITOR); - statuses = clientNested.getStatus(new File[] { nested }, NULL_PROGRESS_MONITOR); + + client.reset(getDefaultBranch(), ResetType.HARD, NULL_PROGRESS_MONITOR); + statuses = clientNested.getStatus(new File[]{nested}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, nested, f2, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); } - - public void testLineEndingsWindows () throws Exception { + + public void testLineEndingsWindows() throws Exception { if (!isWindows()) { return; } @@ -436,18 +434,18 @@ public void testLineEndingsWindows () throws Exception { StoredConfig cfg = repository.getConfig(); cfg.setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_AUTOCRLF, "true"); cfg.save(); - + File f = new File(workDir, "f"); write(f, "a\r\nb\r\n"); - File[] roots = new File[] { f }; - + File[] roots = new File[]{f}; + GitClient client = getClient(workDir); runExternally(workDir, Arrays.asList("git.cmd", "add", "f")); List res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("A f"), res); DirCacheEntry e1 = repository.readDirCache().getEntry("f"); runExternally(workDir, Arrays.asList("git.cmd", "commit", "-m", "hello")); - + write(f, "a\r\nb\r\nc\r\n"); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList(" M f"), res); @@ -455,29 +453,29 @@ public void testLineEndingsWindows () throws Exception { res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("M f"), res); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); - + client.reset(roots, "HEAD", true, NULL_PROGRESS_MONITOR); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); assertEquals(e1.getObjectId(), repository.readDirCache().getEntry("f").getObjectId()); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList(" M f"), res); - + runExternally(workDir, Arrays.asList("git.cmd", "add", "f")); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(Arrays.asList("M f"), res); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); - + client.reset("HEAD", ResetType.HARD, NULL_PROGRESS_MONITOR); assertStatus(client.getStatus(roots, NULL_PROGRESS_MONITOR), workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); assertEquals(e1.getObjectId(), repository.readDirCache().getEntry("f").getObjectId()); res = runExternally(workDir, Arrays.asList("git.cmd", "status", "-s")); assertEquals(0, res.size()); } - - public void testResetConflict () throws Exception { + + public void testResetConflict() throws Exception { File file = new File(workDir, "file"); write(file, "init"); - File[] files = new File[] { file }; + File[] files = new File[]{file}; add(files); commit(files); @@ -493,15 +491,15 @@ public void testResetConflict () throws Exception { builder.add(e1); builder.finish(); builder.commit(); - + GitClient client = getClient(workDir); Map status = client.getStatus(files, NULL_PROGRESS_MONITOR); assertTrue(status.get(file).isConflict()); assertEquals(GitConflictDescriptor.Type.BOTH_DELETED, status.get(file).getConflictDescriptor().getType()); - + client.reset(files, "HEAD", true, NULL_PROGRESS_MONITOR); status = client.getStatus(files, NULL_PROGRESS_MONITOR); assertFalse(status.get(file).isConflict()); } - + } diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/RevertTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/RevertTest.java index 320554ca0368..3db04fd63e95 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/RevertTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/RevertTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -33,10 +32,11 @@ * @author ondra */ public class RevertTest extends AbstractGitTestCase { + private File workDir; private Repository repository; - public RevertTest (String testName) throws IOException { + public RevertTest(String testName) throws IOException { super(testName); } @@ -46,14 +46,14 @@ protected void setUp() throws Exception { workDir = getWorkingDirectory(); repository = getRepository(getLocalGitRepository()); } - - public void testRevertLastCommitOneFile () throws Exception { + + public void testRevertLastCommitOneFile() throws Exception { File f = new File(workDir, "f"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; write(f, "init"); add(f); commit(f); - + // modify and commit write(f, "change"); add(f); @@ -61,18 +61,18 @@ public void testRevertLastCommitOneFile () throws Exception { assertEquals("change", read(f)); getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); assertEquals("init", read(f)); - assertEquals("Revert \"modification\"\n\nThis reverts commit " + commit.getRevision() + ".", getClient(workDir).log("master", NULL_PROGRESS_MONITOR).getFullMessage()); + assertEquals("Revert \"modification\"\n\nThis reverts commit " + commit.getRevision() + ".", getClient(workDir).log(getDefaultBranch(), NULL_PROGRESS_MONITOR).getFullMessage()); } - - public void testRevertLastCommitTwoFiles () throws Exception { + + public void testRevertLastCommitTwoFiles() throws Exception { File f1 = new File(workDir, "f"); File f2 = new File(workDir, "f2"); - File[] files = new File[] { f1, f2 }; + File[] files = new File[]{f1, f2}; write(f1, "init1"); write(f2, "init2"); add(files); commit(files); - + // modify and commit write(f1, "change1"); write(f2, "change2"); @@ -80,18 +80,18 @@ public void testRevertLastCommitTwoFiles () throws Exception { GitRevisionInfo commit = getClient(workDir).commit(files, "modification", null, null, NULL_PROGRESS_MONITOR); assertEquals("change1", read(f1)); assertEquals("change2", read(f2)); - getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); + getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); assertEquals("init1", read(f1)); assertEquals("init2", read(f2)); } - - public void testRevertCommitBeforeLast () throws Exception { + + public void testRevertCommitBeforeLast() throws Exception { File f = new File(workDir, "f"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; write(f, "a\nb\nc"); add(f); commit(f); - + // modify and commit write(f, "z\nb\nc"); add(f); @@ -101,17 +101,17 @@ public void testRevertCommitBeforeLast () throws Exception { add(f); commit(f); assertEquals("z\nb\ny", read(f)); - getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); + getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); assertEquals("a\nb\ny", read(f)); } - - public void testRevertLastTwoCommits () throws Exception { + + public void testRevertLastTwoCommits() throws Exception { File f = new File(workDir, "f"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; write(f, "a\nb\nc"); add(f); commit(f); - + // modify and commit write(f, "z\nb\nc"); add(f); @@ -121,38 +121,38 @@ public void testRevertLastTwoCommits () throws Exception { add(f); GitRevisionInfo commit2 = getClient(workDir).commit(files, "modification 2", null, null, NULL_PROGRESS_MONITOR); assertEquals("z\nb\ny", read(f)); - getClient(workDir).revert(commit2.getRevision(), null, true, NULL_PROGRESS_MONITOR); + getClient(workDir).revert(commit2.getRevision(), null, true, NULL_PROGRESS_MONITOR); assertEquals("z\nb\nc", read(f)); - getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); + getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); assertEquals("a\nb\nc", read(f)); } - - public void testRevertFailure () throws Exception { + + public void testRevertFailure() throws Exception { File f = new File(workDir, "f"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; write(f, "init"); add(f); commit(f); - + // modify and commit write(f, "change"); add(f); GitRevisionInfo commit = getClient(workDir).commit(files, "modification", null, null, NULL_PROGRESS_MONITOR); write(f, "local change"); - GitRevertResult result = getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); + GitRevertResult result = getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); assertEquals("local change", read(f)); assertEquals(Arrays.asList(f), result.getFailures()); assertEquals(GitRevertResult.Status.FAILED, result.getStatus()); assertNull(repository.readMergeCommitMsg()); } - - public void testRevertConflict () throws Exception { + + public void testRevertConflict() throws Exception { File f = new File(workDir, "f"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; write(f, "init"); add(f); commit(f); - + // modify and commit write(f, "change"); add(f); @@ -160,39 +160,39 @@ public void testRevertConflict () throws Exception { write(f, "local change"); add(f); commit(f); - GitRevertResult result = getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); + GitRevertResult result = getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); assertEquals("<<<<<<< OURS\nlocal change\n=======\ninit\n>>>>>>> THEIRS", read(f)); assertEquals(Arrays.asList(f), result.getConflicts()); assertEquals(GitRevertResult.Status.CONFLICTING, result.getStatus()); // @TODO message checking is brittle // assertEquals("Revert \"modification\"\n\nThis reverts commit " + commit.getRevision() + ".\n\nConflicts:\n\tf\n", repository.readMergeCommitMsg()); } - - public void testRevertNotIncluded () throws Exception { + + public void testRevertNotIncluded() throws Exception { File f = new File(workDir, "f"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; write(f, "init"); add(f); commit(f); - - getClient(workDir).createBranch("branch", "master", NULL_PROGRESS_MONITOR); - + + getClient(workDir).createBranch("branch", getDefaultBranch(), NULL_PROGRESS_MONITOR); + // modify and commit write(f, "change"); add(f); GitRevisionInfo commit = getClient(workDir).commit(files, "modification", null, null, NULL_PROGRESS_MONITOR); getClient(workDir).checkoutRevision("branch", true, NULL_PROGRESS_MONITOR); - GitRevertResult result = getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); + GitRevertResult result = getClient(workDir).revert(commit.getRevision(), null, true, NULL_PROGRESS_MONITOR); assertEquals(GitRevertResult.Status.NO_CHANGE, result.getStatus()); } - public void testRevertNoCommit () throws Exception { + public void testRevertNoCommit() throws Exception { File f = new File(workDir, "f"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; write(f, "init"); add(f); commit(f); - + // modify and commit write(f, "change"); add(f); @@ -200,18 +200,18 @@ public void testRevertNoCommit () throws Exception { assertEquals("change", read(f)); GitRevertResult result = getClient(workDir).revert(commit.getRevision(), null, false, NULL_PROGRESS_MONITOR); assertEquals("init", read(f)); - assertEquals(commit.getRevision(), getClient(workDir).getBranches(false, NULL_PROGRESS_MONITOR).get("master").getId()); + assertEquals(commit.getRevision(), getClient(workDir).getBranches(false, NULL_PROGRESS_MONITOR).get(getDefaultBranch()).getId()); assertEquals(Arrays.asList(files), Arrays.asList(getClient(workDir).listModifiedIndexEntries(files, NULL_PROGRESS_MONITOR))); assertEquals(GitRevertResult.Status.REVERTED_IN_INDEX, result.getStatus()); } - public void testRevertMessage () throws Exception { + public void testRevertMessage() throws Exception { File f = new File(workDir, "f"); - File[] files = new File[] { f }; + File[] files = new File[]{f}; write(f, "init"); add(f); commit(f); - + // modify and commit write(f, "change"); add(f); @@ -219,6 +219,6 @@ public void testRevertMessage () throws Exception { assertEquals("change", read(f)); getClient(workDir).revert(commit.getRevision(), "blablabla message", true, NULL_PROGRESS_MONITOR); assertEquals("init", read(f)); - assertEquals("blablabla message", getClient(workDir).log("master", NULL_PROGRESS_MONITOR).getFullMessage()); + assertEquals("blablabla message", getClient(workDir).log(getDefaultBranch(), NULL_PROGRESS_MONITOR).getFullMessage()); } } diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/SetUpstreamBranchTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/SetUpstreamBranchTest.java index 81ec8cf0cc1b..4e8af16fbd63 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/SetUpstreamBranchTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/SetUpstreamBranchTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -26,7 +25,6 @@ import java.util.Map; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.ConfigConstants; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; import org.netbeans.libs.git.GitBranch; @@ -40,11 +38,12 @@ * @author ondra */ public class SetUpstreamBranchTest extends AbstractGitTestCase { + private File workDir; private static final String BRANCH = "mybranch"; private Repository repository; - public SetUpstreamBranchTest (String testName) throws IOException { + public SetUpstreamBranchTest(String testName) throws IOException { super(testName); } @@ -54,53 +53,53 @@ protected void setUp() throws Exception { workDir = getWorkingDirectory(); repository = getRepository(getLocalGitRepository()); } - - public void testLocalTracking () throws GitException { + + 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); - + 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); + GitBranch b = client.createBranch(BRANCH, getDefaultBranch(), NULL_PROGRESS_MONITOR); assertNull(b.getTrackedBranch()); - + // set tracking - b = client.setUpstreamBranch(BRANCH, Constants.MASTER, NULL_PROGRESS_MONITOR); - assertEquals(Constants.MASTER, b.getTrackedBranch().getName()); + b = client.setUpstreamBranch(BRANCH, getDefaultBranch(), NULL_PROGRESS_MONITOR); + assertEquals(getDefaultBranch(), b.getTrackedBranch().getName()); } - - public void testRemoteTrackingNoRemoteSet () throws GitException { + + 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); - + 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/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()), Arrays.asList("+refs/heads/*:refs/remotes/origin/*"), NULL_PROGRESS_MONITOR); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); - assertTrue(branches.containsKey("origin/master")); - assertNull(branches.get("master").getTrackedBranch()); - + assertTrue(branches.containsKey("origin/" + getDefaultBranch())); + assertNull(branches.get(getDefaultBranch()).getTrackedBranch()); + // set tracking - GitBranch b = client.setUpstreamBranch("master", "origin/master", NULL_PROGRESS_MONITOR); - assertEquals("origin/master", b.getTrackedBranch().getName()); - + GitBranch b = client.setUpstreamBranch(getDefaultBranch(), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); + assertEquals("origin/" + getDefaultBranch(), b.getTrackedBranch().getName()); + Config cfg = repository.getConfig(); - assertEquals(".", cfg.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE)); - assertEquals("refs/remotes/origin/master", cfg.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE)); + assertEquals(".", cfg.getString(ConfigConstants.CONFIG_BRANCH_SECTION, getDefaultBranch(), ConfigConstants.CONFIG_KEY_REMOTE)); + assertEquals("refs/remotes/origin/" + getDefaultBranch(), cfg.getString(ConfigConstants.CONFIG_BRANCH_SECTION, getDefaultBranch(), ConfigConstants.CONFIG_KEY_MERGE)); } - - public void testRemoteTracking () throws Exception { + + 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); - + 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", @@ -110,36 +109,36 @@ public void testRemoteTracking () throws Exception { Collections.emptyList()), NULL_PROGRESS_MONITOR); client.push("origin", - Arrays.asList("refs/heads/master:refs/heads/master"), - Arrays.asList("+refs/heads/master:refs/remotes/origin/master"), + Arrays.asList("refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()), + Arrays.asList("+refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch()), NULL_PROGRESS_MONITOR); Map branches = client.getBranches(true, NULL_PROGRESS_MONITOR); - assertTrue(branches.containsKey("origin/master")); - assertNull(branches.get("master").getTrackedBranch()); - + assertTrue(branches.containsKey("origin/" + getDefaultBranch())); + assertNull(branches.get(getDefaultBranch()).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); - assertEquals("origin/master", b.getTrackedBranch().getName()); - + GitBranch b = client.setUpstreamBranch(getDefaultBranch(), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); + assertEquals("origin/" + getDefaultBranch(), b.getTrackedBranch().getName()); + config = repository.getConfig(); - assertEquals("origin", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE)); - assertEquals("refs/heads/master", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE)); + assertEquals("origin", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, getDefaultBranch(), ConfigConstants.CONFIG_KEY_REMOTE)); + assertEquals("refs/heads/" + getDefaultBranch(), config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, getDefaultBranch(), ConfigConstants.CONFIG_KEY_MERGE)); assertFalse(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); - assertEquals("origin/master", b.getTrackedBranch().getName()); + b = client.setUpstreamBranch(getDefaultBranch(), "origin/" + getDefaultBranch(), NULL_PROGRESS_MONITOR); + assertEquals("origin/" + getDefaultBranch(), b.getTrackedBranch().getName()); config = repository.getConfig(); - assertEquals("origin", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE)); - assertEquals("refs/heads/master", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE)); - assertTrue(config.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REBASE, false)); + assertEquals("origin", config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, getDefaultBranch(), ConfigConstants.CONFIG_KEY_REMOTE)); + assertEquals("refs/heads/" + getDefaultBranch(), config.getString(ConfigConstants.CONFIG_BRANCH_SECTION, getDefaultBranch(), ConfigConstants.CONFIG_KEY_MERGE)); + assertTrue(config.getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, getDefaultBranch(), ConfigConstants.CONFIG_KEY_REBASE, false)); } - + } diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/StashTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/StashTest.java index 62e98a8bd717..6716e826609d 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/StashTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/StashTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -33,10 +32,11 @@ * @author ondra */ public class StashTest extends AbstractGitTestCase { + private Repository repository; private File workDir; - public StashTest (String testName) throws IOException { + public StashTest(String testName) throws IOException { super(testName); } @@ -47,147 +47,147 @@ protected void setUp() throws Exception { repository = getRepository(getLocalGitRepository()); } - public void testStashCreate () throws Exception { + public void testStashCreate() throws Exception { File folder = new File(workDir, "folder"); File file1 = new File(workDir, "file"); File file2 = new File(folder, "file"); - + folder.mkdirs(); write(file1, "file1"); write(file2, "file2"); - + add(); commit(); - + write(file1, "modification 1"); add(); write(file2, "modification 2"); - + GitClient client = getClient(workDir); - + String msg = "Stash save"; GitRevisionInfo stashedCommit = client.stashSave(msg, false, NULL_PROGRESS_MONITOR); - + assertEquals("file1", read(file1)); assertEquals("file2", read(file2)); assertEquals(msg, stashedCommit.getFullMessage()); - + Map statuses = client.getStatus(new File[0], NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); } - public void testStashApply () throws Exception { + public void testStashApply() throws Exception { File folder = new File(workDir, "folder"); File file1 = new File(workDir, "file"); File file2 = new File(folder, "file"); - + folder.mkdirs(); write(file1, "file1"); write(file2, "file2"); - + add(); commit(); - + write(file1, "modification 1"); add(); write(file2, "modification 2"); - + GitClient client = getClient(workDir); - + client.stashSave("stash", false, NULL_PROGRESS_MONITOR); - + Map statuses = client.getStatus(new File[0], NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); - + client.stashApply(0, false, NULL_PROGRESS_MONITOR); assertEquals("modification 1", read(file1)); assertEquals("modification 2", read(file2)); statuses = client.getStatus(new File[0], NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); - - client.reset("master", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); + + client.reset(getDefaultBranch(), GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); statuses = client.getStatus(new File[0], NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); - + client.stashApply(0, true, NULL_PROGRESS_MONITOR); assertEquals("modification 1", read(file1)); assertEquals("modification 2", read(file2)); statuses = client.getStatus(new File[0], NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, false); assertStatus(statuses, workDir, file2, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_MODIFIED, GitStatus.Status.STATUS_MODIFIED, false); - + assertEquals(0, client.stashList(NULL_PROGRESS_MONITOR).length); } - public void testStashCreateUntracked () throws Exception { + public void testStashCreateUntracked() throws Exception { File folder = new File(workDir, "folder"); File file1 = new File(workDir, "file"); File file2 = new File(folder, "untracked"); - + folder.mkdirs(); write(file1, "file1"); - + add(); commit(); - + write(file1, "modification 1"); add(); write(file2, "modification 2"); - + GitClient client = getClient(workDir); - + String msg = "Stash save"; GitRevisionInfo stashedCommit = client.stashSave(msg, false, NULL_PROGRESS_MONITOR); - + assertEquals(msg, stashedCommit.getFullMessage()); - + Map statuses = client.getStatus(new File[0], NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2, false, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_ADDED, false); - + stashedCommit = client.stashSave(msg, true, NULL_PROGRESS_MONITOR); assertEquals(msg, stashedCommit.getFullMessage()); - + statuses = client.getStatus(new File[0], NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertFalse(statuses.containsKey(file2)); - + client.stashApply(0, false, NULL_PROGRESS_MONITOR); statuses = client.getStatus(new File[0], NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, true, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2, false, GitStatus.Status.STATUS_NORMAL, GitStatus.Status.STATUS_ADDED, GitStatus.Status.STATUS_ADDED, false); } - - public void testStashDrop () throws Exception { + + public void testStashDrop() throws Exception { File file = new File(workDir, "file"); - + write(file, "file"); - + add(); commit(); - + write(file, "modification"); add(); - + GitClient client = getClient(workDir); - + client.stashSave("stash", false, NULL_PROGRESS_MONITOR); - + write(file, "modification 2"); add(); write(file, "modification 3"); - + client.stashSave("stash", false, NULL_PROGRESS_MONITOR); - + GitRevisionInfo[] stashList = client.stashList(NULL_PROGRESS_MONITOR); assertEquals(2, stashList.length); - + client.stashDrop(1, NULL_PROGRESS_MONITOR); - + GitRevisionInfo[] stashList2 = client.stashList(NULL_PROGRESS_MONITOR); assertEquals(1, stashList2.length); assertEquals(stashList[0].getRevision(), stashList2[0].getRevision()); diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/StatusTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/StatusTest.java index befff6783f26..7eef7c95c5f0 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/StatusTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/StatusTest.java @@ -64,7 +64,7 @@ protected void setUp() throws Exception { repository = getRepository(getLocalGitRepository()); } - public void testMiscStatus () throws Exception { + public void testMiscStatus() throws Exception { write(new File(workDir, ".gitignore"), "ignored"); File untracked = new File(workDir, "untracked"); write(untracked, "untracked"); @@ -126,7 +126,7 @@ public void testMiscStatus () throws Exception { TestStatusListener listener = new TestStatusListener(); GitClient client = getClient(workDir); client.addNotificationListener(listener); - Map statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertFalse(statuses.isEmpty()); assertStatus(statuses, workDir, untracked, false, Status.STATUS_NORMAL, Status.STATUS_ADDED, Status.STATUS_ADDED, false, listener); assertStatus(statuses, workDir, added_uptodate, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false, listener); @@ -145,9 +145,9 @@ public void testMiscStatus () throws Exception { // what about isIgnored() here? assertStatus(statuses, workDir, ignored, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false, listener); } - + // diff WT against a commit other than HEAD - public void testMiscStatusCommit () throws Exception { + public void testMiscStatusCommit() throws Exception { write(new File(workDir, ".gitignore"), "ignored"); File untracked = new File(workDir, "untracked"); write(untracked, "untracked"); @@ -205,10 +205,10 @@ public void testMiscStatusCommit () throws Exception { uptodate_deleted.delete(); write(deleted_untracked, "deleted_untracked"); write(deleted_modified, "deleted_modified\nchange"); - + GitClient client = getClient(workDir); - String revId = client.getBranches(false, NULL_PROGRESS_MONITOR).get(Constants.MASTER).getId(); - + String revId = client.getBranches(false, NULL_PROGRESS_MONITOR).get(getDefaultBranch()).getId(); + File someFile = new File(workDir, "fileforothercommit"); write(someFile, "fileforothercommit"); add(someFile); @@ -216,7 +216,7 @@ public void testMiscStatusCommit () throws Exception { TestStatusListener listener = new TestStatusListener(); client.addNotificationListener(listener); - Map statuses = client.getStatus(new File[] { workDir }, Constants.HEAD, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{workDir}, Constants.HEAD, NULL_PROGRESS_MONITOR); assertFalse(statuses.isEmpty()); assertStatus(statuses, workDir, untracked, false, Status.STATUS_NORMAL, Status.STATUS_ADDED, Status.STATUS_ADDED, false, listener); assertStatus(statuses, workDir, added_uptodate, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false, listener); @@ -235,10 +235,10 @@ public void testMiscStatusCommit () throws Exception { assertStatus(statuses, workDir, someFile, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false, listener); // what about isIgnored() here? assertStatus(statuses, workDir, ignored, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false, listener); - + listener = new TestStatusListener(); client.addNotificationListener(listener); - statuses = client.getStatus(new File[] { workDir }, revId, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{workDir}, revId, NULL_PROGRESS_MONITOR); assertFalse(statuses.isEmpty()); assertStatus(statuses, workDir, untracked, false, Status.STATUS_NORMAL, Status.STATUS_ADDED, Status.STATUS_ADDED, false, listener); assertStatus(statuses, workDir, added_uptodate, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false, listener); @@ -260,7 +260,7 @@ public void testMiscStatusCommit () throws Exception { assertStatus(statuses, workDir, someFile, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false, listener); } - public void testStatusSingleFile () throws Exception { + public void testStatusSingleFile() throws Exception { File untracked = new File(workDir, "untracked"); write(untracked, "untracked"); File added_modified = new File(workDir, "added-modified"); @@ -282,27 +282,27 @@ public void testStatusSingleFile () throws Exception { GitClient client = getClient(workDir); TestStatusListener monitor = new TestStatusListener(); client.addNotificationListener(monitor); - Map statuses = client.getStatus(new File[] { untracked }, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{untracked}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, workDir, untracked, false, Status.STATUS_NORMAL, Status.STATUS_ADDED, Status.STATUS_ADDED, false, monitor); monitor = new TestStatusListener(); client.addNotificationListener(monitor); - statuses = client.getStatus(new File[] { added_modified }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{added_modified}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, workDir, added_modified, true, Status.STATUS_ADDED, Status.STATUS_MODIFIED, Status.STATUS_ADDED, false, monitor); monitor = new TestStatusListener(); client.addNotificationListener(monitor); - statuses = client.getStatus(new File[] { uptodate_modified }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{uptodate_modified}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, workDir, uptodate_modified, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false, monitor); monitor = new TestStatusListener(); client.addNotificationListener(monitor); - statuses = client.getStatus(new File[] { modified_modified }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{modified_modified}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, workDir, modified_modified, true, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false, monitor); } - public void testStatusTree () throws Exception { + public void testStatusTree() throws Exception { File folder = new File(workDir, "folder1"); folder.mkdirs(); write(new File(folder, "untracked1"), "untracked"); @@ -332,7 +332,7 @@ public void testStatusTree () throws Exception { GitClient client = getClient(workDir); TestStatusListener monitor = new TestStatusListener(); client.addNotificationListener(monitor); - Map statuses = client.getStatus(new File[] { folder }, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{folder}, NULL_PROGRESS_MONITOR); assertEquals(6, statuses.size()); assertStatus(statuses, workDir, f1, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false, monitor); assertStatus(statuses, workDir, f2, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false, monitor); @@ -341,20 +341,20 @@ public void testStatusTree () throws Exception { assertStatus(statuses, workDir, f5, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false, monitor); assertStatus(statuses, workDir, f6, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false, monitor); } - - public void testStatusDifferentTree () throws Exception { + + public void testStatusDifferentTree() throws Exception { File folder = new File(workDir.getParent(), "folder1"); folder.mkdirs(); try { StatusListener monitor = new TestStatusListener(); - getClient(workDir).getStatus(new File[] { folder }, NULL_PROGRESS_MONITOR); + getClient(workDir).getStatus(new File[]{folder}, NULL_PROGRESS_MONITOR); fail("Different tree"); } catch (IllegalArgumentException ex) { // OK } } - public void testSkipIgnoredFolders () throws Exception { + public void testSkipIgnoredFolders() throws Exception { File file1 = new File(workDir, "file1"); File folder = new File(workDir, "folder"); File file2 = new File(folder, "file2"); @@ -379,7 +379,7 @@ public void testSkipIgnoredFolders () throws Exception { write(new File(workDir, ".gitignore"), "folder\nfile1"); write(new File(folder2, ".gitignore"), "subfolder"); - Map statuses = getClient(workDir).getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + Map statuses = getClient(workDir).getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file1, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false); assertStatus(statuses, workDir, folder, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_IGNORED, false); assertTrue(statuses.get(folder).isFolder()); @@ -391,34 +391,34 @@ public void testSkipIgnoredFolders () throws Exception { assertTrue(statuses.get(subFolder2).isFolder()); assertNull(statuses.get(file6)); - statuses = getClient(workDir).getStatus(new File[] { folder }, NULL_PROGRESS_MONITOR); + statuses = getClient(workDir).getStatus(new File[]{folder}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, folder, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_IGNORED, false); assertTrue(statuses.get(folder).isFolder()); assertNull(statuses.get(file2)); assertNull(statuses.get(file3)); assertNull(statuses.get(file4)); - - statuses = getClient(workDir).getStatus(new File[] { file2 }, NULL_PROGRESS_MONITOR); + + statuses = getClient(workDir).getStatus(new File[]{file2}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file2, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false); assertNull(statuses.get(folder)); assertNull(statuses.get(file3)); assertNull(statuses.get(file4)); - statuses = getClient(workDir).getStatus(new File[] { folder, file2 }, NULL_PROGRESS_MONITOR); + statuses = getClient(workDir).getStatus(new File[]{folder, file2}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file2, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false); assertStatus(statuses, workDir, folder, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_IGNORED, false); assertTrue(statuses.get(folder).isFolder()); assertNull(statuses.get(file3)); assertNull(statuses.get(file4)); - statuses = getClient(workDir).getStatus(new File[] { folder, file2, file3 }, NULL_PROGRESS_MONITOR); + statuses = getClient(workDir).getStatus(new File[]{folder, file2, file3}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file2, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false); assertStatus(statuses, workDir, file3, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false); assertStatus(statuses, workDir, folder, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_IGNORED, false); assertTrue(statuses.get(folder).isFolder()); assertNull(statuses.get(file4)); - statuses = getClient(workDir).getStatus(new File[] { folder, file2, file3, file4 }, NULL_PROGRESS_MONITOR); + statuses = getClient(workDir).getStatus(new File[]{folder, file2, file3, file4}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, file2, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false); assertStatus(statuses, workDir, file3, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false); assertStatus(statuses, workDir, file4, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false); @@ -426,7 +426,7 @@ public void testSkipIgnoredFolders () throws Exception { assertTrue(statuses.get(folder).isFolder()); } - public void testIgnoredFilesAreNotTracked () throws Exception { + public void testIgnoredFilesAreNotTracked() throws Exception { File file = new File(workDir, "ignoredFile"); file.createNewFile(); File folder = new File(workDir, "ignoredFolder"); @@ -440,22 +440,24 @@ public void testIgnoredFilesAreNotTracked () throws Exception { add(file2); - Map statuses = getClient(workDir).getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + Map statuses = getClient(workDir).getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertFalse(statuses.get(file).isTracked()); assertFalse(statuses.get(folder).isTracked()); assertFalse(statuses.get(folder2).isTracked()); } - public void testCancel () throws Exception { + public void testCancel() throws Exception { final File file = new File(workDir, "file"); file.createNewFile(); final File file2 = new File(workDir, "file2"); file2.createNewFile(); class Monitor extends DefaultProgressMonitor implements StatusListener { + private boolean barrierAccessed; private int count; private boolean cont; + @Override public void notifyStatus(GitStatus status) { barrierAccessed = true; @@ -467,6 +469,7 @@ public void notifyStatus(GitStatus status) { } } } + private void waitAtBarrier() throws InterruptedException { for (int i = 0; i < 100; ++i) { if (barrierAccessed) { @@ -485,7 +488,7 @@ private void waitAtBarrier() throws InterruptedException { public void run() { try { client.addNotificationListener(m); - client.getStatus(new File[] { file, file2 }, m); + client.getStatus(new File[]{file, file2}, m); } catch (GitException ex) { exs[0] = ex; } @@ -501,13 +504,13 @@ public void run() { assertEquals(null, exs[0]); } - public void testConflictScan () throws Exception { + public void testConflictScan() throws Exception { GitClient client = getClient(workDir); File f = new File(workDir, "f"); f.createNewFile(); File f2 = new File(workDir, "f2"); f2.createNewFile(); - File[] roots = new File[] { f, f2 }; + File[] roots = new File[]{f, f2}; add(roots); commit(roots); Map conflicts = client.getConflicts(roots, NULL_PROGRESS_MONITOR); @@ -540,49 +543,49 @@ public void testConflictScan () throws Exception { } finally { cache.unlock(); } - conflicts = client.getConflicts(new File[] { f }, NULL_PROGRESS_MONITOR); + conflicts = client.getConflicts(new File[]{f}, NULL_PROGRESS_MONITOR); assertEquals(1, conflicts.size()); - conflicts = client.getConflicts(new File[] { f2 }, NULL_PROGRESS_MONITOR); + conflicts = client.getConflicts(new File[]{f2}, NULL_PROGRESS_MONITOR); assertEquals(1, conflicts.size()); conflicts = client.getConflicts(roots, NULL_PROGRESS_MONITOR); assertEquals(2, conflicts.size()); } - - public void testIgnoredInExlude () throws Exception { + + public void testIgnoredInExlude() throws Exception { File f = new File(workDir, "f"); write(f, "hi, i am ignored"); File exclude = new File(workDir, ".git/info/exclude"); exclude.getParentFile().mkdirs(); write(exclude, "f"); - GitStatus st = getClient(workDir).getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f); + GitStatus st = getClient(workDir).getStatus(new File[]{f}, NULL_PROGRESS_MONITOR).get(f); assertEquals(Status.STATUS_IGNORED, st.getStatusIndexWC()); } - - public void testModifiedUnderIgnored () throws Exception { + + public void testModifiedUnderIgnored() throws Exception { File f = new File(workDir, "folder/f"); f.getParentFile().mkdirs(); write(f, "hi, i am new"); add(f); commit(f); GitClient client = getClient(workDir); - Map st = client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR); + Map st = client.getStatus(new File[]{f}, NULL_PROGRESS_MONITOR); assertStatus(st, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); - - client.ignore(new File[] { f.getParentFile() }, NULL_PROGRESS_MONITOR); - st = client.getStatus(new File[] { }, NULL_PROGRESS_MONITOR); + + client.ignore(new File[]{f.getParentFile()}, NULL_PROGRESS_MONITOR); + st = client.getStatus(new File[]{}, NULL_PROGRESS_MONITOR); assertStatus(st, workDir, f.getParentFile(), false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_IGNORED, false); // file f is not ignored, it's committed assertStatus(st, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); - + write(f, "hi, i am modified"); - st = client.getStatus(new File[] { }, NULL_PROGRESS_MONITOR); + st = client.getStatus(new File[]{}, NULL_PROGRESS_MONITOR); assertStatus(st, workDir, f.getParentFile(), false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_IGNORED, false); // file f is not ignored, it's committed and modified assertStatus(st, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); - + } - - public void testIgnoreExecutable () throws Exception { + + public void testIgnoreExecutable() throws Exception { if (isWindows()) { // no reason to test on win return; @@ -590,29 +593,29 @@ public void testIgnoreExecutable () throws Exception { File f = new File(workDir, "f"); write(f, "hi, i am executable"); f.setExecutable(true); - File[] roots = { f }; + File[] roots = {f}; add(roots); commit(roots); GitClient client = getClient(workDir); Map statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); - + f.setExecutable(false); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, Status.STATUS_MODIFIED, false); - + StoredConfig config = repository.getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save(); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); - + config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, true); config.save(); add(roots); statuses = client.getStatus(roots, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, f, true, Status.STATUS_MODIFIED, Status.STATUS_NORMAL, Status.STATUS_MODIFIED, false); - + config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_FILEMODE, false); config.save(); add(roots); @@ -621,198 +624,199 @@ public void testIgnoreExecutable () throws Exception { } // must not return status for nested repositories - public void testStatusNested () throws Exception { + public void testStatusNested() throws Exception { File f = new File(workDir, "f"); write(f, "file"); - + GitClient client = getClient(workDir); - client.add(new File[] { f }, NULL_PROGRESS_MONITOR); - client.commit(new File[] { f }, "init commit", null, null, NULL_PROGRESS_MONITOR); - + client.add(new File[]{f}, NULL_PROGRESS_MONITOR); + client.commit(new File[]{f}, "init commit", null, null, NULL_PROGRESS_MONITOR); + File nested = new File(workDir, "nested"); nested.mkdirs(); new File(workDir, "emptyFolder").mkdirs(); - Map statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + Map statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); // commandline is silent about empty folders assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); GitClient clientNested = getClient(nested); clientNested.init(NULL_PROGRESS_MONITOR); File f2 = new File(nested, "f"); write(f2, "file"); - clientNested.add(new File[] { f2 }, NULL_PROGRESS_MONITOR); - clientNested.commit(new File[] { f2 }, "init commit", null, null, NULL_PROGRESS_MONITOR); - - statuses = client.getStatus(new File[] { workDir }, NULL_PROGRESS_MONITOR); + clientNested.add(new File[]{f2}, NULL_PROGRESS_MONITOR); + clientNested.commit(new File[]{f2}, "init commit", null, null, NULL_PROGRESS_MONITOR); + + statuses = client.getStatus(new File[]{workDir}, NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); // on the other hand, nested repository parent should be listed as is on commandline assertStatus(statuses, workDir, f, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, nested, false, Status.STATUS_NORMAL, Status.STATUS_ADDED, Status.STATUS_ADDED, false); - - statuses = clientNested.getStatus(new File[] { nested }, NULL_PROGRESS_MONITOR); + + statuses = clientNested.getStatus(new File[]{nested}, NULL_PROGRESS_MONITOR); assertEquals(1, statuses.size()); assertStatus(statuses, nested, f2, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); } - - public void testSymlinkedFolder () throws Exception { + + public void testSymlinkedFolder() throws Exception { File folder1 = new File(workDir, "boo"); File file1 = new File(workDir, "old_file"); File folder2 = new File(workDir, "some_dir"); File file2_1 = new File(folder2, "some_file"); - + folder1.mkdirs(); folder2.mkdirs(); file1.createNewFile(); file2_1.createNewFile(); add(workDir); commit(workDir); - + GitClient client = getClient(workDir); Map statuses = client.getStatus(new File[0], NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, file1, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2_1, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); - + // create a symlink, not added to index String relPath = "../some_dir"; File link = new File(folder1, folder2.getName()); Files.createSymbolicLink(Paths.get(link.getAbsolutePath()), Paths.get(relPath)); assertTrue(Files.isSymbolicLink(Paths.get(link.getAbsolutePath()))); - statuses = client.getStatus(new File[] { link }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{link}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, link, false, Status.STATUS_NORMAL, Status.STATUS_ADDED, Status.STATUS_ADDED, false); - + // symlink is added to index, not yet committed - client.add(new File[] { link }, NULL_PROGRESS_MONITOR); - statuses = client.getStatus(new File[] { link }, NULL_PROGRESS_MONITOR); + client.add(new File[]{link}, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{link}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, link, true, Status.STATUS_ADDED, Status.STATUS_NORMAL, Status.STATUS_ADDED, false); - + // symlink is committed - client.commit(new File[] { link }, "commit symlink", null, null, NULL_PROGRESS_MONITOR); - statuses = client.getStatus(new File[] { link }, NULL_PROGRESS_MONITOR); + client.commit(new File[]{link}, "commit symlink", null, null, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{link}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, link, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); - + // symlink is deleted on disk Files.delete(Paths.get(link.getAbsolutePath())); assertFalse(Files.isSymbolicLink(Paths.get(link.getAbsolutePath()))); - statuses = client.getStatus(new File[] { link }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{link}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, link, true, Status.STATUS_NORMAL, Status.STATUS_REMOVED, Status.STATUS_REMOVED, false); - + // symlink is also deleted from index - client.remove(new File[] { link }, true, NULL_PROGRESS_MONITOR); - statuses = client.getStatus(new File[] { link }, NULL_PROGRESS_MONITOR); + client.remove(new File[]{link}, true, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{link}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, link, true, Status.STATUS_REMOVED, Status.STATUS_NORMAL, Status.STATUS_REMOVED, false); } - - public void testIgnoredSymlinkFile () throws Exception { + + public void testIgnoredSymlinkFile() throws Exception { File folder1 = new File(workDir, "boo"); File file1 = new File(workDir, "old_file"); File folder2 = new File(workDir, "some_dir"); File file2_1 = new File(folder2, "some_file"); - + folder1.mkdirs(); folder2.mkdirs(); file1.createNewFile(); file2_1.createNewFile(); add(workDir); commit(workDir); - + GitClient client = getClient(workDir); Map statuses = client.getStatus(new File[0], NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, file1, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2_1, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); - + // create a symlink, not added to index String relPath = "../some_dir/some_file"; File link = new File(folder1, file2_1.getName()); Files.createSymbolicLink(Paths.get(link.getAbsolutePath()), Paths.get(relPath)); assertTrue(Files.isSymbolicLink(Paths.get(link.getAbsolutePath()))); - statuses = client.getStatus(new File[] { link }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{link}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, link, false, Status.STATUS_NORMAL, Status.STATUS_ADDED, Status.STATUS_ADDED, false); - - client.ignore(new File[] { link }, NULL_PROGRESS_MONITOR); + + client.ignore(new File[]{link}, NULL_PROGRESS_MONITOR); assertEquals("/boo/some_file", read(new File(workDir, ".gitignore"))); - statuses = client.getStatus(new File[] { link }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{link}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, link, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false); } - - public void testIgnoredSymlinkFolder () throws Exception { + + public void testIgnoredSymlinkFolder() throws Exception { File folder1 = new File(workDir, "boo"); File file1 = new File(workDir, "old_file"); File folder2 = new File(workDir, "some_dir"); File file2_1 = new File(folder2, "some_file"); - + folder1.mkdirs(); folder2.mkdirs(); file1.createNewFile(); file2_1.createNewFile(); add(workDir); commit(workDir); - + GitClient client = getClient(workDir); Map statuses = client.getStatus(new File[0], NULL_PROGRESS_MONITOR); assertEquals(2, statuses.size()); assertStatus(statuses, workDir, file1, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); assertStatus(statuses, workDir, file2_1, true, Status.STATUS_NORMAL, Status.STATUS_NORMAL, Status.STATUS_NORMAL, false); - + // create a symlink, not added to index String relPath = "../some_dir"; File link = new File(folder1, folder2.getName()); Files.createSymbolicLink(Paths.get(link.getAbsolutePath()), Paths.get(relPath)); assertTrue(Files.isSymbolicLink(Paths.get(link.getAbsolutePath()))); - statuses = client.getStatus(new File[] { link }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{link}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, link, false, Status.STATUS_NORMAL, Status.STATUS_ADDED, Status.STATUS_ADDED, false); - - client.ignore(new File[] { link }, NULL_PROGRESS_MONITOR); + + client.ignore(new File[]{link}, NULL_PROGRESS_MONITOR); assertEquals("/boo/some_dir", read(new File(workDir, ".gitignore"))); - statuses = client.getStatus(new File[] { link }, NULL_PROGRESS_MONITOR); + statuses = client.getStatus(new File[]{link}, NULL_PROGRESS_MONITOR); assertStatus(statuses, workDir, link, false, Status.STATUS_NORMAL, Status.STATUS_IGNORED, Status.STATUS_ADDED, false); } - - public void testLastIndexModificationDate () throws Exception { + + public void testLastIndexModificationDate() throws Exception { File f = new File(workDir, "f"); - + GitClient client = getClient(workDir); write(f, "init"); - + // not yet added to the index => ts: -1 - GitStatus status = client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f); + GitStatus status = client.getStatus(new File[]{f}, NULL_PROGRESS_MONITOR).get(f); assertEquals(-1, status.getIndexEntryModificationDate()); - + add(f); // added => current timestamp - status = client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f); + status = client.getStatus(new File[]{f}, NULL_PROGRESS_MONITOR).get(f); long ts = f.lastModified(); assertEquals((ts / 1000) * 1000, (status.getIndexEntryModificationDate() / 1000) * 1000); - + commit(f); // still the same => current timestamp - status = client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f); + status = client.getStatus(new File[]{f}, NULL_PROGRESS_MONITOR).get(f); assertEquals((ts / 1000) * 1000, (status.getIndexEntryModificationDate() / 1000) * 1000); - + Thread.sleep(1000); write(f, "modification"); // modified => both should differ - status = client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f); + status = client.getStatus(new File[]{f}, NULL_PROGRESS_MONITOR).get(f); assertEquals((ts / 1000) * 1000, (status.getIndexEntryModificationDate() / 1000) * 1000); ts = f.lastModified(); assertNotSame((ts / 1000) * 1000, (status.getIndexEntryModificationDate() / 1000) * 1000); - + add(f); // updated -> both are the same - status = client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f); + status = client.getStatus(new File[]{f}, NULL_PROGRESS_MONITOR).get(f); assertEquals((ts / 1000) * 1000, (status.getIndexEntryModificationDate() / 1000) * 1000); - - client.remove(new File[] { f }, true, NULL_PROGRESS_MONITOR); + + client.remove(new File[]{f}, true, NULL_PROGRESS_MONITOR); // removed => ts: -1 - status = client.getStatus(new File[] { f }, NULL_PROGRESS_MONITOR).get(f); + status = client.getStatus(new File[]{f}, NULL_PROGRESS_MONITOR).get(f); assertEquals(-1, status.getIndexEntryModificationDate()); } - + private void assertStatus(Map statuses, File repository, File file, boolean tracked, Status headVsIndex, Status indexVsWorking, Status headVsWorking, boolean conflict, TestStatusListener monitor) { assertStatus(statuses, repository, file, tracked, headVsIndex, indexVsWorking, headVsWorking, conflict); assertStatus(monitor.notifiedStatuses, repository, file, tracked, headVsIndex, indexVsWorking, headVsWorking, conflict); } private static class TestStatusListener implements StatusListener { + private final Map notifiedStatuses; public TestStatusListener() { diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/SubmoduleTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/SubmoduleTest.java index 59c132e24e1a..a09e6d052615 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/SubmoduleTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/SubmoduleTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -28,7 +27,6 @@ import org.eclipse.jgit.transport.URIish; import org.netbeans.libs.git.ApiUtils; import org.netbeans.libs.git.GitClient; -import org.netbeans.libs.git.GitRepository; import org.netbeans.libs.git.GitRevisionInfo; import org.netbeans.libs.git.GitSubmoduleStatus; import org.netbeans.libs.git.jgit.AbstractGitTestCase; @@ -39,7 +37,7 @@ * @author Ondrej Vrabec */ public class SubmoduleTest extends AbstractGitTestCase { - + private Repository repository; private Repository repositorySM1; private Repository repositorySM2; @@ -53,7 +51,7 @@ public class SubmoduleTest extends AbstractGitTestCase { private File f2; private File f; - public SubmoduleTest (String testName) throws IOException { + public SubmoduleTest(String testName) throws IOException { super(testName); } @@ -62,7 +60,7 @@ 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); @@ -72,155 +70,154 @@ protected void setUp() throws Exception { 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); + 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); - + client.push("origin", Arrays.asList("refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()), + Arrays.asList("+refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch()), 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); + 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); - - + getClient(submoduleFolder1).push("origin", Arrays.asList("refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()), + Arrays.asList("+refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch()), 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); + 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); + getClient(submoduleFolder2).push("origin", Arrays.asList("refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()), + Arrays.asList("+refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch()), NULL_PROGRESS_MONITOR); } - - public void testStatusEmpty () throws Exception { + + public void testStatusEmpty() throws Exception { GitClient client = getClient(workDir); assertEquals(0, client.getSubmoduleStatus(new File[0], NULL_PROGRESS_MONITOR).size()); } - - public void testStatusUninitialized () throws Exception { + + public void testStatusUninitialized() throws Exception { prepareUninitializedWorkdir(); - + GitClient client = getClient(workDir); - Map status = client.getSubmoduleStatus(new File[] { f } , NULL_PROGRESS_MONITOR); + Map status = client.getSubmoduleStatus(new File[]{f}, NULL_PROGRESS_MONITOR); assertEquals(0, status.size()); - - status = client.getSubmoduleStatus(new File[] { submoduleFolder1 } , NULL_PROGRESS_MONITOR); + + status = client.getSubmoduleStatus(new File[]{submoduleFolder1}, NULL_PROGRESS_MONITOR); assertStatus(status.get(submoduleFolder1), GitSubmoduleStatus.StatusType.UNINITIALIZED, submoduleFolder1); - - status = client.getSubmoduleStatus(new File[] { submoduleFolder2 } , NULL_PROGRESS_MONITOR); + + status = client.getSubmoduleStatus(new File[]{submoduleFolder2}, NULL_PROGRESS_MONITOR); assertStatus(status.get(submoduleFolder2), GitSubmoduleStatus.StatusType.UNINITIALIZED, submoduleFolder2); - + status = client.getSubmoduleStatus(new File[0], NULL_PROGRESS_MONITOR); assertStatus(status.get(submoduleFolder1), GitSubmoduleStatus.StatusType.UNINITIALIZED, submoduleFolder1); assertStatus(status.get(submoduleFolder2), GitSubmoduleStatus.StatusType.UNINITIALIZED, submoduleFolder2); } - - public void testInitialize () throws Exception { + + public void testInitialize() throws Exception { prepareUninitializedWorkdir(); - + GitClient client = getClient(workDir); - Map status = client.getSubmoduleStatus(new File[] { f } , NULL_PROGRESS_MONITOR); + Map status = client.getSubmoduleStatus(new File[]{f}, NULL_PROGRESS_MONITOR); assertEquals(0, status.size()); - - status = client.getSubmoduleStatus(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR); + + status = client.getSubmoduleStatus(new File[]{submoduleFolder1}, NULL_PROGRESS_MONITOR); assertStatus(status.get(submoduleFolder1), GitSubmoduleStatus.StatusType.UNINITIALIZED, submoduleFolder1); - - status = client.initializeSubmodules(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR); + + status = client.initializeSubmodules(new File[]{submoduleFolder1}, NULL_PROGRESS_MONITOR); assertStatus(status.get(submoduleFolder1), GitSubmoduleStatus.StatusType.UNINITIALIZED, submoduleFolder1); } - - public void testUpdate () throws Exception { + + public void testUpdate() throws Exception { prepareUninitializedWorkdir(); - + GitClient client = getClient(workDir); - Map status = client.getSubmoduleStatus(new File[] { f } , NULL_PROGRESS_MONITOR); + Map status = client.getSubmoduleStatus(new File[]{f}, NULL_PROGRESS_MONITOR); assertEquals(0, status.size()); - - status = client.initializeSubmodules(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR); + + status = client.initializeSubmodules(new File[]{submoduleFolder1}, NULL_PROGRESS_MONITOR); assertStatus(status.get(submoduleFolder1), GitSubmoduleStatus.StatusType.UNINITIALIZED, submoduleFolder1); - status = client.updateSubmodules(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR); + status = client.updateSubmodules(new File[]{submoduleFolder1}, NULL_PROGRESS_MONITOR); assertStatus(status.get(submoduleFolder1), GitSubmoduleStatus.StatusType.INITIALIZED, submoduleFolder1); } - - public void testStatusCommit () throws Exception { + + 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); - + 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); + subClient.checkoutRevision(getDefaultBranch(), true, NULL_PROGRESS_MONITOR); GitRevisionInfo previous = subClient.log("HEAD", NULL_PROGRESS_MONITOR); write(f1, "change"); - subClient.add(new File[] { f1 }, NULL_PROGRESS_MONITOR); - Map status = client.getSubmoduleStatus(new File[] { submoduleFolder1 }, NULL_PROGRESS_MONITOR); + subClient.add(new File[]{f1}, NULL_PROGRESS_MONITOR); + Map status = client.getSubmoduleStatus(new File[]{submoduleFolder1}, NULL_PROGRESS_MONITOR); assertEquals(GitSubmoduleStatus.StatusType.INITIALIZED, status.get(submoduleFolder1).getStatus()); assertEquals(previous.getRevision(), status.get(submoduleFolder1).getReferencedCommitId()); - - subClient.commit(new File[] { f1 }, "change commit", null, null, NULL_PROGRESS_MONITOR); + + 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); + status = client.getSubmoduleStatus(new File[]{submoduleFolder1}, NULL_PROGRESS_MONITOR); assertEquals(GitSubmoduleStatus.StatusType.REV_CHECKED_OUT, status.get(submoduleFolder1).getStatus()); assertEquals(previous.getRevision(), status.get(submoduleFolder1).getReferencedCommitId()); } - private void prepareUninitializedWorkdir () throws Exception { + 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"); - + 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.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); - + client.push("origin", Arrays.asList("refs/heads/" + getDefaultBranch() + ":refs/heads/" + getDefaultBranch()), + Arrays.asList("+refs/heads/" + getDefaultBranch() + ":refs/remotes/origin/" + getDefaultBranch()), NULL_PROGRESS_MONITOR); + Utils.deleteRecursively(submoduleFolder1); Utils.deleteRecursively(submoduleFolder2); assertFalse(submoduleFolder1.exists()); assertFalse(submoduleFolder2.exists()); - client.reset("master", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); + client.reset(getDefaultBranch(), GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); assertTrue(submoduleFolder1.exists()); assertTrue(submoduleFolder2.exists()); // must clear temporary git pool instances @@ -228,7 +225,7 @@ private void prepareUninitializedWorkdir () throws Exception { ApiUtils.clearRepositoryPool(); } - private void assertStatus (GitSubmoduleStatus status, GitSubmoduleStatus.StatusType statusKind, + private void assertStatus(GitSubmoduleStatus status, GitSubmoduleStatus.StatusType statusKind, File submoduleRoot) { assertEquals(statusKind, status.getStatus()); assertEquals(submoduleRoot, status.getSubmoduleFolder()); diff --git a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/UpdateRefTest.java b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/UpdateRefTest.java index 45f3f994a497..2e86d451c082 100644 --- a/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/UpdateRefTest.java +++ b/ide/libs.git/test/unit/src/org/netbeans/libs/git/jgit/commands/UpdateRefTest.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.netbeans.libs.git.jgit.commands; import java.io.File; @@ -34,10 +33,11 @@ * @author ondra */ public class UpdateRefTest extends AbstractGitTestCase { + private Repository repository; private File workDir; - public UpdateRefTest (String testName) throws IOException { + public UpdateRefTest(String testName) throws IOException { super(testName); } @@ -48,91 +48,91 @@ protected void setUp() throws Exception { repository = getRepository(getLocalGitRepository()); } - public void testNotAttempted () throws Exception { + public void testNotAttempted() throws Exception { File f = new File(workDir, "f"); write(f, "init"); add(f); commit(f); - + write(f, "modi"); add(f); commit(f); - + GitClient client = getClient(workDir); GitRevisionInfo info = client.log("HEAD", NULL_PROGRESS_MONITOR); - + client.reset("HEAD~1", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); - + GitRefUpdateResult res = client.updateReference("HEAD", info.getRevision(), NULL_PROGRESS_MONITOR); assertEquals(GitRefUpdateResult.NOT_ATTEMPTED, res); } - public void testMoveMergeCommit () throws Exception { + public void testMoveMergeCommit() throws Exception { File f = new File(workDir, "f"); write(f, "init"); add(f); commit(f); - + write(f, "modif"); add(f); commit(f); - + GitClient client = getClient(workDir); GitRevisionInfo info = client.log("HEAD", NULL_PROGRESS_MONITOR); - + client.reset("HEAD~1", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); - - GitRefUpdateResult res = client.updateReference("master", info.getRevision(), NULL_PROGRESS_MONITOR); + + GitRefUpdateResult res = client.updateReference(getDefaultBranch(), info.getRevision(), NULL_PROGRESS_MONITOR); assertEquals(GitRefUpdateResult.FAST_FORWARD, res); - Ref ref = repository.findRef("master"); + Ref ref = repository.findRef(getDefaultBranch()); assertNotNull(ref); ReflogReader reflogReader = repository.getRefDatabase().getReflogReader(ref); assertEquals("merge " + info.getRevision() + ": Fast-forward", reflogReader.getLastEntry().getComment()); } - public void testMoveMergeRef () throws Exception { + public void testMoveMergeRef() throws Exception { File f = new File(workDir, "f"); write(f, "init"); add(f); commit(f); - + write(f, "modif"); add(f); commit(f); - + GitClient client = getClient(workDir); client.createBranch("BRANCH", "HEAD", NULL_PROGRESS_MONITOR); - + client.reset("HEAD~1", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); - - GitRefUpdateResult res = client.updateReference("master", "BRANCH", NULL_PROGRESS_MONITOR); + + GitRefUpdateResult res = client.updateReference(getDefaultBranch(), "BRANCH", NULL_PROGRESS_MONITOR); assertEquals(GitRefUpdateResult.FAST_FORWARD, res); - Ref ref = repository.findRef("master"); + Ref ref = repository.findRef(getDefaultBranch()); assertNotNull(ref); ReflogReader reflogReader = repository.getRefDatabase().getReflogReader(ref); assertEquals("merge BRANCH: Fast-forward", reflogReader.getLastEntry().getComment()); } // must fail if would end in a non FF update - public void testMoveMergeRejected () throws Exception { + public void testMoveMergeRejected() throws Exception { File f = new File(workDir, "f"); write(f, "init"); add(f); commit(f); - + write(f, "modif"); add(f); commit(f); - + GitClient client = getClient(workDir); client.createBranch("BRANCH", "HEAD", NULL_PROGRESS_MONITOR); - + client.reset("HEAD~1", GitClient.ResetType.HARD, NULL_PROGRESS_MONITOR); - + write(f, "modif2"); add(f); commit(f); - GitRefUpdateResult res = client.updateReference("master", "BRANCH", NULL_PROGRESS_MONITOR); + GitRefUpdateResult res = client.updateReference(getDefaultBranch(), "BRANCH", NULL_PROGRESS_MONITOR); assertEquals(GitRefUpdateResult.REJECTED, res); } }