diff --git a/.gitignore b/.gitignore index a5d4cc8..896c55f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +*.jar + # User-specific stuff: .idea/**/workspace.xml .idea/**/tasks.xml diff --git a/.idea/misc.xml b/.idea/misc.xml index 55b0f50..91a4741 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -38,7 +38,7 @@ - + \ No newline at end of file diff --git a/README.md b/README.md index 84a3af2..b76ceef 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # Sourcegraph for JetBrains IDEs [![JetBrains Plugin](https://img.shields.io/badge/JetBrains-Sourcegraph-green.svg)](https://plugins.jetbrains.com/plugin/9682-sourcegraph) -The Sourcegraph plugin for JetBrains IDEs enables you to quickly open and search code on Sourcegraph easily and efficiently in JetBrains IDEs such as IntelliJ. This plugin works with most JetBrains IDEs: +- Search snippets of code on Sourcegraph. +- Copy and share a link to code on Sourcegraph. +- Quickly go from files in your editor to Sourcegraph. + +The plugin works with all JetBrains IDEs including: - IntelliJ IDEA - IntelliJ IDEA Community Edition @@ -16,49 +20,45 @@ The Sourcegraph plugin for JetBrains IDEs enables you to quickly open and search - Rider - Android Studio - ## Installation - Select `IntelliJ IDEA` then `Preferences` (or use ⌘,) - Click `Plugins` in the left-hand pane. - Choose `Browse repositories...` - Search for `Sourcegraph` -> `Install` +- Restart your IDE if needed, then select some code and choose `Sourcegraph` in the right-click context menu to see actions and keyboard shortcuts. +## Configuring for use with a private Sourcegraph instance -## Usage - -Right click any code or selection and choose `Sourcegraph: Open` or `Sourcegraph: Search`. - -Keyboard Shortcuts: +The plugin is configurable _globally_ by creating a `sourcegraph-jetbrains.properties` in your home directory. For example, modify the following URL to match your on-premises Sourcegraph instance URL: -| Description | Mac | Linux / Windows | -|---------------------------------|---------------------|------------------| -| Open file in Sourcegraph | Option+A | Alt+A | -| Search selection in Sourcegraph | Option+S | Alt+S | - - -## Settings +``` +url = https://sourcegraph.example.com +``` -The plugin is configurable by creating a `sourcegraph-jetbrains.properties` in your home directory. For example, modify the following URL to match your on-premises Sourcegraph instance URL: +You may also choose to configure it _per repository_ using a `.idea/sourcegraph.xml` file in your repository like so: -``` -url = https://sourcegraph.com +```xml + + + + + ``` -By default, the plugin will use the `origin` git remote to determine which repository on Sourcegraph corresponds to the local repository. You may configure this by adding a `sourcegraph` remote which will take priority. +By default, the plugin will use the `origin` git remote to determine which repository on Sourcegraph corresponds to your local repository. If your `origin` remote doesn't match Sourcegraph, you may instead configure a `sourcegraph` Git remote which will take priority. ## Questions & Feedback Please file an issue: https://github.com/sourcegraph/sourcegraph-jetbrains/issues/new - ## Uninstallation - Select `IntelliJ IDEA` then `Preferences` (or use ⌘,) - Click `Plugins` in the left-hand pane. - Search for `Sourcegraph` -> Right click -> `Uninstall` (or uncheck to disable) - ## Development - Start IntelliJ and choose `Check out from Version Control` -> `Git` -> `https://github.com/sourcegraph/sourcegraph-jetbrains` @@ -67,13 +67,23 @@ Please file an issue: https://github.com/sourcegraph/sourcegraph-jetbrains/issue 1. Update `plugin.xml` (change version AND describe changes in change notes). 2. Update `Util.java` (change `VERSION` constant). 3. Update `README.md` (copy changelog from plugin.xml). - 5. choose `Build` -> `Prepare Plugin Module 'sourcegraph' For Deployment` - 6. `git commit -m "all: release v"` and `git push` and `git tag v` and `git push --tags` + 4. choose `Build` -> `Prepare Plugin Module 'sourcegraph' For Deployment` + 5. `git commit -m "all: release v"` and `git push` and `git tag v` and `git push --tags` + 6. Upload the jar to the releases tab of this repository. 7. Publish according to http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/publishing_plugin.html (note: it takes ~2 business days for JetBrains support team to review the plugin). - ## Version History +#### v1.2.0 + +- The search menu entry is now no longer present when no text has been selected. +- When on a branch that does not exist remotely, `master` will now be used instead. +- Menu entries (Open file, etc.) are now under a Sourcegraph sub-menu. +- Added a "Copy link to file" action (alt+c / opt+c). +- Added a "Search in repository" action (alt+r / opt+r). +- It is now possible to configure the plugin per-repository using a `.idea/sourcegraph.xml` file. See the README for details. +- Special thanks: @oliviernotteghem for contributing the new features in this release! + #### v1.1.2 - Fixed an error that occurred when trying to search with no selection. diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 85b8128..4b95bc1 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -1,20 +1,34 @@ com.sourcegraph.jetbrains Sourcegraph - 1.1.2 + 1.2.0 Sourcegraph +
    +
  • Search snippets of code on Sourcegraph.
  • +
  • Copy and share a link to code on Sourcegraph.
  • +
  • Quickly go from files in your editor to Sourcegraph.
  • +
]]>
-
  • v1.1.2 - Minor bug fixes around searching. -
      -
    • Fixed an error that occurred when trying to search with no selection.
    • +
    • v1.2.0 - Copy link to file, search in repository, per-repository configuration, bug fixes & more +
        +
      • The search menu entry is now no longer present when no text has been selected.
      • +
      • When on a branch that does not exist remotely, `master` will now be used instead.
      • +
      • Menu entries (Open file, etc.) are now under a Sourcegraph sub-menu.
      • +
      • Added a "Copy link to file" action (alt+c / opt+c).
      • +
      • Added a "Search in repository" action (alt+r / opt+r).
      • +
      • It is now possible to configure the plugin per-repository using a `.idea/sourcegraph.xml` file. See the README for details.
      • +
      • Special thanks: @oliviernotteghem for contributing the new features in this release!
      +
    • +
    • v1.1.2 - Minor bug fixes around searching.
        +
      • Fixed an error that occurred when trying to search with no selection.
      • The git remote used for repository detection is now `sourcegraph` and then `origin`, instead of the previously poor choice of just the first git remote.
    • @@ -45,18 +59,29 @@ com.intellij.modules.lang - + - - + - - + + + + + + + + + + + + + + diff --git a/resources/icons/icon.png b/resources/icons/icon.png new file mode 100644 index 0000000..7248dc4 Binary files /dev/null and b/resources/icons/icon.png differ diff --git a/resources/icons/icon@2x.png b/resources/icons/icon@2x.png new file mode 100644 index 0000000..8d91d21 Binary files /dev/null and b/resources/icons/icon@2x.png differ diff --git a/sourcegraph.jar b/sourcegraph.jar deleted file mode 100644 index 59312b0..0000000 Binary files a/sourcegraph.jar and /dev/null differ diff --git a/src/Config.java b/src/Config.java new file mode 100644 index 0000000..3263a78 --- /dev/null +++ b/src/Config.java @@ -0,0 +1,34 @@ +import com.intellij.openapi.components.PersistentStateComponent; +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.components.State; +import com.intellij.openapi.components.Storage; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@State( + name = "Config", + storages = {@Storage("sourcegraph.xml")}) +class Config implements PersistentStateComponent { + + public String url; + + public String getUrl() { + return url; + } + + @Nullable + @Override + public Config getState() { + return this; + } + + @Override + public void loadState(@NotNull Config config) { + this.url = config.url; + } + + @Nullable static Config getInstance(Project project) { + return ServiceManager.getService(project, Config.class); + } +} diff --git a/src/Copy.java b/src/Copy.java new file mode 100644 index 0000000..4134a17 --- /dev/null +++ b/src/Copy.java @@ -0,0 +1,20 @@ +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationType; +import com.intellij.notification.Notifications; +import com.intellij.openapi.ide.CopyPasteManager; + +import java.awt.datatransfer.StringSelection; + +public class Copy extends FileAction { + + @Override + void handleFileUri(String uri) { + // Copy file uri to clipboard + CopyPasteManager.getInstance().setContents(new StringSelection(uri)); + + // Display bubble + Notification notification = new Notification("Sourcegraph", "Sourcegraph", + "File URL copied to clipboard.", NotificationType.INFORMATION); + Notifications.Bus.notify(notification); + } +} \ No newline at end of file diff --git a/src/FileAction.java b/src/FileAction.java new file mode 100644 index 0000000..4ad8d88 --- /dev/null +++ b/src/FileAction.java @@ -0,0 +1,80 @@ +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.application.ApplicationInfo; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.LogicalPosition; +import com.intellij.openapi.editor.SelectionModel; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; + +import java.awt.*; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URLEncoder; + +public abstract class FileAction extends AnAction { + + abstract void handleFileUri(String uri); + + @Override + public void actionPerformed(AnActionEvent e) { + Logger logger = Logger.getInstance(this.getClass()); + + // Get project, editor, document, file, and position information. + final Project project = e.getProject(); + if (project == null) { + return; + } + Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); + if (editor == null) { + return; + } + Document currentDoc = editor.getDocument(); + if (currentDoc == null) { + return; + } + VirtualFile currentFile = FileDocumentManager.getInstance().getFile(currentDoc); + if (currentFile == null) { + return; + } + SelectionModel sel = editor.getSelectionModel(); + + // Get repo information. + RepoInfo repoInfo = Util.repoInfo(currentFile.getPath()); + if (repoInfo.remoteURL == "") { + return; + } + + // Build the URL that we will open. + String productName = ApplicationInfo.getInstance().getVersionName(); + String productVersion = ApplicationInfo.getInstance().getFullVersion(); + String uri; + try { + LogicalPosition start = editor.visualToLogicalPosition(sel.getSelectionStartPosition()); + LogicalPosition end = editor.visualToLogicalPosition(sel.getSelectionEndPosition()); + uri = Util.sourcegraphURL(project)+"-/editor" + + "?remote_url=" + URLEncoder.encode(repoInfo.remoteURL, "UTF-8") + + "&branch=" + URLEncoder.encode(repoInfo.branch, "UTF-8") + + "&file=" + URLEncoder.encode(repoInfo.fileRel, "UTF-8") + + "&editor=" + URLEncoder.encode("JetBrains", "UTF-8") + + "&version=" + URLEncoder.encode(Util.VERSION, "UTF-8") + + "&utm_product_name=" + URLEncoder.encode(productName, "UTF-8") + + "&utm_product_version=" + URLEncoder.encode(productVersion, "UTF-8") + + "&start_row=" + URLEncoder.encode(Integer.toString(start.line), "UTF-8") + + "&start_col=" + URLEncoder.encode(Integer.toString(start.column), "UTF-8") + + "&end_row=" + URLEncoder.encode(Integer.toString(end.line), "UTF-8") + + "&end_col=" + URLEncoder.encode(Integer.toString(end.column), "UTF-8"); + } catch (UnsupportedEncodingException err) { + logger.debug("failed to build URL"); + err.printStackTrace(); + return; + } + + handleFileUri(uri); + } +} \ No newline at end of file diff --git a/src/Open.java b/src/Open.java index 4842c73..2c22aac 100644 --- a/src/Open.java +++ b/src/Open.java @@ -1,76 +1,14 @@ -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.SelectionModel; -import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.fileEditor.FileEditorManager; -import com.intellij.openapi.editor.LogicalPosition; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.application.ApplicationInfo; -import java.io.*; -import java.awt.Desktop; +import java.awt.*; +import java.io.IOException; import java.net.URI; -import java.net.URLEncoder; -public class Open extends AnAction { +public class Open extends FileAction { + @Override - public void actionPerformed(AnActionEvent e) { + void handleFileUri(String uri) { Logger logger = Logger.getInstance(this.getClass()); - - // Get project, editor, document, file, and position information. - final Project project = e.getProject(); - if (project == null) { - return; - } - Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); - if (editor == null) { - return; - } - Document currentDoc = editor.getDocument(); - if (currentDoc == null) { - return; - } - VirtualFile currentFile = FileDocumentManager.getInstance().getFile(currentDoc); - if (currentFile == null) { - return; - } - SelectionModel sel = editor.getSelectionModel(); - - // Get repo information. - RepoInfo repoInfo = Util.repoInfo(currentFile.getPath()); - if (repoInfo.remoteURL == "") { - return; - } - - // Build the URL that we will open. - String productName = ApplicationInfo.getInstance().getVersionName(); - String productVersion = ApplicationInfo.getInstance().getFullVersion(); - String uri; - try { - LogicalPosition start = editor.visualToLogicalPosition(sel.getSelectionStartPosition()); - LogicalPosition end = editor.visualToLogicalPosition(sel.getSelectionEndPosition()); - uri = Util.sourcegraphURL()+"-/editor" - + "?remote_url=" + URLEncoder.encode(repoInfo.remoteURL, "UTF-8") - + "&branch=" + URLEncoder.encode(repoInfo.branch, "UTF-8") - + "&file=" + URLEncoder.encode(repoInfo.fileRel, "UTF-8") - + "&editor=" + URLEncoder.encode("JetBrains", "UTF-8") - + "&version=" + URLEncoder.encode(Util.VERSION, "UTF-8") - + "&utm_product_name=" + URLEncoder.encode(productName, "UTF-8") - + "&utm_product_version=" + URLEncoder.encode(productVersion, "UTF-8") - + "&start_row=" + URLEncoder.encode(Integer.toString(start.line), "UTF-8") - + "&start_col=" + URLEncoder.encode(Integer.toString(start.column), "UTF-8") - + "&end_row=" + URLEncoder.encode(Integer.toString(end.line), "UTF-8") - + "&end_col=" + URLEncoder.encode(Integer.toString(end.column), "UTF-8"); - } catch (UnsupportedEncodingException err) { - logger.debug("failed to build URL"); - err.printStackTrace(); - return; - } - // Open the URL in the browser. try { Desktop.getDesktop().browse(URI.create(uri)); diff --git a/src/Search.java b/src/Search.java index 1f69f51..e589d0d 100644 --- a/src/Search.java +++ b/src/Search.java @@ -10,70 +10,15 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.application.ApplicationInfo; +import javax.annotation.Nullable; import java.io.*; import java.awt.Desktop; import java.net.URI; import java.net.URLEncoder; -public class Search extends AnAction { +public class Search extends SearchActionBase { @Override public void actionPerformed(AnActionEvent e) { - Logger logger = Logger.getInstance(this.getClass()); - - // Get project, editor, document, file, and position information. - final Project project = e.getProject(); - if (project == null) { - return; - } - Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); - if (editor == null) { - return; - } - Document currentDoc = editor.getDocument(); - if (currentDoc == null) { - return; - } - VirtualFile currentFile = FileDocumentManager.getInstance().getFile(currentDoc); - if (currentFile == null) { - return; - } - SelectionModel sel = editor.getSelectionModel(); - - // Get repo information. - RepoInfo repoInfo = Util.repoInfo(currentFile.getPath()); - - String q = sel.getSelectedText(); - if (q == null || q.equals("")) { - return; // nothing to query - } - - // Build the URL that we will open. - String uri; - String productName = ApplicationInfo.getInstance().getVersionName(); - String productVersion = ApplicationInfo.getInstance().getFullVersion(); - try { - uri = Util.sourcegraphURL()+"-/editor" - + "?remote_url=" + URLEncoder.encode(repoInfo.remoteURL, "UTF-8") - + "&branch=" + URLEncoder.encode(repoInfo.branch, "UTF-8") - + "&file=" + URLEncoder.encode(repoInfo.fileRel, "UTF-8") - + "&editor=" + URLEncoder.encode("JetBrains", "UTF-8") - + "&version=" + URLEncoder.encode(Util.VERSION, "UTF-8") - + "&utm_product_name=" + URLEncoder.encode(productName, "UTF-8") - + "&utm_product_version=" + URLEncoder.encode(productVersion, "UTF-8") - + "&search=" + URLEncoder.encode(q, "UTF-8"); - } catch (UnsupportedEncodingException err) { - logger.debug("failed to build URL"); - err.printStackTrace(); - return; - } - - // Open the URL in the browser. - try { - Desktop.getDesktop().browse(URI.create(uri)); - } catch (IOException err) { - logger.debug("failed to open browser"); - err.printStackTrace(); - } - return; + super.actionPerformedMode(e, "search"); } } \ No newline at end of file diff --git a/src/SearchActionBase.java b/src/SearchActionBase.java new file mode 100644 index 0000000..90d8119 --- /dev/null +++ b/src/SearchActionBase.java @@ -0,0 +1,111 @@ +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.SelectionModel; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.application.ApplicationInfo; + +import javax.annotation.Nullable; +import java.io.*; +import java.awt.Desktop; +import java.net.URI; +import java.net.URLEncoder; + +public abstract class SearchActionBase extends AnAction { + public void actionPerformedMode(AnActionEvent e, String mode) { + Logger logger = Logger.getInstance(this.getClass()); + + // Get project, editor, document, file, and position information. + final Project project = e.getProject(); + if (project == null) { + return; + } + Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); + if (editor == null) { + return; + } + Document currentDoc = editor.getDocument(); + if (currentDoc == null) { + return; + } + VirtualFile currentFile = FileDocumentManager.getInstance().getFile(currentDoc); + if (currentFile == null) { + return; + } + SelectionModel sel = editor.getSelectionModel(); + + // Get repo information. + RepoInfo repoInfo = Util.repoInfo(currentFile.getPath()); + + String q = sel.getSelectedText(); + if (q == null || q.equals("")) { + return; // nothing to query + } + + // Build the URL that we will open. + String uri; + String productName = ApplicationInfo.getInstance().getVersionName(); + String productVersion = ApplicationInfo.getInstance().getFullVersion(); + try { + uri = Util.sourcegraphURL(project)+"-/editor" + + "?editor=" + URLEncoder.encode("JetBrains", "UTF-8") + + "&version=" + URLEncoder.encode(Util.VERSION, "UTF-8") + + "&utm_product_name=" + URLEncoder.encode(productName, "UTF-8") + + "&utm_product_version=" + URLEncoder.encode(productVersion, "UTF-8") + + "&search=" + URLEncoder.encode(q, "UTF-8"); + + if (mode == "search.repository") { + uri += "&search_remote_url=" + URLEncoder.encode(repoInfo.remoteURL, "UTF-8") + + "&search_branch=" + URLEncoder.encode(repoInfo.branch, "UTF-8"); + } + + } catch (UnsupportedEncodingException err) { + logger.debug("failed to build URL"); + err.printStackTrace(); + return; + } + + // Open the URL in the browser. + try { + Desktop.getDesktop().browse(URI.create(uri)); + } catch (IOException err) { + logger.debug("failed to open browser"); + err.printStackTrace(); + } + return; + } + + @Override + public void update(AnActionEvent e) { + final Project project = e.getProject(); + if (project == null) { + return; + } + String selectedText = getSelectedText(project); + e.getPresentation().setEnabled(selectedText != null && selectedText.length() > 0); + } + + @Nullable + private String getSelectedText(Project project) { + Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); + if (editor == null) { + return null; + } + Document currentDoc = editor.getDocument(); + if (currentDoc == null) { + return null; + } + VirtualFile currentFile = FileDocumentManager.getInstance().getFile(currentDoc); + if (currentFile == null) { + return null; + } + SelectionModel sel = editor.getSelectionModel(); + + return sel.getSelectedText(); + } +} \ No newline at end of file diff --git a/src/SearchRepository.java b/src/SearchRepository.java new file mode 100644 index 0000000..7b7a13c --- /dev/null +++ b/src/SearchRepository.java @@ -0,0 +1,24 @@ +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.editor.SelectionModel; +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.application.ApplicationInfo; + +import javax.annotation.Nullable; +import java.io.*; +import java.awt.Desktop; +import java.net.URI; +import java.net.URLEncoder; + +public class SearchRepository extends SearchActionBase { + @Override + public void actionPerformed(AnActionEvent e) { + super.actionPerformedMode(e, "search.repository"); + } +} \ No newline at end of file diff --git a/src/Util.java b/src/Util.java index 802ea58..debe4f9 100644 --- a/src/Util.java +++ b/src/Util.java @@ -1,10 +1,11 @@ import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.project.Project; import java.io.*; import java.util.Properties; public class Util { - public static String VERSION = "v1.1.2"; + public static String VERSION = "v1.2.0"; // gitRemoteURL returns the remote URL for the given remote name. // e.g. "origin" -> "git@github.com:foo/bar" @@ -43,6 +44,20 @@ public static String gitBranch(String repoDir) throws IOException { return exec("git rev-parse --abbrev-ref HEAD", repoDir).trim(); } + // verify that provided branch exists on remote + public static boolean isRemoteBranch(String branch, String repoDir) throws IOException { + return exec("git show-branch remotes/origin/" + branch, repoDir).length() > 0; + } + + public static String sourcegraphURL(Project project) { + String url = Config.getInstance(project).getUrl(); + if (url == null || url.length() == 0) { + Properties props = readProps(); + url = props.getProperty("url", "https://sourcegraph.com/"); + } + return url.endsWith("/") ? url : url + "/"; + } + // readProps tries to read the $HOME/sourcegraph-jetbrains.properties file. private static Properties readProps() { Properties props = new Properties(); @@ -66,15 +81,6 @@ private static Properties readProps() { return props; } - public static String sourcegraphURL() { - Properties props = readProps(); - String url = props.getProperty("url", "https://sourcegraph.com"); - if (!url.endsWith("/")) { - return url + "/"; - } - return url; - } - // repoInfo returns the Sourcegraph repository URI, and the file path // relative to the repository root. If the repository URI cannot be // determined, a RepoInfo with empty strings is returned. @@ -91,6 +97,11 @@ public static RepoInfo repoInfo(String fileName) { fileRel = fileName.substring(repoRoot.length()+1); remoteURL = configuredGitRemoteURL(repoRoot); branch = gitBranch(repoRoot); + + // If on a branch that does not exist on the remote, use "master" instead. + if (!isRemoteBranch(branch, repoRoot)) { + branch = "master"; + } } catch (Exception err) { Logger.getInstance(Util.class).info(err); err.printStackTrace();