use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.
the class GitCheckInCommandNoBranchTest method testCheckinNoBranch.
public void testCheckinNoBranch() throws Exception {
if (!ScmTestCase.isSystemCmd("git")) {
System.out.println("skip test which git native executable in path");
return;
}
File repo_orig = new File("src/test/resources/repository_no_branch");
File repo = getTestFile("target/git_copy");
FileUtils.deleteDirectory(repo);
FileUtils.copyDirectoryStructure(repo_orig, repo);
ScmRepository scmRepository = getScmManager().makeScmRepository("scm:git:file:///" + repo.getAbsolutePath());
CheckOutScmResult checkOutScmResult = checkoutRepo(scmRepository);
assertEquals(0, checkOutScmResult.getCheckedOutFiles().size());
File f = new File(workingDirectory.getAbsolutePath() + File.separator + "pom.xml");
FileUtils.fileWrite(f.getAbsolutePath(), "toto");
ScmFileSet scmFileSet = new ScmFileSet(workingDirectory, new File("pom.xml"));
AddScmResult addResult = getScmManager().add(scmRepository, scmFileSet);
assertResultIsSuccess(addResult);
CheckInScmResult checkInScmResult = getScmManager().checkIn(scmRepository, scmFileSet, "commit");
assertResultIsSuccess(checkInScmResult);
assertEquals(1, checkInScmResult.getCheckedInFiles().size());
assertEquals("pom.xml", checkInScmResult.getCheckedInFiles().get(0).getPath());
checkOutScmResult = checkoutRepo(scmRepository);
assertResultIsSuccess(checkOutScmResult);
assertEquals(1, checkOutScmResult.getCheckedOutFiles().size());
assertEquals("pom.xml", checkOutScmResult.getCheckedOutFiles().get(0).getPath());
}
use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.
the class JGitAddCommand method executeAddCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, boolean binary) throws ScmException {
if (fileSet.getFileList().isEmpty()) {
throw new ScmException("You must provide at least one file/directory to add (e.g. -Dincludes=...)");
}
Git git = null;
try {
git = JGitUtils.openRepo(fileSet.getBasedir());
List<ScmFile> addedFiles = JGitUtils.addAllFiles(git, fileSet);
if (getLogger().isDebugEnabled()) {
for (ScmFile scmFile : addedFiles) {
getLogger().info("added file: " + scmFile);
}
}
return new AddScmResult("JGit add", addedFiles);
} catch (Exception e) {
throw new ScmException("JGit add failure!", e);
} finally {
JGitUtils.closeRepo(git);
}
}
use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.
the class GitCheckInCommandTest method testCheckinAfterRename.
// Test reproducing SCM-694
public void testCheckinAfterRename() throws Exception {
File repo = getRepositoryRoot();
File checkedOutRepo = getWorkingCopy();
GitScmTestUtils.initRepo("src/test/resources/repository/", getRepositoryRoot(), getWorkingDirectory());
ScmRepository scmRepository = getScmManager().makeScmRepository("scm:git:file://" + repo.getAbsolutePath());
checkoutRepoInto(checkedOutRepo, scmRepository);
// Creating foo/bar/wine.xml
File fooDir = new File(checkedOutRepo.getAbsolutePath() + File.separator + "foo");
fooDir.mkdir();
File barDir = new File(fooDir.getAbsolutePath() + File.separator + "bar");
barDir.mkdir();
File wineFile = new File(barDir.getAbsolutePath() + File.separator + "wine.xml");
FileUtils.fileWrite(wineFile.getAbsolutePath(), "Lacoste castle");
// Adding and commiting file
AddScmResult addResult = getScmManager().add(scmRepository, new ScmFileSet(checkedOutRepo, new File("foo/bar/wine.xml")));
assertResultIsSuccess(addResult);
CheckInScmResult checkInScmResult = getScmManager().checkIn(scmRepository, new ScmFileSet(checkedOutRepo), "Created wine file");
assertResultIsSuccess(checkInScmResult);
// Cloning foo/bar/wine.xml to foo/newbar/wine.xml
File newBarDir = new File(fooDir.getAbsolutePath() + File.separator + "newbar");
newBarDir.mkdir();
File movedWineFile = new File(newBarDir.getAbsolutePath() + File.separator + "wine.xml");
FileUtils.copyFile(wineFile, movedWineFile);
// Removing old file, adding new file and commiting...
RemoveScmResult removeResult = getScmManager().remove(scmRepository, new ScmFileSet(checkedOutRepo, new File("foo/bar/")), "");
assertResultIsSuccess(removeResult);
addResult = getScmManager().add(scmRepository, new ScmFileSet(checkedOutRepo, new File("foo/newbar/wine.xml")));
assertResultIsSuccess(addResult);
checkInScmResult = getScmManager().checkIn(scmRepository, new ScmFileSet(checkedOutRepo), "moved wine.xml from foo/bar/ to foo/newbar/");
assertResultIsSuccess(checkInScmResult);
assertTrue("Renamed file has not been commited !", checkInScmResult.getCheckedInFiles().size() != 0);
}
use of org.apache.maven.scm.command.add.AddScmResult in project maven-scm by apache.
the class GitAddCommand method executeAddFiles.
private AddScmResult executeAddFiles(File workingDirectory, List<File> files) throws ScmException {
Commandline cl = createCommandLine(workingDirectory, files);
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
int exitCode = GitCommandLineUtils.execute(cl, stdout, stderr, getLogger());
if (exitCode != 0) {
return new AddScmResult(cl.toString(), "The git-add command failed.", stderr.getOutput(), false);
}
return null;
}
Aggregations