Merge with 2.0.0-m3

This commit is contained in:
Rene Pfeuffer
2019-09-12 10:31:38 +02:00
5 changed files with 64 additions and 13 deletions

View File

@@ -77,7 +77,7 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
@Override
public void create(String toBeCreated, File file, boolean overwrite) throws IOException {
Path targetFile = new File(workDir, toBeCreated).toPath();
Files.createDirectories(targetFile.getParent());
createDirectories(targetFile);
if (overwrite) {
Files.move(file.toPath(), targetFile, REPLACE_EXISTING);
} else {
@@ -88,7 +88,7 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
}
}
try {
getClone().add().addFilepattern(toBeCreated).call();
addFileToGit(toBeCreated);
} catch (GitAPIException e) {
throwInternalRepositoryException("could not add new file to index", e);
}
@@ -97,18 +97,22 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
@Override
public void modify(String path, File file) throws IOException {
Path targetFile = new File(workDir, path).toPath();
Files.createDirectories(targetFile.getParent());
createDirectories(targetFile);
if (!targetFile.toFile().exists()) {
throw notFound(createFileContext(path));
}
Files.move(file.toPath(), targetFile, REPLACE_EXISTING);
try {
getClone().add().addFilepattern(path).call();
addFileToGit(path);
} catch (GitAPIException e) {
throwInternalRepositoryException("could not add new file to index", e);
}
}
private void addFileToGit(String toBeCreated) throws GitAPIException {
getClone().add().addFilepattern(removeStartingPathSeparators(toBeCreated)).call();
}
@Override
public void delete(String toBeDeleted) throws IOException {
Path fileToBeDeleted = new File(workDir, toBeDeleted).toPath();
@@ -118,12 +122,27 @@ public class GitModifyCommand extends AbstractGitCommand implements ModifyComman
throw notFound(createFileContext(toBeDeleted));
}
try {
getClone().rm().addFilepattern(toBeDeleted).call();
getClone().rm().addFilepattern(removeStartingPathSeparators(toBeDeleted)).call();
} catch (GitAPIException e) {
throwInternalRepositoryException("could not remove file from index", e);
}
}
private String removeStartingPathSeparators(String path) {
while (path.startsWith(File.separator)) {
path = path.substring(1);
}
return path;
}
private void createDirectories(Path targetFile) throws IOException {
try {
Files.createDirectories(targetFile.getParent());
} catch (FileAlreadyExistsException e) {
throw alreadyExists(createFileContext(targetFile.toString()));
}
}
private ContextEntry.ContextBuilder createFileContext(String path) {
ContextEntry.ContextBuilder contextBuilder = entity("file", path);
if (!StringUtils.isEmpty(request.getBranch())) {

View File

@@ -97,6 +97,24 @@ public class GitModifyCommandTest extends AbstractGitCommandTestBase {
assertInTree(assertions);
}
@Test
public void shouldCreateNewFileWhenPathStartsWithSlash() throws IOException, GitAPIException {
File newFile = Files.write(temporaryFolder.newFile().toPath(), "new content".getBytes()).toFile();
GitModifyCommand command = createCommand();
ModifyCommandRequest request = new ModifyCommandRequest();
request.setCommitMessage("test commit");
request.addRequest(new ModifyCommandRequest.CreateFileRequest("/new_file", newFile, false));
request.setAuthor(new Person("Dirk Gently", "dirk@holistic.det"));
command.execute(request);
TreeAssertions assertions = canonicalTreeParser -> assertThat(canonicalTreeParser.findFile("new_file")).isTrue();
assertInTree(assertions);
}
@Test(expected = AlreadyExistsException.class)
public void shouldFailIfOverwritingExistingFileWithoutOverwriteFlag() throws IOException {
File newFile = Files.write(temporaryFolder.newFile().toPath(), "new content".getBytes()).toFile();
@@ -111,6 +129,20 @@ public class GitModifyCommandTest extends AbstractGitCommandTestBase {
command.execute(request);
}
@Test(expected = AlreadyExistsException.class)
public void shouldFailIfPathAlreadyExistsAsAFile() throws IOException {
File newFile = Files.write(temporaryFolder.newFile().toPath(), "new content".getBytes()).toFile();
GitModifyCommand command = createCommand();
ModifyCommandRequest request = new ModifyCommandRequest();
request.setCommitMessage("test commit");
request.addRequest(new ModifyCommandRequest.CreateFileRequest("a.txt/newFile", newFile, false));
request.setAuthor(new Person("Dirk Gently", "dirk@holistic.det"));
command.execute(request);
}
@Test
public void shouldOverwriteExistingFileIfOverwriteFlagSet() throws IOException, GitAPIException {
File newFile = Files.write(temporaryFolder.newFile().toPath(), "new content".getBytes()).toFile();

View File

@@ -70,13 +70,13 @@
"submit": "Save"
},
"delete": {
"button": "Löschen",
"subtitle": "Berechtigungsrolle löschen",
"button": "Delete",
"subtitle": "Delete permission role",
"confirmAlert": {
"title": "Berechtigungsrolle löschen",
"message": "Soll die Berechtigungsrolle wirklich gelöscht werden? Alle Nutzer dieser Rolle verlieren Ihre Berechtigungen.",
"submit": "Ja",
"cancel": "Nein"
"title": "Delete permission role",
"message": "Do you really want to delete this permission role? All users will lose their corresponding permissions.",
"submit": "Yes",
"cancel": "No"
}
}
}

View File

@@ -92,7 +92,7 @@ class FileTreeLeaf extends React.Component<Props> {
{file.description}
</td>
{binder.hasExtension("repos.sources.tree.row.right") && (
<td>
<td className="is-hidden-mobile">
{!file.directory && (
<ExtensionPoint
name="repos.sources.tree.row.right"

View File

@@ -85,10 +85,10 @@ class Sources extends React.Component<Props, State> {
const defaultBranches = branches.filter(b => b.defaultBranch);
if (defaultBranches.length > 0) {
this.setState({ selectedBranch: defaultBranches[0] });
this.props.history.push(
`${baseUrl}/${encodeURIComponent(defaultBranches[0].name)}/`
);
this.setState({ selectedBranch: defaultBranches[0] });
}
}
};