List of usage examples for org.eclipse.jgit.api Git notesRemove
public RemoveNoteCommand notesRemove()
From source file:gov.va.isaac.sync.git.SyncServiceGIT.java
License:Apache License
private Set<String> resolveMergeFailures(MergeFailType mergeFailType, String stashIDToApply, Map<String, MergeFailOption> resolutions) throws IllegalArgumentException, IOException, MergeFailure { log.debug("resolve merge failures called - mergeFailType: {} stashIDToApply: {} resolutions: {}", mergeFailType, stashIDToApply, resolutions); try {// ww w. ja v a 2 s. c o m Git git = getGit(); //We unfortunately, must know the mergeFailType option, because the resolution mechanism here uses OURS and THEIRS - but the //meaning of OURS and THEIRS reverse, depending on if you are recovering from a merge failure, or a stash apply failure. for (Entry<String, MergeFailOption> r : resolutions.entrySet()) { if (MergeFailOption.FAIL == r.getValue()) { throw new IllegalArgumentException("MergeFailOption.FAIL is not a valid option"); } else if (MergeFailOption.KEEP_LOCAL == r.getValue()) { log.debug("Keeping our local file for conflict {}", r.getKey()); git.checkout().addPath(r.getKey()) .setStage(MergeFailType.REMOTE_TO_LOCAL == mergeFailType ? Stage.OURS : Stage.THEIRS) .call(); } else if (MergeFailOption.KEEP_REMOTE == r.getValue()) { log.debug("Keeping remote file for conflict {}", r.getKey()); git.checkout().addPath(r.getKey()) .setStage(MergeFailType.REMOTE_TO_LOCAL == mergeFailType ? Stage.THEIRS : Stage.OURS) .call(); } else { throw new IllegalArgumentException("MergeFailOption is required"); } log.debug("calling add to mark merge resolved"); git.add().addFilepattern(r.getKey()).call(); } if (mergeFailType == MergeFailType.STASH_TO_LOCAL) { //clean up the stash log.debug("Dropping stash"); git.stashDrop().call(); } RevWalk walk = new RevWalk(git.getRepository()); Ref head = git.getRepository().getRef("refs/heads/master"); RevCommit commitWithPotentialNote = walk.parseCommit(head.getObjectId()); log.info("resolve merge failures Complete. Current status: " + statusToString(git.status().call())); RevCommit rc = git.commit().setMessage( "Merging with user specified merge failure resolution for files " + resolutions.keySet()) .call(); git.notesRemove().setObjectId(commitWithPotentialNote).call(); Set<String> filesChangedInCommit = listFilesChangedInCommit(git.getRepository(), commitWithPotentialNote.getId(), rc); //When we auto resolve to KEEP_REMOTE - these will have changed - make sure they are in the list. //seems like this shouldn't really be necessary - need to look into the listFilesChangedInCommit algorithm closer. //this might already be fixed by the rework on 11/12/14, but no time to validate at the moment. - doesn't do any harm. for (Entry<String, MergeFailOption> r : resolutions.entrySet()) { if (MergeFailOption.KEEP_REMOTE == r.getValue()) { filesChangedInCommit.add(r.getKey()); } if (MergeFailOption.KEEP_LOCAL == r.getValue()) { filesChangedInCommit.remove(r.getKey()); } } if (!StringUtils.isEmptyOrNull(stashIDToApply)) { log.info("Replaying stash identified in note"); try { git.stashApply().setStashRef(stashIDToApply).call(); log.debug("stash applied cleanly, dropping stash"); git.stashDrop().call(); } catch (StashApplyFailureException e) { log.debug("Stash failed to merge"); addNote(NOTE_FAILED_MERGE_HAPPENED_ON_STASH, git); throw new MergeFailure(git.status().call().getConflicting(), filesChangedInCommit); } } return filesChangedInCommit; } catch (GitAPIException e) { log.error("Unexpected", e); throw new IOException("Internal error", e); } }