Package org.eclipse.jgit.storage.file

Examples of org.eclipse.jgit.storage.file.FileBasedConfig


  }

  private FileBasedConfig configFor(File gitDir) throws IOException,
      ConfigInvalidException {
    File configPath = new File(gitDir, Constants.CONFIG);
    FileBasedConfig cfg = new FileBasedConfig(configPath, FS.DETECTED);
    cfg.load();
    return cfg;
  }
View Full Code Here


    CleanupThread.deleteOnShutdown(tmp);
    if (!tmp.delete() || !tmp.mkdir())
      throw new IOException("Cannot create " + tmp);

    mockSystemReader = new MockSystemReader();
    mockSystemReader.userGitConfig = new FileBasedConfig(new File(tmp,
        "usergitconfig"), FS.DETECTED);
    ceilTestDirectories(getCeilings());
    SystemReader.setInstance(mockSystemReader);

    final long now = mockSystemReader.getCurrentTime();
View Full Code Here

    BranchBuilder bb = tr.branch("refs/heads/side");
    bb.commit().add("A", "A").add("B", "B").create();
    RevCommit second = bb.commit().add("A", "A2").add("B", "B2").create();

    // Convert the repo to be bare
    FileBasedConfig cfg = repo.getConfig();
    cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_BARE, true);
    cfg.save();
    Git git = Git.open(repo.getDirectory());
    repo = (FileRepository) git.getRepository();

    // check for the unborn branch master. HEAD should point to master and
    // master doesn't exist.
View Full Code Here

    }
  }

  @Test
  public void testRemoteNames() throws Exception {
    FileBasedConfig config = db.getConfig();
    config.setBoolean(ConfigConstants.CONFIG_REMOTE_SECTION,
        "origin", "dummy", true);
    config.setBoolean(ConfigConstants.CONFIG_REMOTE_SECTION,
        "ab/c", "dummy", true);
    config.save();
    assertEquals("[ab/c, origin]",
        new TreeSet<String>(db.getRemoteNames()).toString());

    // one-level deep remote branch
    assertEquals("master",
View Full Code Here

        .getRepository()
        .getConfig()
        .getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, "test",
            ConfigConstants.CONFIG_KEY_REBASE, false));

    FileBasedConfig userConfig = SystemReader.getInstance().openUserConfig(
        null, git.getRepository().getFS());
    userConfig.setString(ConfigConstants.CONFIG_BRANCH_SECTION, null,
        ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE,
        ConfigConstants.CONFIG_KEY_ALWAYS);
    userConfig.save();
    directory = createTempDirectory("testCloneRepository2");
    command = Git.cloneRepository();
    command.setDirectory(directory);
    command.setURI(fileUri());
    git2 = command.call();
    addRepoToClose(git2.getRepository());
    assertTrue(git2
        .getRepository()
        .getConfig()
        .getBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, "test",
            ConfigConstants.CONFIG_KEY_REBASE, false));

    userConfig.setString(ConfigConstants.CONFIG_BRANCH_SECTION, null,
        ConfigConstants.CONFIG_KEY_AUTOSETUPREBASE,
        ConfigConstants.CONFIG_KEY_REMOTE);
    userConfig.save();
    directory = createTempDirectory("testCloneRepository2");
    command = Git.cloneRepository();
    command.setDirectory(directory);
    command.setURI(fileUri());
    git2 = command.call();
View Full Code Here

    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    }

    // Save path and URL to parent repository's .gitmodules file
    FileBasedConfig modulesConfig = new FileBasedConfig(new File(
        repo.getWorkTree(), Constants.DOT_GIT_MODULES), repo.getFS());
    try {
      modulesConfig.load();
      modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
          path, ConfigConstants.CONFIG_KEY_PATH, path);
      modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
          path, ConfigConstants.CONFIG_KEY_URL, uri);
      modulesConfig.save();
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    } catch (ConfigInvalidException e) {
      throw new JGitInternalException(e.getMessage(), e);
    }
