package bluej.groupwork.git;
import bluej.groupwork.TeamworkCommandError;
import bluej.groupwork.TeamworkCommandResult;
import bluej.utility.Debug;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;
import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.errors.UnmergedPathException;
| A git command to commit all files.
|
| @author Fabio Hedayioglu
|
public class GitCommitAllCommand
extends GitCommand{
protected Set<File> newFiles;
protected Set<File> deletedFiles;
protected Set<File> files;
protected String commitComment;
public GitCommitAllCommand(GitRepository repository, Set<File> newFiles,
Set<File> deletedFiles, Set<File> files, String commitComment)
{
super(repository);
this.newFiles = newFiles;
this.deletedFiles = deletedFiles;
this.files = files;
this.commitComment = commitComment;
}
@Override
public TeamworkCommandResult getResult()
{
try (Git repo = Git.open(this.getRepository().getProjectPath())) {
CommitCommand commit = repo.commit();
Path basePath = Paths.get(this.getRepository().getProjectPath().toString());
for (File f : newFiles)
{
String fileName = GitUtilities.getRelativeFileName(basePath, f);
if (!fileName.isEmpty() && !f.isDirectory())
{
repo.add().addFilepattern(fileName).call();
}
}
for (File f : deletedFiles)
{
String fileName = GitUtilities.getRelativeFileName(basePath, f);
if (!fileName.isEmpty())
{
repo.rm().addFilepattern(fileName).call();
}
}
commit.setAll(false);
for (File f : files)
{
String fileName = GitUtilities.getRelativeFileName(basePath, f);
if (!fileName.isEmpty() && !f.isDirectory())
{
if (!deletedFiles.contains(f))
{
repo.add().addFilepattern(fileName).call();
}
}
}
commit.setMessage(commitComment);
commit.setAuthor(getRepository().getYourName(), getRepository().getYourEmail());
commit.call();
} catch (UnmergedPathException | GitAPIException ex) {
Debug.reportError(ex.getMessage());
return new TeamworkCommandError(ex.getMessage(), ex.getLocalizedMessage());
} catch (IOException ex) {
Debug.reportError(ex.getMessage());
return new TeamworkCommandError(ex.getMessage(), ex.getLocalizedMessage());
}
return new TeamworkCommandResult();
}
}
top,
use,
map,
class GitCommitAllCommand
. GitCommitAllCommand
. getResult
121 neLoCode
+ 2 LoComm