0

I am using SCM Manager for HG version control. And I am trying to add an existing sc.txt file to HG repo using Java API provided by maven-scm-provider-hg dependency.

Method to add the file to HG repo:

public void add(ScmRepository scmRepository, ScmFileSet fileSet, String message,
        boolean binary) {
        try {
            AddScmResult rs = scmManager.add(scmRepository, fileSet, message);
            System.out.println("Result : " + rs.getAddedFiles());
        } catch (Exception e) {

            System.out.println("Execption occured while adding new file " + e);
        }
    }

Method to get the ScmRepository:

public ScmRepository getScmRepository(String scmUrl) throws Exception {
    ScmRepository repository;
    try {
        repository = getScmManager().makeScmRepository(scmUrl);
        System.out.println("Repo " + repository.getProviderRepository().getUser() + " Path : "
            + repository.getProvider());
        return repository;

} catch (NoSuchScmProviderException ex) {
    throw new Exception("Could not find a provider.", ex);
} catch (ScmRepositoryException ex) {
    throw new Exception("Error while connecting to the repository", ex);
}

}

MainApp.java

 ScmRepository repo = scmClient.getScmRepository("scm:hg:/Users/john/work/hgtest/v1");
      ScmFileSet fileSet = new ScmFileSet(new File("/Users/john/work/hgtest/v1"),
                new File("sc.txt"));

            scmClient.add(repo, fileSet, "This is first file checking", false);

This is what error I get when I execute the code:

Adding new file to hg..... EXECUTING: /bin/sh -c cd /Users/diwakar/work/hgtest/v2 && hg add --verbose sc.txt [ERROR] EXECUTION FAILED Execution of cmd : add failed with exit code: 127. Working directory was: /Users/diwakar/work/hgtest/v2 Your Hg installation seems to be valid and complete. Hg version: NA (OK)

Result : [] Done.....

POM.xml:

<dependency>
    <groupId>org.apache.maven.scm</groupId>
    <artifactId>maven-scm-provider-hg</artifactId>
    <version>1.8</version>
</dependency>
Diwakar
  • 1
  • 3
  • Can you tell me why you are using such an old version of maven-scm-...* ? See http://maven.apache.org/scm/ (1.9.5)... – khmarbaise Apr 17 '17 at 17:15
  • I have updated the version to org.apache.maven.scm maven-scm-provider-hg 1.9.5 – Diwakar Apr 18 '17 at 05:05
  • Still getting the same error, When I manually run below command it is working fine but the same command is giving 127 error code./bin/sh -c cd /Users/diwakar/work/hgtest/v2 && hg add --verbose sc.txt – Diwakar Apr 18 '17 at 05:06
  • 1
    found the solution: you need to add the environment variable as PATH=/usr/local/bin where your hg is installed. It was not able to find the path of hg – Diwakar Apr 19 '17 at 06:32

0 Answers0