org.eclipse.jgit.api.Git.add()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(14.4k)|赞(0)|评价(0)|浏览(200)

本文整理了Java中org.eclipse.jgit.api.Git.add()方法的一些代码示例,展示了Git.add()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Git.add()方法的具体详情如下:
包路径:org.eclipse.jgit.api.Git
类名称:Git
方法名:add

Git.add介绍

[英]Return a command object to execute a Add command
[中]返回命令对象以执行添加命令

代码示例

代码示例来源:origin: gocd/gocd

public void checkin(final GoConfigRevision rev) throws Exception {
  try {
    if (rev.equals(getCurrentRevision())) {
      return;
    }
    final File file = new File(workingDir, CRUISE_CONFIG_XML);
    FileUtils.writeStringToFile(file, rev.getContent(), UTF_8);
    final AddCommand addCommand = git.add();
    doLocked(new VoidThrowingFn<Exception>() {
      public void run() throws Exception {
        addCommand.addFilepattern(CRUISE_CONFIG_XML).call();
        git.commit().setAuthor(rev.getUsername(), STUDIOS_PRODUCT).setMessage(rev.getComment()).call();
      }
    });
  } catch (Exception e) {
    LOGGER.error("[CONFIG SAVE] Check-in failed for {}", rev.toString(), e);
    throw e;
  }
}

代码示例来源:origin: apache/incubator-gobblin

@Test (dependsOnMethods = "testDelete")
public void testGitCreate() throws Exception {
 // push a new config file
 File testFlowFile = new File(GIT_CLONE_DIR + "/gobblin-config/testGroup/testFlow.pull");
 testFlowFile.getParentFile().mkdirs();
 Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value20\n", testFlowFile, Charsets.UTF_8);
 Collection<Spec> specs = this.gobblinServiceManager.flowCatalog.getSpecs();
 Assert.assertTrue(specs.size() == 0);
 // add, commit, push
 this.gitForPush.add().addFilepattern("gobblin-config/testGroup/testFlow.pull").call();
 this.gitForPush.commit().setMessage("second commit").call();
 this.gitForPush.push().setRemote("origin").setRefSpecs(new RefSpec("master")).call();
 // polling is every 5 seconds, so wait twice as long and check
 TimeUnit.SECONDS.sleep(10);
 specs = this.gobblinServiceManager.flowCatalog.getSpecs();
 Assert.assertTrue(specs.size() == 1);
 FlowSpec spec = (FlowSpec) (specs.iterator().next());
 Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow"));
 Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow");
 Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup");
 Assert.assertEquals(spec.getConfig().getString("param1"), "value20");
}

代码示例来源:origin: apache/incubator-gobblin

@Test(dependsOnMethods = "testAddConfig")
public void testUpdateConfig() throws IOException, GitAPIException, URISyntaxException {
 // push an updated config file
 Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value2\n", testFlowFile, Charsets.UTF_8);
 // add, commit, push
 this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName()))
   .call();
 this.gitForPush.commit().setMessage("Third commit").call();
 this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
 this.gitConfigMonitor.processGitConfigChanges();
 Collection<Spec> specs = this.flowCatalog.getSpecs();
 Assert.assertTrue(specs.size() == 1);
 FlowSpec spec = (FlowSpec) (specs.iterator().next());
 Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow"));
 Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow");
 Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup");
 Assert.assertEquals(spec.getConfig().getString("param1"), "value2");
}

代码示例来源:origin: apache/incubator-gobblin

@Test
public void testAddConfig() throws IOException, GitAPIException, URISyntaxException {
 // push a new config file
 this.testGroupDir.mkdirs();
 this.testFlowFile.createNewFile();
 Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value1\n", testFlowFile, Charsets.UTF_8);
 // add, commit, push
 this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName()))
   .call();
 this.gitForPush.commit().setMessage("Second commit").call();
 this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
 this.gitConfigMonitor.processGitConfigChanges();
 Collection<Spec> specs = this.flowCatalog.getSpecs();
 Assert.assertTrue(specs.size() == 1);
 FlowSpec spec = (FlowSpec) (specs.iterator().next());
 Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow"));
 Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow");
 Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup");
 Assert.assertEquals(spec.getConfig().getString("param1"), "value1");
}

代码示例来源:origin: jphp-group/jphp

@Signature
public void add(String filePattern, ArrayMemory settings) throws GitAPIException {
  AddCommand addCommand = getWrappedObject().add();
  addCommand.addFilepattern(filePattern);
  if (settings != null && settings.isNotNull()) {
    addCommand.setUpdate(settings.valueOfIndex("update").toBoolean());
  }
  DirCache dirCache = addCommand.call();
}

