mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-05 15:19:02 +02:00
Fixed bug with git not adding deleted files.
This commit is contained in:
@@ -49,6 +49,9 @@ public class WLBridgedProject {
|
||||
for (WritableRepositoryContents contents : writableRepositories) {
|
||||
contents.write();
|
||||
Git git = new Git(repository);
|
||||
for (String missing : git.status().call().getMissing()) {
|
||||
git.rm().setCached(true).addFilepattern(missing).call();
|
||||
}
|
||||
git.add().addFilepattern(".").call();
|
||||
git.commit().setAuthor(new PersonIdent(contents.getUserName(), contents.getUserEmail(), contents.getWhen(), TimeZone.getDefault()))
|
||||
.setMessage(contents.getCommitMessage())
|
||||
|
||||
@@ -34,8 +34,8 @@ public class FileUtil {
|
||||
}
|
||||
|
||||
public static boolean gitDirectoriesAreEqual(Path dir1, Path dir2) {
|
||||
Set<String> dir1Contents = getAllFilesRecursivelyInDirectoryApartFrom(dir1, dir1.resolve(".git"));
|
||||
Set<String> dir2Contents = getAllFilesRecursivelyInDirectoryApartFrom(dir2, dir2.resolve(".git"));
|
||||
Set<String> dir1Contents = getAllRecursivelyInDirectoryApartFrom(dir1, dir1.resolve(".git"));
|
||||
Set<String> dir2Contents = getAllRecursivelyInDirectoryApartFrom(dir2, dir2.resolve(".git"));
|
||||
boolean filesEqual = dir1Contents.equals(dir2Contents);
|
||||
if (!filesEqual) {
|
||||
System.out.println("Not equal: (" + dir1Contents + ", " + dir2Contents + ")");
|
||||
@@ -72,20 +72,31 @@ public class FileUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<String> getAllFilesRecursivelyInDirectoryApartFrom(Path dir, Path excluded) {
|
||||
public static Set<String> getAllRecursivelyInDirectoryApartFrom(Path dir, Path excluded) {
|
||||
return getAllRecursivelyInDirectoryApartFrom(dir, excluded, true);
|
||||
}
|
||||
|
||||
public static Set<String> getOnlyFilesRecursivelyInDirectoryApartFrom(Path dir, Path excluded) {
|
||||
return getAllRecursivelyInDirectoryApartFrom(dir, excluded, false);
|
||||
}
|
||||
|
||||
private static Set<String> getAllRecursivelyInDirectoryApartFrom(Path dir, Path excluded, boolean directories) {
|
||||
if (!dir.toFile().isDirectory()) {
|
||||
throw new IllegalArgumentException("need a directory");
|
||||
}
|
||||
return getAllFilesRecursively(dir, dir, excluded);
|
||||
return getAllFilesRecursively(dir, dir, excluded, directories);
|
||||
}
|
||||
|
||||
static Set<String> getAllFilesRecursively(Path baseDir, Path dir, Path excluded) {
|
||||
static Set<String> getAllFilesRecursively(Path baseDir, Path dir, Path excluded, boolean directories) {
|
||||
Set<String> files = new HashSet<String>();
|
||||
for (File file : dir.toFile().listFiles()) {
|
||||
if (!file.equals(excluded.toFile())) {
|
||||
files.add(baseDir.relativize(file.toPath()).toString());
|
||||
if (file.isDirectory()) {
|
||||
files.addAll(getAllFilesRecursively(baseDir, file.toPath(), excluded));
|
||||
boolean isDirectory = file.isDirectory();
|
||||
if (directories || !isDirectory) {
|
||||
files.add(baseDir.relativize(file.toPath()).toString());
|
||||
}
|
||||
if (isDirectory) {
|
||||
files.addAll(getAllFilesRecursively(baseDir, file.toPath(), excluded, directories));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -36,6 +36,7 @@ public class GitDirectoryContents implements WritableRepositoryContents {
|
||||
public void write() throws IOException, FailedConnectionException {
|
||||
WLFileStore.deleteInDirectoryApartFrom(gitDirectory, ".git");
|
||||
for (FileNode fileNode : fileNodes) {
|
||||
System.out.println("Writing: " + fileNode.getFilePath());
|
||||
fileNode.writeToDisk(gitDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -58,6 +58,7 @@ public class WLFileStore implements PersistentStoreSource {
|
||||
if (file.isDirectory()) {
|
||||
deleteInDirectory(file);
|
||||
}
|
||||
System.out.println("deleting: " + file.getAbsolutePath());
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user