Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions GitHub.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@

// The default branch to use when issuing Copy Remote URL to Clipboard, Open Remote URL in Browser, View, Blame,
// History, or Edit commands
// Set to falsey values to fetch the current repo's default branch
"default_branch": "main",
}
28 changes: 27 additions & 1 deletion sublime_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import plistlib
import sublime
import sublime_plugin
import subprocess

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from github import GitHubApi
Expand Down Expand Up @@ -430,7 +431,32 @@ class RemoteUrlCommand(git.GitTextCommand):
def run(self, edit):
if self.branch == "default":
self.settings = sublime.load_settings("GitHub.sublime-settings")
branch = self.settings.get("default_branch")
default_branch_setting = self.settings.get("default_branch")

if default_branch_setting:
branch = default_branch_setting
else:
# Get the path of the currently opened file
file_path = self.view.window().active_view().file_name()

# Get the list of folders in the project
folders = self.view.window().folders()

top_level_folder = None
for folder in folders:
if file_path.startswith(folder):
top_level_folder = folder
break

branch = (
subprocess.check_output(
"git -C %s symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'"%(top_level_folder),
stderr=subprocess.STDOUT,
shell=True,
)
.decode("utf-8")
.strip()
)
else:
# Get the current remote branch--useful whether we want to link directly to that
# branch or to the branch's HEAD.
Expand Down