mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-31 12:51:35 +02:00
Ignore .gitignore files on git.overleaf.com repos (fix #1281)
This commit is contained in:
@@ -6,6 +6,7 @@ import uk.ac.ic.wlgitbridge.bridge.db.DBStore;
|
||||
import uk.ac.ic.wlgitbridge.bridge.db.ProjectState;
|
||||
import uk.ac.ic.wlgitbridge.bridge.lock.LockGuard;
|
||||
import uk.ac.ic.wlgitbridge.bridge.lock.ProjectLock;
|
||||
import uk.ac.ic.wlgitbridge.bridge.repo.ProjectRepo;
|
||||
import uk.ac.ic.wlgitbridge.bridge.repo.RepoStore;
|
||||
import uk.ac.ic.wlgitbridge.bridge.resource.ResourceCache;
|
||||
import uk.ac.ic.wlgitbridge.bridge.resource.UrlResourceCache;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package uk.ac.ic.wlgitbridge.bridge;
|
||||
package uk.ac.ic.wlgitbridge.bridge.repo;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.ResetCommand;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
||||
import uk.ac.ic.wlgitbridge.bridge.repo.RepoStore;
|
||||
import uk.ac.ic.wlgitbridge.data.filestore.GitDirectoryContents;
|
||||
import uk.ac.ic.wlgitbridge.data.filestore.RawFile;
|
||||
import uk.ac.ic.wlgitbridge.git.exception.GitUserException;
|
||||
@@ -80,10 +80,23 @@ public class GitProjectRepo implements ProjectRepo {
|
||||
}
|
||||
}
|
||||
|
||||
public void resetHard() throws IOException {
|
||||
Git git = new Git(getJGitRepository());
|
||||
try {
|
||||
git.reset().setMode(ResetCommand.ResetType.HARD).call();
|
||||
} catch (GitAPIException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Repository getJGitRepository() {
|
||||
return repository.get();
|
||||
}
|
||||
|
||||
public File getDirectory() {
|
||||
return getJGitRepository().getWorkTree();
|
||||
}
|
||||
|
||||
private void initRepositoryField(RepoStore repoStore) throws IOException {
|
||||
Preconditions.checkNotNull(repoStore);
|
||||
Preconditions.checkArgument(Project.isValidProjectName(projectName));
|
||||
@@ -103,10 +116,11 @@ public class GitProjectRepo implements ProjectRepo {
|
||||
GitDirectoryContents contents
|
||||
) throws IOException, GitAPIException {
|
||||
Preconditions.checkState(repository.isPresent());
|
||||
Repository repo = getJGitRepository();
|
||||
String name = getProjectName();
|
||||
Log.info("[{}] Writing commit", name);
|
||||
contents.write();
|
||||
Git git = new Git(repository.get());
|
||||
Git git = new Git(getJGitRepository());
|
||||
Log.info("[{}] Getting missing files", name);
|
||||
Set<String> missingFiles = git.status().call().getMissing();
|
||||
for (String missing : missingFiles) {
|
||||
@@ -114,7 +128,10 @@ public class GitProjectRepo implements ProjectRepo {
|
||||
git.rm().setCached(true).addFilepattern(missing).call();
|
||||
}
|
||||
Log.info("[{}] Calling Git add", name);
|
||||
git.add().addFilepattern(".").call();
|
||||
git.add(
|
||||
).setWorkingTreeIterator(
|
||||
new NoGitignoreIterator(repo)
|
||||
).addFilepattern(".").call();
|
||||
Log.info("[{}] Calling Git commit", name);
|
||||
git.commit(
|
||||
).setAuthor(
|
||||
@@ -0,0 +1,82 @@
|
||||
package uk.ac.ic.wlgitbridge.bridge.repo;
|
||||
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.treewalk.FileTreeIterator;
|
||||
import org.eclipse.jgit.treewalk.WorkingTreeIterator;
|
||||
import org.eclipse.jgit.treewalk.WorkingTreeOptions;
|
||||
import org.eclipse.jgit.util.FS;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Created by winston on 08/10/2016.
|
||||
*/
|
||||
public class NoGitignoreIterator extends FileTreeIterator {
|
||||
|
||||
private static final Field ignoreNodeField;
|
||||
|
||||
static {
|
||||
try {
|
||||
ignoreNodeField = WorkingTreeIterator.class.getDeclaredField(
|
||||
"ignoreNode"
|
||||
);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ignoreNodeField.setAccessible(true);
|
||||
}
|
||||
|
||||
public NoGitignoreIterator(Repository repo) {
|
||||
super(repo);
|
||||
}
|
||||
|
||||
public NoGitignoreIterator(
|
||||
Repository repo,
|
||||
FileModeStrategy fileModeStrategy
|
||||
) {
|
||||
super(repo, fileModeStrategy);
|
||||
}
|
||||
|
||||
public NoGitignoreIterator(File root, FS fs, WorkingTreeOptions options) {
|
||||
super(root, fs, options);
|
||||
}
|
||||
|
||||
public NoGitignoreIterator(
|
||||
File root,
|
||||
FS fs,
|
||||
WorkingTreeOptions options,
|
||||
FileModeStrategy fileModeStrategy
|
||||
) {
|
||||
super(root, fs, options, fileModeStrategy);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected NoGitignoreIterator(WorkingTreeIterator p, File root, FS fs) {
|
||||
super(p, root, fs);
|
||||
}
|
||||
|
||||
protected NoGitignoreIterator(FileTreeIterator p, File root, FS fs) {
|
||||
super(p, root, fs);
|
||||
}
|
||||
|
||||
protected NoGitignoreIterator(
|
||||
WorkingTreeIterator p,
|
||||
File root,
|
||||
FS fs,
|
||||
FileModeStrategy fileModeStrategy
|
||||
) {
|
||||
super(p, root, fs, fileModeStrategy);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(Entry[] list) {
|
||||
super.init(list);
|
||||
try {
|
||||
ignoreNodeField.set(this, null);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package uk.ac.ic.wlgitbridge.bridge;
|
||||
package uk.ac.ic.wlgitbridge.bridge.repo;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.bridge.repo.RepoStore;
|
||||
import uk.ac.ic.wlgitbridge.data.filestore.GitDirectoryContents;
|
||||
@@ -20,13 +20,38 @@ public class GitDirectoryContents {
|
||||
private final String commitMessage;
|
||||
private final Date when;
|
||||
|
||||
public GitDirectoryContents(List<RawFile> files, File rootGitDirectory, String projectName, Snapshot snapshot) {
|
||||
public GitDirectoryContents(
|
||||
List<RawFile> files,
|
||||
File rootGitDirectory,
|
||||
String projectName,
|
||||
String userName,
|
||||
String userEmail,
|
||||
String commitMessage,
|
||||
Date when
|
||||
) {
|
||||
this.files = files;
|
||||
gitDirectory = new File(rootGitDirectory, projectName);
|
||||
userName = snapshot.getUserName();
|
||||
userEmail = snapshot.getUserEmail();
|
||||
commitMessage = snapshot.getComment();
|
||||
when = snapshot.getCreatedAt();
|
||||
this.gitDirectory = new File(rootGitDirectory, projectName);
|
||||
this.userName = userName;
|
||||
this.userEmail = userEmail;
|
||||
this.commitMessage = commitMessage;
|
||||
this.when = when;
|
||||
}
|
||||
|
||||
public GitDirectoryContents(
|
||||
List<RawFile> files,
|
||||
File rootGitDirectory,
|
||||
String projectName,
|
||||
Snapshot snapshot
|
||||
) {
|
||||
this(
|
||||
files,
|
||||
rootGitDirectory,
|
||||
projectName,
|
||||
snapshot.getUserName(),
|
||||
snapshot.getUserEmail(),
|
||||
snapshot.getComment(),
|
||||
snapshot.getCreatedAt()
|
||||
);
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
|
||||
@@ -32,7 +32,8 @@ public abstract class RawFile {
|
||||
return false;
|
||||
}
|
||||
RawFile that = (RawFile) obj;
|
||||
return getPath().equals(that.getPath()) && Arrays.equals(getContents(), that.getContents());
|
||||
return getPath().equals(that.getPath())
|
||||
&& Arrays.equals(getContents(), that.getContents());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.eclipse.jgit.transport.resolver.RepositoryResolver;
|
||||
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
|
||||
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
|
||||
import uk.ac.ic.wlgitbridge.bridge.Bridge;
|
||||
import uk.ac.ic.wlgitbridge.bridge.GitProjectRepo;
|
||||
import uk.ac.ic.wlgitbridge.bridge.repo.GitProjectRepo;
|
||||
import uk.ac.ic.wlgitbridge.git.exception.GitUserException;
|
||||
import uk.ac.ic.wlgitbridge.server.Oauth2Filter;
|
||||
import uk.ac.ic.wlgitbridge.snapshot.base.ForbiddenException;
|
||||
|
||||
Reference in New Issue
Block a user