use of com.google.startupos.common.repo.Protos.File in project startup-os by google.
the class CodeReviewServiceTextDiffTest method testTextDiff_deletedFile.
// DELETE, any file
@Test
public void testTextDiff_deletedFile() {
File file = File.newBuilder().setRepoId("startup-os").setWorkspace(TEST_WORKSPACE).setFilename(TEST_FILE).setAction(Action.DELETE).build();
TextDiffResponse response = getResponse(file);
assertEquals(getExpectedResponse(""), response);
}
use of com.google.startupos.common.repo.Protos.File in project startup-os by google.
the class CodeReviewServiceTextDiffTest method testTextDiff_locallyModifiedWorkspaceExistsNewFile.
// ADD, locally modified, workspace exists, new file
@Test
public void testTextDiff_locallyModifiedWorkspaceExistsNewFile() {
writeFile("somefile.txt", TEST_FILE_CONTENTS);
writeFile(TEST_FILE_CONTENTS);
File file = File.newBuilder().setRepoId("startup-os").setWorkspace(TEST_WORKSPACE).setFilename("somefile.txt").build();
TextDiffResponse response = getResponse(file);
assertEquals(getExpectedResponse(TEST_FILE_CONTENTS), response);
}
use of com.google.startupos.common.repo.Protos.File in project startup-os by google.
the class SnapshotCommand method run.
@Override
public boolean run(String[] args) {
if (diffNumber == -1) {
System.out.println(RED_ERROR + "Cannot find diff number");
return false;
}
String branchName = String.format("D%d", diffNumber);
try {
fileUtils.listContents(workspacePath).stream().map(path -> fileUtils.joinToAbsolutePath(workspacePath, path)).filter(fileUtils::folderExists).forEach(path -> {
String repoName = Paths.get(path).getFileName().toString();
GitRepo repo = this.gitRepoFactory.create(path);
repoToInitialBranch.put(repoName, repo.currentBranch());
repo.switchBranch(branchName);
ImmutableList<File> files = repo.getUncommittedFiles();
if (files.isEmpty()) {
System.out.println(String.format("[%s]: No files to update", repoName));
// Only skips this iteration
return;
}
String message = branchName + ":\n" + files.stream().map(File::getFilename).collect(Collectors.joining("\n"));
repo.commit(files, String.format(message, branchName));
System.out.println(String.format("[%s]: Committed changes", repoName));
});
} catch (Exception e) {
revertChanges(repoToInitialBranch);
e.printStackTrace();
}
return true;
}
use of com.google.startupos.common.repo.Protos.File in project startup-os by google.
the class GitRepo method getFilesInCommit.
@Override
public ImmutableList<File> getFilesInCommit(String commitId) {
CommandResult commandResult = runCommand("diff-tree --no-commit-id --name-status -r " + commitId);
ImmutableList.Builder<File> result = ImmutableList.builder();
try {
ImmutableList<String> lines = splitLines(commandResult.stdout);
for (String line : lines) {
String[] parts = line.split("\t");
File file = File.newBuilder().setAction(getAction(parts[0].trim())).setCommitId(commitId).setFilename(parts[1].trim()).build();
result.add(file);
}
} catch (IllegalStateException e) {
throw new IllegalStateException("getFilesInCommit failed for commit " + commitId, e);
}
return result.build();
}
use of com.google.startupos.common.repo.Protos.File in project startup-os by google.
the class GitRepo method commit.
@Override
public Commit commit(ImmutableList<File> files, String message) {
Commit.Builder commitBuilder = Commit.newBuilder();
for (File file : files) {
addFile(file.getFilename());
}
runCommand(Arrays.asList("commit", "-m", "\"" + message + "\""));
String commitId = getHeadCommitId();
for (File file : files) {
commitBuilder.addFile(file.toBuilder().setCommitId(commitId));
}
return commitBuilder.setId(commitId).build();
}
Aggregations