Add push popup spec

This commit is contained in:
Cameron 2024-09-02 22:36:32 +02:00
parent a46188c725
commit c84bb954b9
No known key found for this signature in database
GPG key ID: 7998CB3EA6CE5CBC
5 changed files with 148 additions and 85 deletions

View file

@ -1,120 +1,114 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.2)
activesupport (7.2.0)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
amazing_print (1.6.0)
ast (2.4.2)
attr_extras (7.1.0)
base64 (0.2.0)
bigdecimal (3.1.5)
concurrent-ruby (1.2.2)
bigdecimal (3.1.8)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
debug (1.9.1)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
diff-lcs (1.5.0)
drb (2.2.0)
ruby2_keywords
diff-lcs (1.5.1)
drb (2.2.1)
fileutils (1.7.2)
fuubar (2.5.1)
rspec-core (~> 3.0)
ruby-progressbar (~> 1.4)
git (1.19.0)
git (2.1.1)
activesupport (>= 5.0)
addressable (~> 2.8)
process_executer (~> 1.1)
rchardet (~> 1.8)
i18n (1.14.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
io-console (0.7.1)
irb (1.11.0)
rdoc
reline (>= 0.3.8)
io-console (0.7.2)
irb (1.14.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.7.2)
language_server-protocol (3.17.0.3)
minitest (5.20.0)
logger (1.6.0)
minitest (5.25.1)
msgpack (1.7.2)
multi_json (1.15.0)
mutex_m (0.2.0)
neovim (0.9.1)
neovim (0.10.0)
msgpack (~> 1.1)
multi_json (~> 1.0)
optimist (3.1.0)
parallel (1.24.0)
parser (3.3.1.0)
parallel (1.26.3)
parser (3.3.4.2)
ast (~> 2.4.1)
racc
patience_diff (1.2.0)
optimist (~> 3.0)
process_executer (1.1.0)
psych (5.1.2)
stringio
public_suffix (5.0.4)
public_suffix (6.0.1)
quickfix_formatter (0.1.0)
rspec (>= 3.12.0)
racc (1.8.0)
racc (1.8.1)
rainbow (3.1.1)
rchardet (1.8.0)
rdoc (6.6.2)
rdoc (6.7.0)
psych (>= 4.0.0)
regexp_parser (2.9.2)
reline (0.4.1)
reline (0.5.9)
io-console (~> 0.5)
rexml (3.2.8)
strscan (>= 3.0.9)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
rexml (3.3.5)
strscan
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.63.5)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
rubocop-ast (1.32.1)
parser (>= 3.3.1.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.25.1)
rubocop (~> 1.41)
rubocop-performance (1.21.0)
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rspec (2.29.2)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
rubocop-rspec_rails (~> 2.28)
rubocop-rspec_rails (2.28.3)
rubocop (~> 1.40)
rubocop-rspec (3.0.4)
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
stringio (3.1.0)
securerandom (0.3.1)
stringio (3.1.1)
strscan (3.1.0)
super_diff (0.10.0)
super_diff (0.12.1)
attr_extras (>= 6.2.4)
diff-lcs
patience_diff

View file

@ -31,38 +31,34 @@ local function push_to(args, remote, branch, opts)
local res = git.push.push_interactive(remote, branch, args)
-- Inform the user about missing permissions
if res.code == 128 then
notification.info(table.concat(res.stdout, "\n"))
return
end
local using_force = vim.tbl_contains(args, "--force") or vim.tbl_contains(args, "--force-with-lease")
local updates_rejected = string.find(table.concat(res.stdout), "Updates were rejected") ~= nil
-- Only ask the user whether to force push if not already specified
if res and res.code ~= 0 and not using_force and updates_rejected then
logger.error("Attempting force push to " .. name)
local message = "Your branch has diverged from the remote branch. Do you want to force push?"
if input.get_permission(message) then
table.insert(args, "--force")
res = git.push.push_interactive(remote, branch, args)
end
end
if res and res.code == 0 then
a.util.scheduler()
logger.debug("Pushed to " .. name)
notification.info("Pushed to " .. name, { dismiss = true })
vim.api.nvim_exec_autocmds("User", { pattern = "NeogitPushComplete", modeline = false })
else
logger.error("Failed to push to " .. name)
-- Inform the user about missing permissions
if res.code == 128 then
notification.info(table.concat(res.stdout, "\n"))
return
end
-- Only ask the user whether to force push if not already specified
if vim.tbl_contains(args, "--force") or vim.tbl_contains(args, "--force-with-lease") then
return
end
local stdout = table.concat(res.stdout)
if string.find(stdout, "Updates were rejected") == nil then
return
end
local message = "Your branch has diverged from the remote branch. Do you want to force push?"
if not input.get_confirmation(message) then
return
end
-- Ignore if it still errors
table.insert(args, "--force")
local _ = git.push.push_interactive(remote, branch, args)
logger.debug("Failed to push to " .. name)
notification.error("Failed to push to " .. name, { dismiss = true })
end
end

View file

@ -0,0 +1,65 @@
# frozen_string_literal: true
require "spec_helper"
RSpec.describe "Push Popup", :git, :nvim, :with_remote_origin do
describe "Actions" do
describe "Push to branch.pushRemote" do
context "when branch.pushRemote is unset" do
it "sets branch.pushRemote" do
nvim.keys("Pp")
expect(git.config("branch.master.pushRemote")).to eq("origin")
end
it "pushes local commits to remote" do
File.write("example.txt", "hello, world")
git.add("example.txt")
nvim.refresh
nvim.keys("Pp")
expect(git.show("HEAD").split[1]).to eq(git.remotes.first.branch.gcommit.sha)
end
end
context "when remote has diverged" do
it "prompts the user to force push (yes)" do
File.write("example.txt", "hello, world")
git.add("example.txt")
git.commit("commit A")
nvim.refresh
nvim.keys("Pp")
# nvim.keys("XhHEAD^<cr>") TODO
`git reset --hard HEAD^`
File.write("example.txt", "hello, world, again")
git.add("example.txt")
git.commit("commit B")
nvim.confirm(true)
nvim.keys("Pp")
expect(git.show("HEAD").split[1]).to eq(git.remotes.first.branch.gcommit.sha)
end
it "prompts the user to force push (no)" do
File.write("example.txt", "hello, world")
git.add("example.txt")
git.commit("commit A")
nvim.refresh
nvim.keys("Pp")
# nvim.keys("XhHEAD^<cr>") TODO
`git reset --hard HEAD^`
File.write("example.txt", "hello, world, again")
git.add("example.txt")
git.commit("commit B")
nvim.confirm(false)
nvim.keys("Pp")
expect(git.show("HEAD").split[1]).not_to eq(git.remotes.first.branch.gcommit.sha)
end
end
end
end
end

View file

@ -36,7 +36,7 @@ RSpec.configure do |config|
Dir.mktmpdir do |local|
Dir.mktmpdir do |remote|
Git.init(remote) if with_remote
Git.init(remote, { bare: true }) if with_remote
Dir.chdir(local) do
local_repo = Git.init

View file

@ -119,6 +119,14 @@ class NeovimClient # rubocop:disable Metrics/ClassLength
LUA
end
def confirm(state)
lua <<~LUA
vim.fn.confirm = function()
return #{state ? 1 : 0}
end
LUA
end
def keys(keys) # rubocop:disable Metrics/MethodLength
keys = keys.chars