|
|
|
|
Re: Invalid history entries after push [message #1760264 is a reply to message #1760260] |
Tue, 25 April 2017 09:19 |
Messages: 23 Registered: September 2015 |
Junior Member |
|
|
I check particular files in GitLab. I run attached code for single file - it is copied to local repo subdir and pushed to remote. When I run this code second time (for other file) it is pushed, but file contains history form first run :/
JAVA code:
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import org.eclipse.jgit.api.AddCommand;
import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.SubmoduleAddCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.JschConfigSessionFactory;
import org.eclipse.jgit.transport.OpenSshConfig;
import org.eclipse.jgit.util.FS;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.StringTokenizer;
public class GitManager {
private static final String DIR_PATH = "patch";
private Git git;
private PropertiesManager propertiesManager;
private String dirPath, fileName;
public GitManager(PropertiesManager propertiesManager) {
this.propertiesManager = propertiesManager;
this.dirPath = propertiesManager.get(ProperiesUtils.LOCAL_PATH) + "/" + DIR_PATH;
}
public void save() throws IOException {
try {
connect();
this.fileName = generateFileName();
copyFiles();
add();
commit();
push();
} catch (Exception e) {
e.printStackTrace();
}
git.close();
}
public void add() throws IOException, GitAPIException {
git.add().addFilepattern(DIR_PATH + "/" + this.fileName).call();
}
public void commit() throws IOException, GitAPIException, JGitInternalException {
Object command = git.commit().setMessage("Added new patch file").call();
}
public void push() throws IOException, JGitInternalException, GitAPIException {
Object result = git.push().call();
}
private void connect() throws IOException, URISyntaxException, GitAPIException {
final JschConfigSessionFactory f = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session sn) {
}
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
JSch defaultJSch = super.createDefaultJSch(fs);
defaultJSch.addIdentity(propertiesManager.get(ProperiesUtils.PRIVATE_KEY), propertiesManager.get(ProperiesUtils.PASSPHRASE));
return defaultJSch;
}
};
JschConfigSessionFactory.setInstance(f);
git = Git.open(new File(propertiesManager.get(ProperiesUtils.LOCAL_PATH)));
git.pull().call();
}
private void copyFiles() throws IOException {
Path source = Paths.get(propertiesManager.get(ProperiesUtils.FILE));
Path destination = Paths.get(propertiesManager.get(ProperiesUtils.LOCAL_PATH) + "/" + DIR_PATH + "/" + this.fileName);
Files.copy(source, destination);
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04772 seconds