コード例 #1
0
ファイル: IndexDiffTest.java プロジェクト: fpringvaldsen/jgit
  @Test
  public void testAutoCRLFInput() throws Exception {
    try (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();

      assertTrue(
          "Expected no modified files, but there were: " + diff.getModified(),
          diff.getModified().isEmpty());
    }
  }
コード例 #2
0
  @Before
  public void setUp() throws Exception {
    super.setUp();

    final TestRepository<FileRepository> src = createTestRepository();
    final String srcName = src.getRepository().getDirectory().getName();

    ServletContextHandler app = server.addContext("/git");
    GitServlet gs = new GitServlet();
    gs.setRepositoryResolver(
        new RepositoryResolver<HttpServletRequest>() {
          public Repository open(HttpServletRequest req, String name)
              throws RepositoryNotFoundException, ServiceNotEnabledException {
            if (!name.equals(srcName)) throw new RepositoryNotFoundException(name);

            final Repository db = src.getRepository();
            db.incrementOpen();
            return db;
          }
        });
    app.addServlet(new ServletHolder(gs), "/*");

    server.setUp();

    remoteRepository = src.getRepository();
    remoteURI = toURIish(app, srcName);

    FileBasedConfig cfg = remoteRepository.getConfig();
    cfg.setBoolean("http", null, "receivepack", true);
    cfg.save();

    a_blob = src.blob("a");
  }
コード例 #3
0
  @Test
  public void dontPackHEAD_bare() throws Exception {
    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.
    assertEquals(repo.exactRef("HEAD").getTarget().getName(), "refs/heads/master");
    assertNull(repo.exactRef("HEAD").getTarget().getObjectId());
    gc.packRefs();
    assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE);
    assertEquals(repo.exactRef("HEAD").getTarget().getName(), "refs/heads/master");
    assertNull(repo.exactRef("HEAD").getTarget().getObjectId());

    // check for non-detached HEAD
    repo.updateRef(Constants.HEAD).link("refs/heads/side");
    gc.packRefs();
    assertSame(repo.exactRef("HEAD").getStorage(), Storage.LOOSE);
    assertEquals(repo.exactRef("HEAD").getTarget().getObjectId(), second.getId());
  }
コード例 #4
0
  public Repository call() throws JGitInternalException {
    checkCallable();
    if (path == null || path.length() == 0)
      throw new IllegalArgumentException(JGitText.get().pathNotConfigured);
    if (uri == null || uri.length() == 0)
      throw new IllegalArgumentException(JGitText.get().uriNotConfigured);

    try {
      if (submoduleExists())
        throw new JGitInternalException(MessageFormat.format(JGitText.get().submoduleExists, path));
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    }

    // Clone submodule repository
    File moduleDirectory = SubmoduleWalk.getSubmoduleDirectory(repo, path);
    CloneCommand clone = Git.cloneRepository();
    clone.setDirectory(moduleDirectory);
    clone.setURI(uri);
    if (monitor != null) clone.setProgressMonitor(monitor);
    if (credentialsProvider != null) clone.setCredentialsProvider(credentialsProvider);
    Repository subRepo = clone.call().getRepository();

    // Save submodule URL to parent repository's config
    StoredConfig config = repo.getConfig();
    config.setString(
        ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL, uri);
    try {
      config.save();
    } 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());
    modulesConfig.setString(
        ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_PATH, path);
    modulesConfig.setString(
        ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL, uri);
    try {
      modulesConfig.save();
    } catch (IOException e) {
      throw new JGitInternalException(e.getMessage(), e);
    }

    AddCommand add = new AddCommand(repo);
    // Add .gitmodules file to parent repository's index
    add.addFilepattern(Constants.DOT_GIT_MODULES);
    // Add submodule directory to parent repository's index
    add.addFilepattern(path);
    try {
      add.call();
    } catch (NoFilepatternException e) {
      throw new JGitInternalException(e.getMessage(), e);
    }

    return subRepo;
  }
コード例 #5
0
 private void updateGerritConfig(SitePaths sitePaths, String newSecureStore)
     throws IOException, ConfigInvalidException {
   log.info("Set gerrit.secureStoreClass property of gerrit.config to {}", newSecureStore);
   FileBasedConfig config = new FileBasedConfig(sitePaths.gerrit_config.toFile(), FS.DETECTED);
   config.load();
   config.setString("gerrit", null, "secureStoreClass", newSecureStore);
   config.save();
 }
コード例 #6
0
ファイル: PluginDaemonTest.java プロジェクト: kinglcc/gerrit
 protected void setPluginConfigString(String name, String value)
     throws IOException, ConfigInvalidException {
   SitePaths sitePath = new SitePaths(testSite);
   FileBasedConfig cfg = getGerritConfigFile(sitePath);
   cfg.load();
   cfg.setString("plugin", pluginName, name, value);
   cfg.save();
 }
コード例 #7
0
ファイル: GitblitAuthority.java プロジェクト: noelmac/gitblit
 private void updateAuthorityConfig(UserCertificateModel ucm) {
   File certificatesConfigFile = new File(folder, X509Utils.CA_CONFIG);
   FileBasedConfig config = new FileBasedConfig(certificatesConfigFile, FS.detect());
   if (certificatesConfigFile.exists()) {
     try {
       config.load();
     } catch (Exception e) {
       Utils.showException(GitblitAuthority.this, e);
     }
   }
   ucm.update(config);
   try {
     config.save();
   } catch (Exception e) {
     Utils.showException(GitblitAuthority.this, e);
   }
 }
コード例 #8
0
  @Test
  public void testListRemote_Smart_UploadPackDisabled() throws Exception {
    FileRepository src = remoteRepository.getRepository();
    final FileBasedConfig cfg = src.getConfig();
    cfg.setBoolean("http", null, "uploadpack", false);
    cfg.save();

    Repository dst = createBareRepository();
    Transport t = Transport.open(dst, smartAuthNoneURI);
    try {
      try {
        t.openFetch();
        fail("connection opened even though service disabled");
      } catch (TransportException err) {
        String exp = smartAuthNoneURI + ": git-upload-pack not permitted";
        assertEquals(exp, err.getMessage());
      }
    } finally {
      t.close();
    }
  }