Skip to content

Commit

Permalink
[wip] Use default preferences for preferred MergeStrategy
Browse files Browse the repository at this point in the history
The default scope was not correctly taken into account.

Bug: 485385
Change-Id: If38c2c4402ae6b1d03e1dc471b3be3885432b995
Signed-off-by: Laurent Delaigue <laurent.delaigue@obeo.fr>
  • Loading branch information
ldelaigue authored and hudson committed Jan 20, 2016
1 parent 1ef0cb6 commit 1d59523
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
14 changes: 13 additions & 1 deletion org.eclipse.egit.core/src/org/eclipse/egit/core/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,24 @@ public void optionsChanged(DebugOptions options) {
* @since 4.1
*/
public MergeStrategy getPreferredMergeStrategy() {
// Get preferences set by user in the UI
final IEclipsePreferences prefs = InstanceScope.INSTANCE
.getNode(Activator.getPluginId());
String preferredMergeStrategyKey = prefs.get(
GitCorePreferences.core_preferredMergeStrategy, null);

// Get default preferences, wherever they are defined
if (preferredMergeStrategyKey == null
|| preferredMergeStrategyKey.isEmpty()) {
final IEclipsePreferences defaultPrefs = DefaultScope.INSTANCE
.getNode(Activator.getPluginId());
preferredMergeStrategyKey = defaultPrefs.get(
GitCorePreferences.core_preferredMergeStrategy, null);
}
if (preferredMergeStrategyKey != null
&& !preferredMergeStrategyKey.isEmpty()) {
&& !preferredMergeStrategyKey.isEmpty()
&& !GitCorePreferences.core_preferredMergeStrategy_Default
.equals(preferredMergeStrategyKey)) {
MergeStrategy result = MergeStrategy.get(preferredMergeStrategyKey);
if (result != null) {
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,11 @@ public class GitCorePreferences {
* {@code MergeStrategy.get(key)}.
*/
public static final String core_preferredMergeStrategy = "core_preferredMergeStrategy"; //$NON-NLS-1$

/**
* Default key value of the core_preferredMergeStrategy property in the UI,
* which means that EGit must not pass any specific merge strategy to JGit,
* to let JGit use its default behavior.
*/
public static final String core_preferredMergeStrategy_Default = "jgit-default-mergeStrategy"; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,14 @@ private String[][] getAvailableMergeStrategies() {
org.eclipse.egit.core.Activator coreActivator = org.eclipse.egit.core.Activator
.getDefault();
List<String[]> strategies = new ArrayList<>();

// We need to add a default name for EGit default strategy in order to
// be able to distinguish a state where users haven't chosen any
// preference (in this case, values defined in eclipse configuration
// files may apply) or if they have chosen the default merge strategy.
strategies.add(new String[] {
UIText.GitPreferenceRoot_defaultMergeStrategyLabel, "" }); //$NON-NLS-1$
UIText.GitPreferenceRoot_defaultMergeStrategyLabel,
GitCorePreferences.core_preferredMergeStrategy_Default });
for (MergeStrategyDescriptor strategy : coreActivator
.getRegisteredMergeStrategies()) {
strategies.add(new String[] { strategy.getLabel(),
Expand Down

0 comments on commit 1d59523

Please sign in to comment.