Bug 501111 - Cannot execute pull with MergeStrategy.THEIRS
Summary: Cannot execute pull with MergeStrategy.THEIRS
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 4.4   Edit
Hardware: PC Linux
: P3 normal with 4 votes (vote)
Target Milestone: 5.12   Edit
Assignee: Thomas Wolf CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-08 17:39 EDT by Marek Kaluzny CLA
Modified: 2021-04-20 05:56 EDT (History)
8 users (show)

See Also:


Attachments
a standalone java program showing the bug (2.50 KB, application/octet-stream)
2016-09-09 06:20 EDT, Christian Halstrick CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Kaluzny CLA 2016-09-08 17:39:30 EDT
When I try to execute pull with following code:
 git.pull()
   .setStrategy(MergeStrategy.THEIRS)
   .setRebase(true)
   .call().isSuccessful();

I got following error:
java.lang.ClassCastException: org.eclipse.jgit.merge.StrategyOneSided$OneSide cannot be cast to org.eclipse.jgit.merge.ResolveMerger
	at org.eclipse.jgit.api.CherryPickCommand.call(CherryPickCommand.java:152) ~[org.eclipse.jgit-4.4.1.201607150455-r.jar:4.4.1.201607150455-r]
	at org.eclipse.jgit.api.RebaseCommand.cherryPickCommitFlattening(RebaseCommand.java:527) ~[org.eclipse.jgit-4.4.1.201607150455-r.jar:4.4.1.201607150455-r]
	at org.eclipse.jgit.api.RebaseCommand.cherryPickCommit(RebaseCommand.java:503) ~[org.eclipse.jgit-4.4.1.201607150455-r.jar:4.4.1.201607150455-r]
	at org.eclipse.jgit.api.RebaseCommand.processStep(RebaseCommand.java:454) ~[org.eclipse.jgit-4.4.1.201607150455-r.jar:4.4.1.201607150455-r]
	at org.eclipse.jgit.api.RebaseCommand.call(RebaseCommand.java:368) ~[org.eclipse.jgit-4.4.1.201607150455-r.jar:4.4.1.201607150455-r]
	at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:324) ~[org.eclipse.jgit-4.4.1.201607150455-r.jar:4.4.1.201607150455-r]
Comment 1 Christian Halstrick CLA 2016-09-09 03:27:57 EDT
That looks like a severe bug. I'll have a look
Comment 2 Christian Halstrick CLA 2016-09-09 06:19:01 EDT
I attach my small standalone program which reproduces this bug. I also have a fix prepared but I am not sure exactly what you want. If you look at [1] you see the term "ours" is used twice. Once as a merge strategy and once as an option to the recursive merge strategy. Which one do you want.

E.g. if you have branch master and branch side and on side a brand new file "new.txt" was created. If you are sitting on master do "git merge side" .... do you want that the file "new.txt" exists afterwards or not.

[1] https://git-scm.com/docs/merge-strategies
Comment 3 Christian Halstrick CLA 2016-09-09 06:20:43 EDT
Created attachment 264072 [details]
a standalone java program showing the bug
Comment 4 Andrey Pavlenko CLA 2016-12-15 07:46:36 EST
The same issue for StashApplyCommand. As I see in the code, the merger is casted to ResolveMerger - https://github.com/eclipse/jgit/blob/ad1548b49ee3954814f95d14e111d5e70c811186/org.eclipse.jgit/src/org/eclipse/jgit/api/StashApplyCommand.java#L195:

ResolveMerger merger = (ResolveMerger) strategy.newMerger(repo);

However, in case of the OURS/THEIRS MergeStrategy, the merger is of type org.eclipse.jgit.merge.StrategyOneSided.OneSide.
Comment 5 Matthieu Scholler CLA 2018-02-16 06:50:22 EST
While there is a fix being issued, is there a recommended workaround?
Comment 6 Saket Narayan CLA 2020-06-17 03:09:00 EDT
Any chances this can be fixed soon? This bug has been around for 5 years and hasn't been fixed yet. It's unfortunate that JGit is the only java git library available out there and it has so many bugs, especially related to rebase.
Comment 7 Karolina Bozkova CLA 2021-04-10 06:51:50 EDT
Same issue for RebaseCommand. Any progress on this issue? Or does anybody have a workaround?
Comment 8 Eclipse Genie CLA 2021-04-12 18:01:16 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jgit/jgit/+/179234