use of com.google.copybara.util.CommandOutput in project copybara by google.
the class GitRepository method status.
public List<StatusFile> status() throws RepoException {
CommandOutput output = git(getCwd(), addGitDirAndWorkTreeParams(ImmutableList.of("status", "--porcelain")));
ImmutableList.Builder<StatusFile> builder = ImmutableList.builder();
for (String line : Splitter.on('\n').split(output.getStdout())) {
if (line.isEmpty()) {
continue;
}
// Format 'XY file (-> file)?'
List<String> split = Splitter.on(" -> ").limit(2).splitToList(line.substring(3));
String fileName;
String newFileName;
if (split.size() == 1) {
fileName = split.get(0);
newFileName = null;
} else {
fileName = split.get(0);
newFileName = split.get(1);
}
builder.add(new StatusFile(fileName, newFileName, toStatusCode(line.charAt(0)), toStatusCode(line.charAt(1))));
}
return builder.build();
}
use of com.google.copybara.util.CommandOutput in project copybara by google.
the class GitRepository method showRef.
/**
* Execute show-ref git command in the local repository and returns a map from reference name to
* GitReference(SHA-1).
*/
protected ImmutableMap<String, GitRevision> showRef(Iterable<String> refs) throws RepoException {
ImmutableMap.Builder<String, GitRevision> result = ImmutableMap.builder();
CommandOutput commandOutput = gitAllowNonZeroExit(CommandRunner.NO_INPUT, ImmutableList.<String>builder().add("show-ref").addAll(refs).build());
if (!commandOutput.getStderr().isEmpty()) {
throw new RepoException(String.format("Error executing show-ref on %s git repo:\n%s", getGitDir(), commandOutput.getStderr()));
}
for (String line : Splitter.on('\n').split(commandOutput.getStdout())) {
if (line.isEmpty()) {
continue;
}
List<String> strings = Splitter.on(' ').splitToList(line);
Preconditions.checkState(strings.size() == 2 && SHA1_PATTERN.matcher(strings.get(0)).matches(), "Cannot parse line: '%s'", line);
// Ref -> SHA1
result.put(strings.get(1), new GitRevision(this, strings.get(0)));
}
return result.build();
}
Aggregations