Skip to content

Commit

Permalink
fix: make urls relative before calling Sbrowse
Browse files Browse the repository at this point in the history
Summary:

When you are in a buffer that has a absolute path as its name. When calling
Sbrowse it will use that hole path in the url. This is obviously incorrect.

Now we are making sure we get the relative path before we create the url so we
don't end up going to a 404.

Test Plan:

CI, unit tests. I have also had the change locally for quite some time.
  • Loading branch information
AdeAttwood committed Sep 17, 2024
1 parent 68717bc commit 3a9dabd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ codes = true
self = false

-- Global objects defined by the C code
read_globals = { "vim", "describe", "it", "assert", "teardown" }
read_globals = { "vim", "describe", "it", "assert", "teardown", "spy", "stub", "before_each" }
16 changes: 16 additions & 0 deletions lua/sapling_scm_tests/remote_url_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,19 @@ describe("sapling_scm.remote_url.commit", function()
)
end)
end)

describe("remote url integration test", function()
local un_stubbed = vim.cmd
local match = require "luassert.match"

before_each(function()
vim.cmd("edit " .. os.getenv "PWD" .. "/.github/workflows/test.yml")

stub(vim, "cmd")
un_stubbed "Sbrowse"
end)

it("creates the url from a relative path when the buffer is absolute", function()
assert.spy(vim.cmd).was_called_with(match.has_match "/blob/[^/]+/.github/workflows/test.yml")
end)
end)
3 changes: 3 additions & 0 deletions lua/sapling_scm_tests/setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ _G.describe = busted.describe
_G.it = busted.it
_G.assert = busted.assert
_G.teardown = busted.teardown
_G.spy = busted.spy
_G.stub = busted.stub
_G.before_each = busted.before_each
2 changes: 1 addition & 1 deletion plugin/sapling_scm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ else
end

vim.api.nvim_create_user_command("Sbrowse", function(props)
local file = vim.fn.expand "%"
local file = vim.fn.expand "%:."
local start_line = props.line1
local end_line = props.line2

Expand Down

0 comments on commit 3a9dabd

Please sign in to comment.