View Full Code Here

        ent.setObjectId(id);
      }
    });
    editor.commit();

    FileBasedConfig modulesConfig = new FileBasedConfig(new File(
        db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
    modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
        ConfigConstants.CONFIG_KEY_PATH, path);
    String url = "git://server/repo.git";
    modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
        ConfigConstants.CONFIG_KEY_URL, url);
    modulesConfig.save();

    Repository subRepo = Git.cloneRepository()
        .setURI(db.getDirectory().toURI().toString())
        .setDirectory(new File(db.getWorkTree(), path)).call()
        .getRepository();
View Full Code Here

      }
    });
    editor.commit();

    String base = "git://server/repo.git";
    FileBasedConfig config = db.getConfig();
    config.setString(ConfigConstants.CONFIG_REMOTE_SECTION,
        Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL,
        base);
    config.save();

    FileBasedConfig modulesConfig = new FileBasedConfig(new File(
        db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
    modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
        ConfigConstants.CONFIG_KEY_PATH, path);
    String current = "git://server/repo.git";
    modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
        ConfigConstants.CONFIG_KEY_URL, current);
    modulesConfig.save();

    Repository subRepo = Git.cloneRepository()
        .setURI(db.getDirectory().toURI().toString())
        .setDirectory(new File(db.getWorkTree(), path)).call()
        .getRepository();
    assertNotNull(subRepo);
    addRepoToClose(subRepo);

    SubmoduleWalk generator = SubmoduleWalk.forIndex(db);
    assertTrue(generator.next());
    assertNull(generator.getConfigUrl());
    assertEquals(current, generator.getModulesUrl());

    modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
        ConfigConstants.CONFIG_KEY_URL, "../sub.git");
    modulesConfig.save();

    SubmoduleSyncCommand command = new SubmoduleSyncCommand(db);
    Map<String, String> synced = command.call();
    assertNotNull(synced);
    assertEquals(1, synced.size());
View Full Code Here

  }

  @Test
  public void testAutoCRLFInput() throws Exception {
    Git git = new Git(db);
    FileBasedConfig config = db.getConfig();

    // Make sure core.autocrlf is false before adding
    config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE);
    config.save();

    // File is already in repository with CRLF
    writeTrashFile("crlf.txt", "this\r\ncontains\r\ncrlf\r\n");
    git.add().addFilepattern("crlf.txt").call();
    git.commit().setMessage("Add crlf.txt").call();

    // Now set core.autocrlf to input
    config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.INPUT);
    config.save();

    FileTreeIterator iterator = new FileTreeIterator(db);
    IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
    diff.diff();
View Full Code Here

  public void addSubmoduleWithExistingSubmoduleDefined() throws Exception {
    String path1 = "sub1";
    String url1 = "git://server/repo1.git";
    String path2 = "sub2";

    FileBasedConfig modulesConfig = new FileBasedConfig(new File(
        db.getWorkTree(), Constants.DOT_GIT_MODULES), db.getFS());
    modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
        path1, ConfigConstants.CONFIG_KEY_PATH, path1);
    modulesConfig.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
        path1, ConfigConstants.CONFIG_KEY_URL, url1);
    modulesConfig.save();

    Git git = new Git(db);
    writeTrashFile("file.txt", "content");
    git.add().addFilepattern("file.txt").call();
    assertNotNull(git.commit().setMessage("create file").call());

    SubmoduleAddCommand command = new SubmoduleAddCommand(db);
    command.setPath(path2);
    String url2 = db.getDirectory().toURI().toString();
    command.setURI(url2);
    Repository r = command.call();
    assertNotNull(r);
    addRepoToClose(r);

    modulesConfig.load();
    assertEquals(path1, modulesConfig.getString(
        ConfigConstants.CONFIG_SUBMODULE_SECTION, path1,
        ConfigConstants.CONFIG_KEY_PATH));
    assertEquals(url1, modulesConfig.getString(
        ConfigConstants.CONFIG_SUBMODULE_SECTION, path1,
        ConfigConstants.CONFIG_KEY_URL));
    assertEquals(path2, modulesConfig.getString(
        ConfigConstants.CONFIG_SUBMODULE_SECTION, path2,
        ConfigConstants.CONFIG_KEY_PATH));
    assertEquals(url2, modulesConfig.getString(
        ConfigConstants.CONFIG_SUBMODULE_SECTION, path2,
        ConfigConstants.CONFIG_KEY_URL));
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.storage.file.FileBasedConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.