use of org.eclipse.jgit.internal.storage.file.FileRepository in project gerrit by GerritCodeReview.
the class AccountsOnInit method insert.
public void insert(ReviewDb db, Account account) throws OrmException, IOException {
db.accounts().insert(ImmutableSet.of(account));
File path = getPath();
if (path != null) {
try (Repository repo = new FileRepository(path);
ObjectInserter oi = repo.newObjectInserter()) {
PersonIdent serverIdent = new GerritPersonIdentProvider(flags.cfg).get();
AccountsUpdate.createUserBranch(repo, oi, serverIdent, serverIdent, account);
}
}
}
use of org.eclipse.jgit.internal.storage.file.FileRepository in project searchcode-server by boyter.
the class IndexGitHistoryJob method getGitChangeSets.
public void getGitChangeSets() throws IOException, GitAPIException {
//Repository localRepository = new FileRepository(new File("./repo/server/.git"));
Repository localRepository = new FileRepository(new File("./repo/thumbor/.git"));
Git git = new Git(localRepository);
Iterable<RevCommit> logs = git.log().call();
List<GitChangeSet> gitChangeSets = new ArrayList<>();
for (RevCommit rev : logs) {
String message = rev.getFullMessage();
String author = rev.getAuthorIdent().getName();
Date expiry = new Date(Long.valueOf(rev.getCommitTime()) * 1000);
System.out.println(expiry.toString() + " " + rev.getCommitTime() + " " + rev.getName());
gitChangeSets.add(new GitChangeSet(message, author, rev.getName(), expiry));
}
gitChangeSets = Lists.reverse(gitChangeSets);
// TODO currently this is ignoring the very first commit changes need to include those
for (int i = 1; i < gitChangeSets.size(); i++) {
System.out.println("///////////////////////////////////////////////");
this.getRevisionChanges(localRepository, git, gitChangeSets.get(i - 1), gitChangeSets.get(i));
}
}
use of org.eclipse.jgit.internal.storage.file.FileRepository in project searchcode-server by boyter.
the class IndexGitRepoJob method updateGitRepository.
/**
* Update a git repository and return if it has changed and the differences
*/
public RepositoryChanged updateGitRepository(String repoName, String repoRemoteLocation, String repoUserName, String repoPassword, String repoLocations, String branch, boolean useCredentials) {
boolean changed = false;
List<String> changedFiles = new ArrayList<>();
List<String> deletedFiles = new ArrayList<>();
Singleton.getLogger().info("Attempting to pull latest from " + repoRemoteLocation + " for " + repoName);
Repository localRepository = null;
Git git = null;
try {
localRepository = new FileRepository(new File(repoLocations + "/" + repoName + "/.git"));
Ref head = localRepository.getRef("HEAD");
git = new Git(localRepository);
git.reset();
git.clean();
PullCommand pullCmd = git.pull();
if (useCredentials) {
pullCmd.setCredentialsProvider(new UsernamePasswordCredentialsProvider(repoUserName, repoPassword));
}
pullCmd.call();
Ref newHEAD = localRepository.getRef("HEAD");
if (!head.toString().equals(newHEAD.toString())) {
changed = true;
// Get the differences between the the heads which we updated at
// and use these to just update the differences between them
ObjectId oldHead = localRepository.resolve(head.getObjectId().getName() + "^{tree}");
ObjectId newHead = localRepository.resolve(newHEAD.getObjectId().getName() + "^{tree}");
ObjectReader reader = localRepository.newObjectReader();
CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
oldTreeIter.reset(reader, oldHead);
CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
newTreeIter.reset(reader, newHead);
List<DiffEntry> entries = git.diff().setNewTree(newTreeIter).setOldTree(oldTreeIter).call();
for (DiffEntry entry : entries) {
if ("DELETE".equals(entry.getChangeType().name())) {
deletedFiles.add(FilenameUtils.separatorsToUnix(entry.getOldPath()));
} else {
changedFiles.add(FilenameUtils.separatorsToUnix(entry.getNewPath()));
}
}
}
} catch (IOException | GitAPIException | InvalidPathException ex) {
changed = false;
Singleton.getLogger().warning("ERROR - caught a " + ex.getClass() + " in " + this.getClass() + " updateGitRepository for " + repoName + "\n with message: " + ex.getMessage());
} finally {
Singleton.getHelpers().closeQuietly(localRepository);
Singleton.getHelpers().closeQuietly(git);
}
return new RepositoryChanged(changed, changedFiles, deletedFiles);
}
use of org.eclipse.jgit.internal.storage.file.FileRepository in project Aspose.Imaging-for-Java by aspose-imaging.
the class GitHelper method updateRepository.
public static void updateRepository(String localPath, String remotePath) throws Exception {
Repository localRepo;
try {
localRepo = new FileRepository(localPath + "/.git");
Git git = new Git(localRepo);
{
AsposeConstants.println("Cloning Repository [" + remotePath + "]....");
}
// First try to clone the repository
try {
Git.cloneRepository().setURI(remotePath).setDirectory(new File(localPath)).call();
} catch (Exception ex) {
// If clone fails, try to pull the changes
try {
git.pull().call();
} catch (Exception exPull) {
// Pull also failed. Throw this exception to caller
{
AsposeConstants.println("Pull also failed.");
}
// throw it
throw exPull;
}
}
} catch (Exception ex) {
throw new Exception("Could not download Repository from Github. Error: " + ex.getMessage());
}
}
use of org.eclipse.jgit.internal.storage.file.FileRepository in project Corgi by kevinYin.
the class JGitTest method init.
@Before
public void init() throws IOException {
localPath = "/Users/kevin/tmp/platform-parent";
remotePath = "http://gits.ibeiliao.net/platform/platform-parent.git";
localRepo = new FileRepository(localPath + "/.git");
git = new Git(localRepo);
}
Aggregations