-
-
Notifications
You must be signed in to change notification settings - Fork 44
Get remote branch #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -238,6 +238,31 @@ function M.get_closest_remote_compatible_rev(remote) | |||||||||||
return nil | ||||||||||||
end | ||||||||||||
|
||||||||||||
local function get_remote_branch(remote) | ||||||||||||
local errs = { | ||||||||||||
string.format("Failed to retrieve remote branch for remote '%s'", remote), | ||||||||||||
} | ||||||||||||
local symRef | ||||||||||||
local p = job:new({ | ||||||||||||
command = "git", | ||||||||||||
args = { "symbolic-ref", "-q", "HEAD" }, | ||||||||||||
}) | ||||||||||||
p:after_success(function(j) | ||||||||||||
symRef = j:result()[1] | ||||||||||||
end) | ||||||||||||
p:sync() | ||||||||||||
local trackingBranch | ||||||||||||
local p = job:new({ | ||||||||||||
command = 'git', | ||||||||||||
args = { 'for-each-ref', '--format=%(upstream:short)', symRef }, | ||||||||||||
}) | ||||||||||||
p:after_success(function(j) | ||||||||||||
trackingBranch = (j:result()[1]):match(remote .. '/(.+)$') | ||||||||||||
end) | ||||||||||||
p:sync() | ||||||||||||
return trackingBranch or 'origin/master' | ||||||||||||
robertgzr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
end | ||||||||||||
|
||||||||||||
function M.get_repo_data(remote) | ||||||||||||
local errs = { | ||||||||||||
string.format("Failed to retrieve repo data for remote '%s'", remote), | ||||||||||||
|
@@ -255,6 +280,12 @@ function M.get_repo_data(remote) | |||||||||||
if not repo or vim.tbl_isempty(repo) then | ||||||||||||
vim.notify(table.concat(errs), vim.log.levels.Error) | ||||||||||||
end | ||||||||||||
|
||||||||||||
local branch = get_remote_branch(remote) | ||||||||||||
if branch then | ||||||||||||
repo.rev = branch | ||||||||||||
end | ||||||||||||
Comment on lines
+284
to
+287
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for conditionality here, always set it, even if
Suggested change
|
||||||||||||
|
||||||||||||
return repo | ||||||||||||
Comment on lines
+284
to
289
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why call the key |
||||||||||||
end | ||||||||||||
|
||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we wouldn't have to do this if the key was called
branch
. Then we can embed both the branch name and the rev sha in the url data that is passed to callbacks.Which is good because then it is up to the callbacks to decide what they want to do (either use the branch name or the rev sha).