use of me.sheimi.sgit.ssh.SgitTransportCallback in project MGit by maks.
the class PullTask method pullRepo.
public boolean pullRepo() {
Git git;
try {
git = mRepo.getGit();
} catch (StopTaskException e) {
return false;
}
PullCommand pullCommand = git.pull().setRemote(mRemote).setProgressMonitor(new BasicProgressMonitor()).setTransportConfigCallback(new SgitTransportCallback());
setCredentials(pullCommand);
try {
String branch = null;
if (mForcePull) {
branch = git.getRepository().getFullBranch();
if (!branch.startsWith("refs/heads/")) {
setException(new GitAPIException("not on branch") {
}, R.string.error_pull_failed_not_on_branch);
return false;
}
branch = branch.substring(11);
BasicProgressMonitor bpm = new BasicProgressMonitor();
bpm.beginTask("clearing repo state", 3);
git.getRepository().writeMergeCommitMsg(null);
git.getRepository().writeMergeHeads(null);
bpm.update(1);
try {
git.rebase().setOperation(RebaseCommand.Operation.ABORT).call();
} catch (Exception e) {
}
bpm.update(2);
git.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD").call();
bpm.endTask();
}
pullCommand.call();
if (mForcePull) {
BasicProgressMonitor bpm = new BasicProgressMonitor();
bpm.beginTask("resetting to " + mRemote + "/" + branch, 1);
git.reset().setMode(ResetCommand.ResetType.HARD).setRef(mRemote + "/" + branch).call();
bpm.endTask();
}
} catch (TransportException e) {
setException(e);
handleAuthError(this);
return false;
} catch (Exception e) {
setException(e, R.string.error_pull_failed);
return false;
} catch (OutOfMemoryError e) {
setException(e, R.string.error_out_of_memory);
return false;
} catch (Throwable e) {
setException(e);
return false;
}
mRepo.updateLatestCommitInfo();
return true;
}
use of me.sheimi.sgit.ssh.SgitTransportCallback in project MGit by maks.
the class PushTask method pushRepo.
public boolean pushRepo() {
Git git;
try {
git = mRepo.getGit();
} catch (StopTaskException e1) {
return false;
}
PushCommand pushCommand = git.push().setPushTags().setProgressMonitor(new BasicProgressMonitor()).setTransportConfigCallback(new SgitTransportCallback()).setRemote(mRemote);
if (mPushAll) {
pushCommand.setPushAll();
} else {
RefSpec spec = new RefSpec(mRepo.getBranchName());
pushCommand.setRefSpecs(spec);
}
if (mForcePush) {
pushCommand.setForce(true);
}
setCredentials(pushCommand);
try {
Iterable<PushResult> result = pushCommand.call();
for (PushResult r : result) {
Collection<RemoteRefUpdate> updates = r.getRemoteUpdates();
for (RemoteRefUpdate update : updates) {
parseRemoteRefUpdate(update);
}
}
} catch (TransportException e) {
setException(e);
handleAuthError(this);
return false;
} catch (Exception e) {
setException(e);
return false;
} catch (OutOfMemoryError e) {
setException(e, R.string.error_out_of_memory);
return false;
} catch (Throwable e) {
setException(e);
return false;
}
return true;
}
use of me.sheimi.sgit.ssh.SgitTransportCallback in project MGit by maks.
the class CloneTask method cloneRepo.
public boolean cloneRepo() {
File localRepo = mRepo.getDir();
CloneCommand cloneCommand = Git.cloneRepository().setURI(mRepo.getRemoteURL()).setCloneAllBranches(true).setProgressMonitor(new RepoCloneMonitor()).setTransportConfigCallback(new SgitTransportCallback()).setDirectory(localRepo).setCloneSubmodules(mCloneRecursive);
setCredentials(cloneCommand);
try {
cloneCommand.call();
Profile.setLastCloneSuccess();
} catch (InvalidRemoteException e) {
setException(e, R.string.error_invalid_remote);
Profile.setLastCloneFailed(mRepo);
return false;
} catch (TransportException e) {
setException(e);
Profile.setLastCloneFailed(mRepo);
handleAuthError(this);
return false;
} catch (GitAPIException e) {
setException(e, R.string.error_clone_failed);
return false;
} catch (JGitInternalException e) {
setException(e);
return false;
} catch (OutOfMemoryError e) {
setException(e, R.string.error_out_of_memory);
return false;
} catch (Throwable e) {
setException(e);
return false;
}
return true;
}
use of me.sheimi.sgit.ssh.SgitTransportCallback in project MGit by maks.
the class FetchTask method fetchRepo.
private boolean fetchRepo(String remote) {
Git git;
try {
git = mRepo.getGit();
} catch (StopTaskException e) {
return false;
}
final FetchCommand fetchCommand = git.fetch().setProgressMonitor(new BasicProgressMonitor()).setTransportConfigCallback(new SgitTransportCallback()).setRemote(remote);
setCredentials(fetchCommand);
try {
fetchCommand.call();
} catch (TransportException e) {
setException(e);
handleAuthError(this);
return false;
} catch (Exception e) {
setException(e, R.string.error_pull_failed);
return false;
} catch (OutOfMemoryError e) {
setException(e, R.string.error_out_of_memory);
return false;
} catch (Throwable e) {
setException(e);
return false;
}
mRepo.updateLatestCommitInfo();
return true;
}
Aggregations