|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require "spec_helper" |
| 4 | +require "fileutils" |
4 | 5 |
|
5 | 6 | RSpec.describe "Status Buffer", :git, :nvim do |
6 | 7 | it "renders, raising no errors" do |
|
82 | 83 | # context "with tracked file" do |
83 | 84 | # end |
84 | 85 | end |
| 86 | + |
| 87 | + describe "submodule navigation" do |
| 88 | + let(:submodule_path) { File.join("deps", "nested-submodule") } |
| 89 | + let(:submodule_repo_root) { File.expand_path(submodule_path) } |
| 90 | + let!(:submodule_source_dir) { Dir.mktmpdir("neogit-submodule-source") } |
| 91 | + |
| 92 | + before do |
| 93 | + initialize_submodule_source |
| 94 | + |
| 95 | + git.config("protocol.file.allow", "always") |
| 96 | + unless system("git", "-c", "protocol.file.allow=always", "submodule", "add", submodule_source_dir, submodule_path) |
| 97 | + raise "Failed to add submodule" |
| 98 | + end |
| 99 | + |
| 100 | + git.commit("Add submodule") |
| 101 | + |
| 102 | + File.open(File.join(submodule_path, "file.txt"), "a") { _1.puts("local change") } |
| 103 | + nvim.lua(<<~LUA) |
| 104 | + local status = require("neogit.buffers.status") |
| 105 | + local instance = status.instance() |
| 106 | + if instance then |
| 107 | + status.register(instance, vim.uv.cwd()) |
| 108 | + end |
| 109 | + LUA |
| 110 | + nvim.refresh |
| 111 | + end |
| 112 | + |
| 113 | + after do |
| 114 | + FileUtils.remove_entry(submodule_source_dir) if File.directory?(submodule_source_dir) |
| 115 | + end |
| 116 | + |
| 117 | + it "opens submodule status and returns to the parent repo twice" do |
| 118 | + # First jump and back |
| 119 | + await do |
| 120 | + expect(nvim.screen.join("\n")).to include("#{submodule_path} (modified content)") |
| 121 | + end |
| 122 | + |
| 123 | + nvim.move_to_line(submodule_path) |
| 124 | + nvim.keys("<cr>") |
| 125 | + |
| 126 | + await do |
| 127 | + expect(nvim.fn("getcwd", [])).to eq(submodule_repo_root) |
| 128 | + expect(nvim.screen.join("\n")).to include("modified file.txt") |
| 129 | + end |
| 130 | + |
| 131 | + nvim.keys("gp") |
| 132 | + |
| 133 | + await do |
| 134 | + expect(nvim.fn("getcwd", [])).to eq(Dir.pwd) |
| 135 | + expect(nvim.screen.join("\n")).to include("#{submodule_path} (modified content)") |
| 136 | + end |
| 137 | + |
| 138 | + # Second jump and back |
| 139 | + nvim.move_to_line(submodule_path) |
| 140 | + nvim.keys("<cr>") |
| 141 | + |
| 142 | + await do |
| 143 | + expect(nvim.fn("getcwd", [])).to eq(submodule_repo_root) |
| 144 | + expect(nvim.screen.join("\n")).to include("modified file.txt") |
| 145 | + end |
| 146 | + |
| 147 | + nvim.keys("gp") |
| 148 | + |
| 149 | + await do |
| 150 | + expect(nvim.fn("getcwd", [])).to eq(Dir.pwd) |
| 151 | + expect(nvim.screen.join("\n")).to include("#{submodule_path} (modified content)") |
| 152 | + end |
| 153 | + end |
| 154 | + |
| 155 | + def initialize_submodule_source |
| 156 | + repo = Git.init(submodule_source_dir) |
| 157 | + repo.config("user.email", "test@example.com") |
| 158 | + repo.config("user.name", "tester") |
| 159 | + File.write(File.join(submodule_source_dir, "file.txt"), "submodule file\n") |
| 160 | + repo.add("file.txt") |
| 161 | + repo.commit("Initial submodule commit") |
| 162 | + end |
| 163 | + end |
85 | 164 | end |
0 commit comments