diff options
| author | Robin Stocker | 2011-03-21 17:34:56 +0000 |
|---|---|---|
| committer | Robin Stocker | 2011-03-22 10:21:45 +0000 |
| commit | 88e2c573bce212e3f31db02b43645a4bc2e6879c (patch) | |
| tree | 6721af4b057f30515318c19ab5eb3a95fa71d0df | |
| parent | 50a95e22fce923b86e77cccc14706ab2e3145c52 (diff) | |
| download | egit-88e2c573bce212e3f31db02b43645a4bc2e6879c.tar.gz egit-88e2c573bce212e3f31db02b43645a4bc2e6879c.tar.xz egit-88e2c573bce212e3f31db02b43645a4bc2e6879c.zip | |
Show warning when HEAD is detached after checkout
When checking out a remote tracking branch or a commit, an information
dialog is shown to inform the user about the 'detached HEAD' state. The
dialog can be dismissed with a "Do not show again" check.
Change-Id: I973e53b73dfe14d0d4eec2aef546f322b2ce17f1
Signed-off-by: Robin Stocker <robin@nibor.org>
5 files changed, 47 insertions, 1 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java index 251df36491..71e9d40a5f 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/PluginPreferenceInitializer.java @@ -76,6 +76,7 @@ public class PluginPreferenceInitializer extends AbstractPreferenceInitializer { store.setDefault(UIPreferences.REBASE_HIDE_CONFIRM, false); store.setDefault(UIPreferences.SHOW_INITIAL_CONFIG_DIALOG, true); store.setDefault(UIPreferences.SHOW_HOME_DIR_WARNING, MessageDialogWithToggle.PROMPT); + store.setDefault(UIPreferences.SHOW_DETACHED_HEAD_WARNING, MessageDialogWithToggle.PROMPT); store.setDefault(UIPreferences.SYNC_VIEW_CHANGESET_LABEL_FORMAT, GitChangeSetLabelProvider.DEFAULT_CHANGESET_FORMAT); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java index d540271641..c33656f3af 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIPreferences.java @@ -116,6 +116,8 @@ public class UIPreferences { /** */ public static final String SHOW_HOME_DIR_WARNING = "show_home_drive_warning"; //$NON-NLS-1$ /** */ + public static final String SHOW_DETACHED_HEAD_WARNING = "show_detached_head_warning"; //$NON-NLS-1$ + /** */ public static final String TREE_COMPARE_SHOW_EQUALS = "CompareTreeView_ShowEquals"; //$NON-NLS-1$ /** */ public static final String HISTORY_MAX_NUM_COMMITS = "HistoryView_MaxNumberOfCommmits"; //$NON-NLS-1$ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java index f8316897e7..fd02fe050b 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java @@ -2257,6 +2257,12 @@ public class UIText extends NLS { public static String BranchAction_repositoryState; /** */ + public static String BranchOperationUI_DetachedHeadTitle; + + /** */ + public static String BranchOperationUI_DetachedHeadMessage; + + /** */ public static String BranchResultDialog_CheckoutConflictsMessage; /** */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/BranchOperationUI.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/BranchOperationUI.java index 6a23dbee68..6eda5ef191 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/BranchOperationUI.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/BranchOperationUI.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.egit.ui.internal.branch; +import java.io.IOException; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -20,16 +22,20 @@ import org.eclipse.core.runtime.jobs.JobChangeAdapter; import org.eclipse.egit.core.op.BranchOperation; import org.eclipse.egit.ui.Activator; import org.eclipse.egit.ui.JobFamilies; +import org.eclipse.egit.ui.UIPreferences; import org.eclipse.egit.ui.UIText; import org.eclipse.egit.ui.internal.decorators.GitLightweightDecorator; import org.eclipse.egit.ui.internal.dialogs.BranchSelectionDialog; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.window.Window; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Repository; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; +import org.eclipse.jgit.api.CheckoutResult; /** * The UI wrapper for {@link BranchOperation} @@ -131,7 +137,7 @@ public class BranchOperationUI { job.addJobChangeListener(new JobChangeAdapter() { @Override public void done(IJobChangeEvent cevent) { - BranchResultDialog.show(bop.getResult(), repository, refName); + showResultDialog(); } }); job.schedule(); @@ -168,7 +174,36 @@ public class BranchOperationUI { bop = new BranchOperation(repository, refName); bop.execute(monitor); + showResultDialog(); + } + + private void showResultDialog() { BranchResultDialog.show(bop.getResult(), repository, refName); + try { + if (ObjectId.isId(repository.getFullBranch()) && bop.getResult().getStatus() == CheckoutResult.Status.OK) + showDetachedHeadWarning(); + } catch (IOException e) { + // Don't show warning then. + } + } + + private void showDetachedHeadWarning() { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + IPreferenceStore store = Activator.getDefault() + .getPreferenceStore(); + + if (store.getString(UIPreferences.SHOW_DETACHED_HEAD_WARNING) + .equals(MessageDialogWithToggle.PROMPT)) { + String toggleMessage = UIText.ConfigurationChecker_doNotShowAgain; + MessageDialogWithToggle.openInformation(getShell(), + UIText.BranchOperationUI_DetachedHeadTitle, + UIText.BranchOperationUI_DetachedHeadMessage, + toggleMessage, false, store, + UIPreferences.SHOW_DETACHED_HEAD_WARNING); + } + } + }); } private Shell getShell() { diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties index 7d2eaa466f..21698358af 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties @@ -757,6 +757,8 @@ BranchAction_branchFailed=Branch failed BranchAction_cannotCheckout=Cannot checkout now BranchAction_checkingOut=Checking out {0} - {1} BranchAction_repositoryState=Repository state: {0} +BranchOperationUI_DetachedHeadTitle=Detached HEAD +BranchOperationUI_DetachedHeadMessage=You are in the 'detached HEAD' state. This means that you don't have a local branch checked out.\n\nYou can look around, but it's not recommended to commit changes. The reason is that these commits would not be on any branch and would not be visible after checking out another branch.\n\nIf you want to make changes, create or checkout a local branch first. BranchResultDialog_CheckoutConflictsMessage=The files below have uncommited changes which would be lost when checking out "{0}".\nPlease either add the changes to the Repository by creating or amending a commit with these changes or dispose the changes by resetting your current HEAD. BranchResultDialog_CheckoutConflictsTitle=Checkout Conflicts BranchSelectionDialog_TitleCheckout=Checkout: {0} |