代码示例来源:origin: apache/incubator-gobblin

this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName()))
  .call();
this.gitForPush.commit().setMessage("Seventh commit").call();

代码示例来源:origin: apache/incubator-gobblin

private void addEdge(File edgeDir, File edgeFile, String fileContents) throws IOException, GitAPIException {
 createNewFile(edgeDir, edgeFile, fileContents);
 // add, commit, push edge
 this.gitForPush.add().addFilepattern(formEdgeFilePath(edgeDir.getParentFile().getName(), edgeDir.getName(), edgeFile.getName())).call();
 this.gitForPush.commit().setMessage("Edge commit").call();
 this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
}

代码示例来源:origin: apache/incubator-gobblin

@Test (dependsOnMethods = "testAddNode")
public void testUpdateEdge()
  throws IOException, GitAPIException, URISyntaxException, ExecutionException, InterruptedException {
 //Update edge1 file
 String fileContents = buildEdgeFileContents("node1", "node2", "edge1", "value2");
 addEdge(this.edge1Dir, this.edge1File, fileContents);
 // add, commit, push
 this.gitForPush.add().addFilepattern(formEdgeFilePath(this.edge1Dir.getParentFile().getName(), this.edge1Dir.getName(), this.edge1File.getName())).call();
 this.gitForPush.commit().setMessage("Edge commit").call();
 this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
 this.gitFlowGraphMonitor.processGitConfigChanges();
 //Check if new edge1 has been added to the FlowGraph
 testIfEdgeSuccessfullyAdded("node1", "node2", "edge1", "value2");
}

代码示例来源:origin: apache/incubator-gobblin

this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName()))
  .call();
this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile2.getName()))
  .call();
this.gitForPush.commit().setMessage("Fifth commit").call();
this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile2.getName()))
  .call();
this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile3.getName()))
  .call();
this.gitForPush.commit().setMessage("Sixth commit").call();

代码示例来源:origin: apache/incubator-gobblin

private void addNode(File nodeDir, File nodeFile, String fileContents) throws IOException, GitAPIException {
 createNewFile(nodeDir, nodeFile, fileContents);
 // add, commit, push node
 this.gitForPush.add().addFilepattern(formNodeFilePath(nodeDir.getName(), nodeFile.getName())).call();
 this.gitForPush.commit().setMessage("Node commit").call();
 this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
}

代码示例来源:origin: apache/incubator-gobblin

gitForPush.add().addFilepattern(formNodeFilePath(flowGraphDir, nodeDir.getName(), nodeFile.getName())).call();
gitForPush.commit().setMessage("Node commit").call();
gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call();

代码示例来源:origin: apache/incubator-gobblin

