use of org.eclipse.jgit.api.errors.GitAPIException in project zeppelin by apache.
the class GitNotebookRepo method checkpoint.
/* implemented as git add+commit
* @param pattern is the noteId
* @param commitMessage is a commit message (checkpoint message)
* (non-Javadoc)
* @see org.apache.zeppelin.notebook.repo.VFSNotebookRepo#checkpoint(String, String)
*/
@Override
public Revision checkpoint(String pattern, String commitMessage, AuthenticationInfo subject) {
Revision revision = Revision.EMPTY;
try {
List<DiffEntry> gitDiff = git.diff().call();
if (!gitDiff.isEmpty()) {
LOG.debug("Changes found for pattern '{}': {}", pattern, gitDiff);
DirCache added = git.add().addFilepattern(pattern).call();
LOG.debug("{} changes are about to be commited", added.getEntryCount());
RevCommit commit = git.commit().setMessage(commitMessage).call();
revision = new Revision(commit.getName(), commit.getShortMessage(), commit.getCommitTime());
} else {
LOG.debug("No changes found {}", pattern);
}
} catch (GitAPIException e) {
LOG.error("Failed to add+comit {} to Git", pattern, e);
}
return revision;
}
use of org.eclipse.jgit.api.errors.GitAPIException in project zeppelin by apache.
the class GitNotebookRepo method get.
/**
* the idea is to:
* 1. stash current changes
* 2. remember head commit and checkout to the desired revision
* 3. get note and checkout back to the head
* 4. apply stash on top and remove it
*/
@Override
public synchronized Note get(String noteId, String revId, AuthenticationInfo subject) throws IOException {
Note note = null;
RevCommit stash = null;
try {
List<DiffEntry> gitDiff = git.diff().setPathFilter(PathFilter.create(noteId)).call();
boolean modified = !gitDiff.isEmpty();
if (modified) {
// stash changes
stash = git.stashCreate().call();
Collection<RevCommit> stashes = git.stashList().call();
LOG.debug("Created stash : {}, stash size : {}", stash, stashes.size());
}
ObjectId head = git.getRepository().resolve(Constants.HEAD);
// checkout to target revision
git.checkout().setStartPoint(revId).addPath(noteId).call();
// get the note
note = super.get(noteId, subject);
// checkout back to head
git.checkout().setStartPoint(head.getName()).addPath(noteId).call();
if (modified && stash != null) {
// unstash changes
ObjectId applied = git.stashApply().setStashRef(stash.getName()).call();
ObjectId dropped = git.stashDrop().setStashRef(0).call();
Collection<RevCommit> stashes = git.stashList().call();
LOG.debug("Stash applied as : {}, and dropped : {}, stash size: {}", applied, dropped, stashes.size());
}
} catch (GitAPIException e) {
LOG.error("Failed to return note from revision \"{}\"", revId, e);
}
return note;
}
use of org.eclipse.jgit.api.errors.GitAPIException in project che by eclipse.
the class JGitConnection method rm.
@Override
public void rm(RmParams params) throws GitException {
List<String> files = params.getItems();
RmCommand rmCommand = getGit().rm();
rmCommand.setCached(params.isCached());
if (files != null) {
files.forEach(rmCommand::addFilepattern);
}
try {
rmCommand.call();
} catch (GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
use of org.eclipse.jgit.api.errors.GitAPIException in project che by eclipse.
the class JGitConnection method tagCreate.
@Override
public Tag tagCreate(TagCreateParams params) throws GitException {
String commit = params.getCommit();
if (commit == null) {
commit = Constants.HEAD;
}
try {
RevWalk revWalk = new RevWalk(repository);
RevObject revObject;
try {
revObject = revWalk.parseAny(repository.resolve(commit));
} finally {
revWalk.close();
}
TagCommand tagCommand = getGit().tag().setName(params.getName()).setObjectId(revObject).setMessage(params.getMessage()).setForceUpdate(params.isForce());
GitUser tagger = getUser();
if (tagger != null) {
tagCommand.setTagger(new PersonIdent(tagger.getName(), tagger.getEmail()));
}
Ref revTagRef = tagCommand.call();
RevTag revTag = revWalk.parseTag(revTagRef.getLeaf().getObjectId());
return newDto(Tag.class).withName(revTag.getTagName());
} catch (IOException | GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
use of org.eclipse.jgit.api.errors.GitAPIException in project che by eclipse.
the class JGitConnection method reset.
@Override
public void reset(ResetParams params) throws GitException {
try {
ResetCommand resetCommand = getGit().reset();
resetCommand.setRef(params.getCommit());
List<String> patterns = params.getFilePattern();
patterns.forEach(resetCommand::addPath);
if (params.getType() != null && patterns.isEmpty()) {
switch(params.getType()) {
case HARD:
resetCommand.setMode(ResetType.HARD);
break;
case KEEP:
resetCommand.setMode(ResetType.KEEP);
break;
case MERGE:
resetCommand.setMode(ResetType.MERGE);
break;
case MIXED:
resetCommand.setMode(ResetType.MIXED);
break;
case SOFT:
resetCommand.setMode(ResetType.SOFT);
break;
}
}
resetCommand.call();
} catch (GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
Aggregations