-1

I would like to ask regarding the below code lines why i get null pointer Exception. Is this something Git related which i don't understand ?

refsideMerge=existingRepo.exactRef("refs/heads/sideMerge");
tmpMerge = git.merge();
tmpMerge.include(refsideMerge);
tmpMerge.setCommit(false);//dry run to get conflicting files
tmpMergeRes = tmpMerge.call();

Map allConflicts = tmpMergeRes.getConflicts();          
 for (Map.Entry<String,int[][]> entry : tmpMergeRes.getConflicts().entrySet()) {
 System.out.println("Key: " + entry.getKey());
  for(int[] arr : entry.getValue()) {
   System.out.println("value: " + Arrays.toString(arr));
  }
}

Description:

After Repeatedly running this code snippet i bump into Nullpointer exception. I want to test my xml Parsing for Merge Conflicts that's why i need repeated Merge Conflicts to handle. Currently only the Merge part is used to generate conflicts.

As far as i realized it stops at the below line

Map allConflicts = tmpMergeRes.getConflicts();

1 Answers1

0

So the Explanations i found for this:

Basically whenever you run git merge it will touch the working directory even if its dry run as its written there.

There are 2 possible solutions: First, Second.

For now i will go with resetting the head after dry-run. This is a simple solution, The other solution with ResolveMerger would be better but still investigating how to do it.

refsideMerge=existingRepo.exactRef("refs/heads/sideMerge");
tmpMerge = git.merge();
tmpMerge.include(refsideMerge);
tmpMerge.setCommit(false);//dry run to get conflicting files
tmpMergeRes = tmpMerge.call();

Map allConflicts = tmpMergeRes.getConflicts();          
 for (Map.Entry<String,int[][]> entry : tmpMergeRes.getConflicts().entrySet()) {
 System.out.println("Key: " + entry.getKey());
  for(int[] arr : entry.getValue()) {
   System.out.println("value: " + Arrays.toString(arr));
  }
}
git.reset().setMode(ResetType.HARD).call();