this.gitForPush.add().addFilepattern(formNodeFilePath(this.node1Dir.getName(), this.node1File.getName())).call();
this.gitForPush.add().addFilepattern(formNodeFilePath(this.node2Dir.getName(), this.node2File.getName())).call();
this.gitForPush.commit().setMessage("Add nodes commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.add().addFilepattern(formEdgeFilePath(this.edge1Dir.getParentFile().getName(), this.edge1Dir.getName(), this.edge1File.getName())).call();
this.gitForPush.commit().setMessage("Add nodes and edges commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.add().addFilepattern(formNodeFilePath(this.node1Dir.getName(), this.node1File.getName())).call();
this.gitForPush.commit().setMessage("Add node1 commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();

代码示例来源:origin: FlowCI/flow-platform

private void commitSomething(Path path) {
  try (Git git = Git.open(path.toFile())) {
    Path emptyFilePath = Paths.get(path.toString(), EMPTY_FILE);
    try {
      Files.createFile(emptyFilePath);
    } catch (FileAlreadyExistsException ignore) {
    }
    git.add()
      .addFilepattern(".")
      .call();
    git.commit()
      .setMessage("add test branch")
      .call();
  } catch (Throwable e) {
    log.error("Method: commitSomething Exception", e);
  }
}

代码示例来源:origin: centic9/jgit-cookbook

private static void createCommit(Repository repository, Git git, String fileName, String content) throws IOException, GitAPIException {
    // create the file
    File myFile = new File(repository.getDirectory().getParent(), fileName);
    FileUtils.writeStringToFile(myFile, content, "UTF-8");

    // run the add
    git.add()
        .addFilepattern(fileName)
        .call();

    // and then commit the changes
    RevCommit revCommit = git.commit()
        .setMessage("Added " + fileName)
        .call();

    System.out.println("Committed file " + myFile + " as " + revCommit + " to repository at " + repository.getDirectory());
  }
}

代码示例来源:origin: centic9/jgit-cookbook

private static void createCommit(Repository repository, Git git, String fileName, String content) throws IOException, GitAPIException {
    // create the file
    File myFile = new File(repository.getDirectory().getParent(), fileName);
    FileUtils.writeStringToFile(myFile, content, "UTF-8");

    // run the add
    git.add()
        .addFilepattern(fileName)
        .call();

    // and then commit the changes
    RevCommit revCommit = git.commit()
        .setMessage("Added " + fileName)
        .call();

    System.out.println("Committed file " + myFile + " as " + revCommit + " to repository at " + repository.getDirectory());
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    final File localPath;
    // prepare a new test-repository
    try (Repository repository = CookbookHelper.createNewRepository()) {
      localPath = repository.getWorkTree();

      try (Git git = new Git(repository)) {
        // create the file
        File myFile = new File(repository.getDirectory().getParent(), "testfile");
        if(!myFile.createNewFile()) {
          throw new IOException("Could not create file " + myFile);
        }

        // run the add-call
        git.add()
            .addFilepattern("testfile")
            .call();

        System.out.println("Added file " + myFile + " to repository at " + repository.getDirectory());
      }
    }

    // clean up here to not keep using more and more disk-space for these samples
    FileUtils.deleteDirectory(localPath);
  }
}

代码示例来源:origin: centic9/jgit-cookbook

public static void main(String[] args) throws IOException, GitAPIException {
    final File localPath;
    // prepare a new test-repository
    try (Repository repository = CookbookHelper.createNewRepository()) {
      localPath = repository.getWorkTree();

      try (Git git = new Git(repository)) {
        // create the file
        File myFile = new File(repository.getDirectory().getParent(), "testfile");
        if(!myFile.createNewFile()) {
          throw new IOException("Could not create file " + myFile);
        }

        // run the add-call
        git.add()
            .addFilepattern("testfile")
            .call();

        System.out.println("Added file " + myFile + " to repository at " + repository.getDirectory());
      }
    }

    // clean up here to not keep using more and more disk-space for these samples
    FileUtils.deleteDirectory(localPath);
  }
}

代码示例来源:origin: centic9/jgit-cookbook

private static File createSampleGitRepo() throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.createNewRepository()) {
      System.out.println("Temporary repository at " + repository.getDirectory());

      // create the file
      File myFile = new File(repository.getDirectory().getParent(), "testfile");
      if(!myFile.createNewFile()) {
        throw new IOException("Could not create file " + myFile);
      }

      // run the add-call
      try (Git git = new Git(repository)) {
        git.add()
            .addFilepattern("testfile")
            .call();

        // and then commit the changes
        git.commit()
            .setMessage("Added testfile")
            .call();
      }

      System.out.println("Added file " + myFile + " to repository at " + repository.getDirectory());

      return repository.getDirectory();
    }
  }
}

代码示例来源:origin: centic9/jgit-cookbook

private static File createSampleGitRepo() throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.createNewRepository()) {
      System.out.println("Temporary repository at " + repository.getDirectory());

      // create the file
      File myFile = new File(repository.getDirectory().getParent(), "testfile");
      if(!myFile.createNewFile()) {
        throw new IOException("Could not create file " + myFile);
      }

      // run the add-call
      try (Git git = new Git(repository)) {
        git.add()
            .addFilepattern("testfile")
            .call();

        // and then commit the changes
        git.commit()
            .setMessage("Added testfile")
            .call();
      }

      System.out.println("Added file " + myFile + " to repository at " + repository.getDirectory());

      return repository.getDirectory();
    }
  }
}

代码示例来源:origin: e-biz/androidkickstartr

public Repository createCommit(File srcFolder, String applicationName) throws IOException, GitAPIException {
    Repository repository = repositoryService.createRepository(new Repository().setName(applicationName));

    String cloneUrl = repository.getCloneUrl();

    InitCommand init = new InitCommand();
    init.setDirectory(srcFolder);
    init.setBare(false);
    Git git = init.call();

    StoredConfig config = git.getRepository().getConfig();
    config.setString("remote", "origin", "url", cloneUrl);
    config.save();

    UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(accessToken, "");
    git.add().addFilepattern(".").call();
    git.commit().setMessage(COMMIT_MESSAGE).call();
    git.push().setCredentialsProvider(user).call();

    return repository;
  }
}

相关文章