Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2018-05-31 20:26:12 +0000
committerMatthias Sohn2018-06-04 20:53:32 +0000
commitd9700cf14f6ffafdb58cdc8087e664159efdefc0 (patch)
treebe509497a2d4622a0aad8635d28e23b90a04ad0f /org.eclipse.egit.ui/src/org
parentcdda987e0ddfbb0ef3b617c5b78fc08cd80888d5 (diff)
downloadegit-d9700cf14f6ffafdb58cdc8087e664159efdefc0.tar.gz
egit-d9700cf14f6ffafdb58cdc8087e664159efdefc0.tar.xz
egit-d9700cf14f6ffafdb58cdc8087e664159efdefc0.zip
Do not display "[NO-HEAD]" for empty repository
After a new repository has been created, its "master" branch is an unborn branch. EGit showed "NO-HEAD" in the decorations for this case. This is confusing for novices and looks like something went wrong. The canonical implementation shows after "git init; git status": "On branch master" and "Initial commit". So let's display "master" in this case, too. Reserve the "NO-HEAD" for cases where there is really no HEAD. Also show such a HEAD in the repositories view under "References" and decorate it as "[master] unborn; will be created by commit". Limit showing such a HEAD to the repositories view: the content provider is used in other places where such a HEAD node would only cause confusion or malfunctioning. Use an extension factory to create the content provider for the repositories view; in this way the new behavior can be enabled there only without having to touch all the other places where this content provider is used. Adapt the label provider to handle the new case, and ensure that the history page doesn't get confused and broken if HEAD is such an unborn branch. In the staging view, use the the warning message label above the commit message text area to tell the user that this commit will create the still unborn branch. Bug: 533596 Change-Id: Ifd0547a156f0a5616ce7e032ea8daebd2596f31e Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui/src/org')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/ToggleableWarningLabel.java56
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java5
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java27
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewExtensionFactory.java27
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java16
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java30
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/ToggleableLabel.java60
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties2
9 files changed, 206 insertions, 23 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index cacf395d37..ec072e1c9c 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -3699,6 +3699,9 @@ public class UIText extends NLS {
public static String RepositoriesViewLabelProvider_TagsNodeText;
/** */
+ public static String RepositoriesViewLabelProvider_UnbornBranchText;
+
+ /** */
public static String DialogsPreferencePage_DetachedHeadCombo;
/** */
@@ -5378,6 +5381,9 @@ public class UIText extends NLS {
public static String StagingView_IgnoreItemMenuLabel;
/** */
+ public static String StagingView_InitialCommitText;
+
+ /** */
public static String StagingView_IgnoreFolderMenuLabel;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/ToggleableWarningLabel.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/ToggleableWarningLabel.java
index df4a6d43b8..b5ca1af6e7 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/ToggleableWarningLabel.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/ToggleableWarningLabel.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2012, Robin Stocker <robin@nibor.org>
+ * Copyright (C) 2012, 2018 Robin Stocker <robin@nibor.org> and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -12,6 +12,7 @@ package org.eclipse.egit.ui.internal.components;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
@@ -27,6 +28,10 @@ public class ToggleableWarningLabel extends Composite {
private Label warningText;
+ private Label image;
+
+ private boolean isBuiltInImage;
+
/**
* Constructs the composite. Note that for the toggling to work, its parent
* composite must use a grid layout.
@@ -40,26 +45,29 @@ public class ToggleableWarningLabel extends Composite {
setVisible(false);
setLayout(new GridLayout(2, false));
- Label image = new Label(this, SWT.NONE);
+ image = new Label(this, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.BEGINNING)
.applyTo(image);
image.setImage(PlatformUI.getWorkbench().getSharedImages()
.getImage(ISharedImages.IMG_OBJS_WARN_TSK));
-
+ isBuiltInImage = true;
warningText = new Label(this, SWT.WRAP);
GridDataFactory.fillDefaults().grab(true, true).applyTo(warningText);
}
/**
- * Set the warning message and show the label.
+ * Set the warning message and show the label. Forces the image to the
+ * warning icon if it had been changed.
*
* @param message
*/
public void showMessage(String message) {
- warningText.setText(message);
- layout(true);
-
- changeVisibility(true);
+ if (!isBuiltInImage) {
+ image.setImage(PlatformUI.getWorkbench().getSharedImages()
+ .getImage(ISharedImages.IMG_OBJS_WARN_TSK));
+ isBuiltInImage = true;
+ }
+ setText(message);
}
/**
@@ -70,7 +78,37 @@ public class ToggleableWarningLabel extends Composite {
changeVisibility(false);
}
- private void changeVisibility(boolean visible) {
+ /**
+ * Sets a new image. Does not change visibility or layout. Can be used by
+ * subclasses to define their own images.
+ *
+ * @param image
+ * to set
+ */
+ protected void setImage(Image image) {
+ this.image.setImage(image);
+ isBuiltInImage = false;
+ }
+
+ /**
+ * Sets the text and shows the Composite.
+ *
+ * @param message
+ * to show
+ */
+ protected void setText(String message) {
+ warningText.setText(message);
+ layout(true);
+ changeVisibility(true);
+ }
+
+ /**
+ * Defines the visibility of the whole Composite.
+ *
+ * @param visible
+ * whether to show the composite
+ */
+ protected void changeVisibility(boolean visible) {
setVisible(visible);
GridData data = (GridData) getLayoutData();
data.exclude = !visible;
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
index c00617b0ce..9a3a810014 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
@@ -1829,7 +1829,10 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
case ADDITIONALREF:
input = new HistoryPageInput(repo);
ref = ((AdditionalRefNode) repoNode).getObject();
- showRef = true;
+ if (ref.getObjectId() == null) {
+ ref = null;
+ }
+ showRef = ref != null;
break;
case TAG:
input = new HistoryPageInput(repo);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java
index 591054be27..6514bdd850 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewContentProvider.java
@@ -109,14 +109,29 @@ public class RepositoriesViewContentProvider implements ITreeContentProvider,
private boolean branchHierarchyMode = false;
+ private boolean showUnbornHead = false;
+
private Map<Repository, Map<String, Ref>> branchRefs = new WeakHashMap<>();
private Map<Repository, ListenerHandle> refsChangedListeners = new WeakHashMap<>();
/**
- * Constructs this instance
+ * Constructs a new {@link RepositoriesViewContentProvider} that doesn't
+ * show an unborn branch as HEAD.
*/
public RepositoriesViewContentProvider() {
+ this(false);
+ }
+
+ /**
+ * Constructs a new {@link RepositoriesViewContentProvider}.
+ *
+ * @param showUnbornHead
+ * whether to show HEAD even if it is an unborn branch
+ */
+ public RepositoriesViewContentProvider(boolean showUnbornHead) {
+ super();
+ this.showUnbornHead = showUnbornHead;
ICommandService srv = CommonUtils.getService(PlatformUI.getWorkbench(), ICommandService.class);
commandState = srv.getCommand(
ToggleBranchHierarchyCommand.ID)
@@ -220,8 +235,16 @@ public class RepositoriesViewContentProvider implements ITreeContentProvider,
refs.add(new AdditionalRefNode(node, repo, refEntry
.getValue()));
}
- for (Ref r : repo.getRefDatabase().getAdditionalRefs())
+ for (Ref r : repo.getRefDatabase().getAdditionalRefs()) {
refs.add(new AdditionalRefNode(node, repo, r));
+ }
+ if (showUnbornHead) {
+ Ref head = repo.exactRef(Constants.HEAD);
+ if (head != null && head.isSymbolic()
+ && head.getObjectId() == null) {
+ refs.add(new AdditionalRefNode(node, repo, head));
+ }
+ }
} catch (Exception e) {
return handleException(e, node);
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewExtensionFactory.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewExtensionFactory.java
new file mode 100644
index 0000000000..04f5c62419
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewExtensionFactory.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Thomas Wolf <thomas.wolf@paranor.ch>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.repository;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IExecutableExtensionFactory;
+
+/**
+ * Extension factory to create the content provider for the repositories view.
+ */
+public class RepositoriesViewExtensionFactory
+ implements IExecutableExtensionFactory {
+
+ @Override
+ public Object create() throws CoreException {
+ return new RepositoriesViewContentProvider(true);
+ }
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java
index aa096a8677..f625ff639a 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java
@@ -401,28 +401,30 @@ public class RepositoriesViewLabelProvider extends ColumnLabelProvider
StyledString refName = new StyledString(
Repository.shortenRefName(ref.getName()));
- ObjectId refId;
if (ref.isSymbolic()) {
refName.append(' ');
refName.append('[', StyledString.DECORATIONS_STYLER);
refName.append(ref.getLeaf().getName(),
StyledString.DECORATIONS_STYLER);
refName.append(']', StyledString.DECORATIONS_STYLER);
- refId = ref.getLeaf().getObjectId();
- } else
- refId = ref.getObjectId();
-
+ }
+ ObjectId refId = ref.getObjectId();
refName.append(' ');
RevCommit commit = getLatestCommit(node);
- if (commit != null)
+ if (commit != null) {
refName.append(abbreviate(commit),
StyledString.QUALIFIER_STYLER)
.append(' ')
.append(commit.getShortMessage(),
StyledString.QUALIFIER_STYLER);
- else
+ } else if (!ref.isSymbolic() || refId != null) {
refName.append(abbreviate(refId),
StyledString.QUALIFIER_STYLER);
+ } else {
+ refName.append(
+ UIText.RepositoriesViewLabelProvider_UnbornBranchText,
+ StyledString.QUALIFIER_STYLER);
+ }
return refName;
case WORKINGDIR:
StyledString dirString = new StyledString(
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
index d57ffbe100..ae17af6ec4 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2011, 2017 Bernard Leach <leachbj@bouncycastle.org> and others.
+ * Copyright (C) 2011, 2018 Bernard Leach <leachbj@bouncycastle.org> and others.
* Copyright (C) 2015 SAP SE (Christian Georgi <christian.georgi@sap.com>)
* Copyright (C) 2015 Denis Zygann <d.zygann@web.de>
* Copyright (C) 2016 IBM (Daniel Megert <daniel_megert@ch.ibm.com>)
@@ -22,6 +22,7 @@ package org.eclipse.egit.ui.internal.staging;
import static org.eclipse.egit.ui.internal.CommonUtils.runCommand;
import java.io.File;
+import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
@@ -94,7 +95,6 @@ import org.eclipse.egit.ui.internal.commit.CommitMessageHistory;
import org.eclipse.egit.ui.internal.commit.CommitProposalProcessor;
import org.eclipse.egit.ui.internal.commit.DiffViewer;
import org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction;
-import org.eclipse.egit.ui.internal.components.ToggleableWarningLabel;
import org.eclipse.egit.ui.internal.decorators.IProblemDecoratable;
import org.eclipse.egit.ui.internal.decorators.ProblemLabelDecorator;
import org.eclipse.egit.ui.internal.dialogs.CommitMessageArea;
@@ -166,6 +166,7 @@ import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.events.ListenerHandle;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -283,7 +284,7 @@ public class StagingView extends ViewPart
private TreeViewer unstagedViewer;
- private ToggleableWarningLabel warningLabel;
+ private ToggleableLabel warningLabel;
private Text filterText;
@@ -352,6 +353,10 @@ public class StagingView extends ViewPart
private Set<IPath> pathsToExpandInUnstaged = new HashSet<>();
+ private boolean isUnbornHead;
+
+ private String currentBranch;
+
/**
* Presentation mode of the staged/unstaged files.
*/
@@ -1007,7 +1012,7 @@ public class StagingView extends ViewPart
GridLayoutFactory.fillDefaults().numColumns(1)
.applyTo(commitMessageComposite);
- warningLabel = new ToggleableWarningLabel(commitMessageComposite,
+ warningLabel = new ToggleableLabel(commitMessageComposite,
SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).exclude(true)
.applyTo(warningLabel);
@@ -2682,6 +2687,10 @@ public class StagingView extends ViewPart
if (message != null) {
warningLabel.showMessage(message);
needsRedraw = true;
+ } else if (isUnbornHead) {
+ warningLabel.showInfo(MessageFormat.format(
+ UIText.StagingView_InitialCommitText, currentBranch));
+ needsRedraw = true;
} else {
needsRedraw = warningLabel.getVisible();
warningLabel.hideMessage();
@@ -3777,6 +3786,19 @@ public class StagingView extends ViewPart
&& noConflicts;
rebaseContinueButton.setEnabled(rebaseContinueEnabled);
+ isUnbornHead = false;
+ if (repository.getRepositoryState() == RepositoryState.SAFE) {
+ try {
+ Ref head = repository.exactRef(Constants.HEAD);
+ if (head != null && head.isSymbolic()
+ && head.getObjectId() == null) {
+ isUnbornHead = true;
+ }
+ currentBranch = repository.getBranch();
+ } catch (IOException e) {
+ Activator.logError(e.getLocalizedMessage(), e);
+ }
+ }
form.setText(GitLabels.getStyledLabelSafe(repository).toString());
updateCommitMessageComponent(repositoryChanged, indexDiffAvailable);
enableCommitWidgets(indexDiffAvailable && noConflicts);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/ToggleableLabel.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/ToggleableLabel.java
new file mode 100644
index 0000000000..674a3a7e59
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/ToggleableLabel.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.staging;
+
+import org.eclipse.egit.ui.internal.components.ToggleableWarningLabel;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * A toggleable label that can show a warning or an info message.
+ */
+public class ToggleableLabel extends ToggleableWarningLabel {
+
+ private boolean isInfo;
+
+ /**
+ * Creates a new ToggleableLabel
+ *
+ * @param parent
+ * of the new label
+ * @param style
+ * of the Composite
+ */
+ public ToggleableLabel(Composite parent, int style) {
+ super(parent, style);
+ isInfo = false;
+ }
+
+ /**
+ * Show the info message with an info icon.
+ *
+ * @param message
+ * to show
+ */
+ public void showInfo(String message) {
+ if (!isInfo) {
+ setImage(PlatformUI.getWorkbench().getSharedImages()
+ .getImage(ISharedImages.IMG_OBJS_INFO_TSK));
+ isInfo = true;
+ }
+ setText(message);
+ layout(true);
+ changeVisibility(true);
+ }
+
+ @Override
+ public void showMessage(String message) {
+ super.showMessage(message);
+ isInfo = false;
+ }
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index 704e466720..27db53edc6 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -1310,6 +1310,7 @@ RepositoriesViewLabelProvider_StashNodeText=Stashed Commits
RepositoriesViewLabelProvider_SubmodulesNodeText=Submodules
RepositoriesViewLabelProvider_SymbolicRefNodeText=References
RepositoriesViewLabelProvider_TagsNodeText=Tags
+RepositoriesViewLabelProvider_UnbornBranchText=unborn branch; will be created on commit
DialogsPreferencePage_DetachedHeadCombo=D&etached HEAD and checkout of remote-tracking branch
DialogsPreferencePage_HideConfirmationGroupHeader=Show confirmation dialogs
@@ -1877,6 +1878,7 @@ StagingView_StageAllItemTooltip=Add all files including not selected ones to the
StagingView_StageItemMenuLabel=&Add to Index
StagingView_StageItemTooltip=Add selected files to the index
StagingView_IgnoreItemMenuLabel=&Ignore
+StagingView_InitialCommitText=Unborn branch: this commit will create the branch ''{0}''.
StagingView_IgnoreFolderMenuLabel=Ignore &Folder
StagingView_DeleteItemMenuLabel=&Delete
StagingView_Presentation=Presentation

Back to the top