diff --git a/lua/git/core/repo.lua b/lua/git/core/repo.lua index 1b7fe11..d9a75ac 100644 --- a/lua/git/core/repo.lua +++ b/lua/git/core/repo.lua @@ -249,7 +249,7 @@ function Repo.new(gitdir, worktree) util.debounce(Repo._fetch_status, 50) self:start_watcher() self:refresh() - if vim.g.git_submodule_recursion then + if vim.g.git_submodule_recursion ~= false then self:_start_modules_watcher() for _, name in ipairs(find_submodules(gitdir)) do self:_register_submodule(name) @@ -382,7 +382,7 @@ function Repo:_handle_fs_event(relpath) return end self:_invalidate(relpath) - if relpath == "modules" and vim.g.git_submodule_recursion then + if relpath == "modules" and vim.g.git_submodule_recursion ~= false then if vim.uv.fs_stat(vim.fs.joinpath(self.gitdir, "modules")) then self:_start_modules_watcher() for _, name in ipairs(find_submodules(self.gitdir)) do diff --git a/test/git/repo_test.lua b/test/git/repo_test.lua index 5ac0c57..366436d 100644 --- a/test/git/repo_test.lua +++ b/test/git/repo_test.lua @@ -218,21 +218,13 @@ t.test("refresh emits change.paths listing structurally-changed paths", function t.falsy(change.paths["b"], "b is unchanged structurally") end) -t.test("submodule: parent enumerates initialized submodules with flag on", function() - vim.g.git_submodule_recursion = true - t.defer(function() - vim.g.git_submodule_recursion = nil - end) +t.test("submodule: parent enumerates initialized submodules by default", function() local outer_path = h.make_submodule_repo() local outer = assert(require("git.core.repo").resolve(outer_path)) t.truthy(outer._submodules["sub"], "sub recorded as submodule") end) -t.test("submodule: recursion flag eagerly creates child Repos and subscribes", function() - vim.g.git_submodule_recursion = true - t.defer(function() - vim.g.git_submodule_recursion = nil - end) +t.test("submodule: eagerly creates child Repos and subscribes by default", function() local outer_path = h.make_submodule_repo() local outer = assert(require("git.core.repo").resolve(outer_path)) wait_initial(outer) @@ -257,23 +249,23 @@ t.test("submodule: recursion flag eagerly creates child Repos and subscribes", f t.eq(entry.kind, "changed") end) -t.test("submodule: no eager creation when flag is off", function() +t.test("submodule: no eager creation when flag is explicitly disabled", function() + vim.g.git_submodule_recursion = false + t.defer(function() + vim.g.git_submodule_recursion = nil + end) local outer_path = h.make_submodule_repo() local outer = assert(require("git.core.repo").resolve(outer_path)) wait_initial(outer) t.eq( require("git.core.repo").all()[outer_path .. "/sub"], nil, - "inner Repo not created when flag off" + "inner Repo not created when flag is false" ) t.eq(next(outer._submodules), nil) end) t.test("submodule: outer created after inner picks up existing child", function() - vim.g.git_submodule_recursion = true - t.defer(function() - vim.g.git_submodule_recursion = nil - end) local outer_path = h.make_submodule_repo() local inner = assert( require("git.core.repo").resolve(outer_path .. "/sub")