Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.StoredConfig


    // and commit it
    source.add().addFilepattern("SomeFile.txt").call();
    source.commit().setMessage("Initial commit for source").call();

    // configure the target repo to connect to the source via "origin"
    StoredConfig targetConfig = dbTarget.getConfig();
    targetConfig.setString("branch", "master", "remote", "origin");
    targetConfig
        .setString("branch", "master", "merge", "refs/heads/master");
    RemoteConfig config = new RemoteConfig(targetConfig, "origin");

    config
        .addURI(new URIish(source.getRepository().getWorkTree()
            .getAbsolutePath()));
    config.addFetchRefSpec(new RefSpec(
        "+refs/heads/*:refs/remotes/origin/*"));
    config.update(targetConfig);
    targetConfig.save();

    targetFile = new File(dbTarget.getWorkTree(), "SomeFile.txt");
    // make sure we have the same content
    target.pull().call();
    assertFileContentsEqual(targetFile, "Hello world");
View Full Code Here


    rup.setNewObjectId(initialCommit.getId());
    rup.forceUpdate();

    Repository localRepository = createWorkRepository();
    Git localGit = new Git(localRepository);
    StoredConfig config = localRepository.getConfig();
    RemoteConfig rc = new RemoteConfig(config, "origin");
    rc.addURI(new URIish(remoteRepository.getDirectory().getAbsolutePath()));
    rc.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
    rc.update(config);
    config.save();
    FetchResult res = localGit.fetch().setRemote("origin").call();
    assertFalse(res.getTrackingRefUpdates().isEmpty());
    rup = localRepository.updateRef("refs/heads/master");
    rup.setNewObjectId(initialCommit.getId());
    rup.forceUpdate();
View Full Code Here

  }

  @Test
  public void emptyRepositoryFormatVersion() throws Exception {
    Repository r = createWorkRepository();
    StoredConfig config = r.getConfig();
    config.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "");
    config.save();

    new FileRepository(r.getDirectory());
  }
View Full Code Here

  }

  @Test
  public void invalidRepositoryFormatVersion() throws Exception {
    Repository r = createWorkRepository();
    StoredConfig config = r.getConfig();
    config.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "notanumber");
    config.save();

    try {
      new FileRepository(r.getDirectory());
      fail("IllegalArgumentException not thrown");
    } catch (IllegalArgumentException e) {
View Full Code Here

  }

  @Test
  public void unknownRepositoryFormatVersion() throws Exception {
    Repository r = createWorkRepository();
    StoredConfig config = r.getConfig();
    config.setLong(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 1);
    config.save();

    try {
      new FileRepository(r.getDirectory());
      fail("IOException not thrown");
    } catch (IOException e) {
View Full Code Here

        | ASSUME_UNCHANGED));
  }

  @Test
  public void testExecutableRetention() throws Exception {
    StoredConfig config = db.getConfig();
    config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_FILEMODE, true);
    config.save();

    FS executableFs = new FS() {

      public boolean supportsExecute() {
        return true;
      }

      public boolean setExecute(File f, boolean canExec) {
        return true;
      }

      public ProcessBuilder runInShell(String cmd, String[] args) {
        return null;
      }

      public boolean retryFailedLockFileCommit() {
        return false;
      }

      public FS newInstance() {
        return this;
      }

      protected File discoverGitPrefix() {
        return null;
      }

      public boolean canExecute(File f) {
        return true;
      }

      @Override
      public boolean isCaseSensitive() {
        return false;
      }
    };

    Git git = Git.open(db.getDirectory(), executableFs);
    String path = "a.txt";
    writeTrashFile(path, "content");
    git.add().addFilepattern(path).call();
    RevCommit commit1 = git.commit().setMessage("commit").call();
    TreeWalk walk = TreeWalk.forPath(db, path, commit1.getTree());
    assertNotNull(walk);
    assertEquals(FileMode.EXECUTABLE_FILE, walk.getFileMode(0));

    FS nonExecutableFs = new FS() {

      public boolean supportsExecute() {
        return false;
      }

      public boolean setExecute(File f, boolean canExec) {
        return false;
      }

      public ProcessBuilder runInShell(String cmd, String[] args) {
        return null;
      }

      public boolean retryFailedLockFileCommit() {
        return false;
      }

      public FS newInstance() {
        return this;
      }

      protected File discoverGitPrefix() {
        return null;
      }

      public boolean canExecute(File f) {
        return false;
      }

      @Override
      public boolean isCaseSensitive() {
        return false;
      }
    };

    config = db.getConfig();
    config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
        ConfigConstants.CONFIG_KEY_FILEMODE, false);
    config.save();

    Git git2 = Git.open(db.getDirectory(), nonExecutableFs);
    writeTrashFile(path, "content2");
    git2.add().addFilepattern(path).call();
    RevCommit commit2 = git2.commit().setMessage("commit2").call();
View Full Code Here

    // create other repository
    Repository remoteRepository = createWorkRepository();
    remoteGit = new Git(remoteRepository);

    // setup the first repository to fetch from the second repository
    final StoredConfig config = db.getConfig();
    RemoteConfig remoteConfig = new RemoteConfig(config, "test");
    URIish uri = new URIish(remoteRepository.getDirectory().toURI().toURL());
    remoteConfig.addURI(uri);
    remoteConfig.update(config);
    config.save();
  }
View Full Code Here

    // create other repository
    Repository db2 = createWorkRepository();

    // setup the first repository
    final StoredConfig config = db.getConfig();
    RemoteConfig remoteConfig = new RemoteConfig(config, "test");
    URIish uri = new URIish(db2.getDirectory().toURI().toURL());
    remoteConfig.addURI(uri);
    remoteConfig.update(config);
    config.save();

    Git git1 = new Git(db);
    // create some refs via commits and tag
    RevCommit commit = git1.commit().setMessage("initial commit").call();
    Ref tagRef = git1.tag().setName("tag").call();
View Full Code Here

    RefUpdate trackingBranchRefUpdate = db.updateRef(trackingBranch);
    trackingBranchRefUpdate.setNewObjectId(commit1.getId());
    trackingBranchRefUpdate.update();

    final StoredConfig config = db.getConfig();
    RemoteConfig remoteConfig = new RemoteConfig(config, remote);
    URIish uri = new URIish(db2.getDirectory().toURI().toURL());
    remoteConfig.addURI(uri);
    remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/"
        + remote + "/*"));
    remoteConfig.update(config);
    config.save();


    RevCommit commit2 = git.commit().setMessage("Commit to push").call();

    RefSpec spec = new RefSpec(branch + ":" + branch);
View Full Code Here

  @Test
  public void testPushRefUpdate() throws Exception {
    Git git = new Git(db);
    Git git2 = new Git(createBareRepository());

    final StoredConfig config = git.getRepository().getConfig();
    RemoteConfig remoteConfig = new RemoteConfig(config, "test");
    URIish uri = new URIish(git2.getRepository().getDirectory().toURI()
        .toURL());
    remoteConfig.addURI(uri);
    remoteConfig.addPushRefSpec(new RefSpec("+refs/heads/*:refs/heads/*"));
    remoteConfig.update(config);
    config.save();

    writeTrashFile("f", "content of f");
    git.add().addFilepattern("f").call();
    RevCommit commit = git.commit().setMessage("adding f").call();

View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.StoredConfig

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.