jGit and Dirty Worktree

83 Views Asked by At

If I do pull and one of the local files are modified, I may get an exeception with status 'DIRTY_WORKTREE'. Which is the best approach to avoid this? What I did:

MergeResult mergeResult = git.pull().setRemote("origin").setRemoteBranchName(git.getRepository().getBranch()).call();
if (mergeResult != null) {
  if ( mergeResult.getConflicts() != null && !mergeResult.getConflicts().isEmpty()) {
  new GitConflictsDialog(FxGitDialog.this, git, new ArrayList<>(mergeResult.getConflicts().keySet())).showDialog();
} else if (mergeResult.getMergeStatus().isSuccessful() ) {
   showInformation(getDialogScene(), mergeResult.toString());
} else {
  final StringBuilder sb = new StringBuilder();
  for ( Map.Entry<String, ResolveMerger.MergeFailureReason> entry : mergeResult.getFailingPaths().entrySet() ){
      String reason = entry.getValue().toString();
      if ( reason.contains("DIRTY_WORKTREE")){
         reason = "has un-commited changes. " + reason;
      }
      sb.append( entry.getKey() ).append(" ").append( reason ).append( "\n\n");
   }
   sb.append( mergeResult );
   showError(getDialogScene(), sb.toString() );
}
0

There are 0 best solutions below