|
| 1 | +local git = require("rocks-git.git") |
| 2 | + |
| 3 | +local origin_pkg_dir = vim.fn.tempname() |
| 4 | +local origin_pkg_remote_dir = vim.fs.joinpath(origin_pkg_dir, ".git", "refs", "remotes", "origin") |
| 5 | + |
| 6 | +local upstream_pkg_dir = vim.fn.tempname() |
| 7 | +local upstream_pkg_remote_dir = vim.fs.joinpath(upstream_pkg_dir, ".git", "refs", "remotes", "upstream") |
| 8 | + |
| 9 | +setup(function() |
| 10 | + vim.system({ "mkdir", "-p", origin_pkg_remote_dir }, {}):wait() |
| 11 | + vim.system({ "mkdir", "-p", upstream_pkg_remote_dir }, {}):wait() |
| 12 | + local origin_head = vim.fs.joinpath(origin_pkg_remote_dir, "HEAD") |
| 13 | + local fd = assert(io.open(origin_head, "w"), "could not open " .. origin_head) |
| 14 | + fd:write("foo") |
| 15 | + fd:close() |
| 16 | + local upstream_head = vim.fs.joinpath(upstream_pkg_remote_dir, "HEAD") |
| 17 | + fd = assert(io.open(upstream_head, "w"), "could not open " .. upstream_head) |
| 18 | + fd:write("bar") |
| 19 | + fd:close() |
| 20 | +end) |
| 21 | + |
| 22 | +describe("git", function() |
| 23 | + it("Can get head branch from 'origin' remote", function() |
| 24 | + local head_branch = git.get_head_branch({ |
| 25 | + dir = origin_pkg_dir, |
| 26 | + url = "https://github.com/lumen-oss/luarocks-stub.git", |
| 27 | + }) |
| 28 | + assert.Same("foo", head_branch) |
| 29 | + end) |
| 30 | + it("Can get head branch from 'upstream' remote", function() |
| 31 | + local head_branch = git.get_head_branch({ |
| 32 | + dir = upstream_pkg_dir, |
| 33 | + url = "https://github.com/lumen-oss/luarocks-stub.git", |
| 34 | + }) |
| 35 | + assert.Same("bar", head_branch) |
| 36 | + end) |
| 37 | +end) |
0 commit comments