From fe36bb5892a67ecced4e90df5ba35b76d9467330 Mon Sep 17 00:00:00 2001 From: Robert Fletcher Date: Mon, 16 Sep 2024 11:12:19 -0700 Subject: [PATCH] switch to `git maintenance` (#101) This is a bit higher level and probably a bit less aggressive. --- lib/baes/actions/clean.rb | 2 +- lib/baes/git.rb | 8 ++++---- spec/baes/actions/clean_spec.rb | 4 ++-- spec/baes/actions/run_spec.rb | 2 +- spec/baes/git_spec.rb | 14 +++++++------- spec/support/fake_git.rb | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/baes/actions/clean.rb b/lib/baes/actions/clean.rb index ce21d6d..2c95442 100644 --- a/lib/baes/actions/clean.rb +++ b/lib/baes/actions/clean.rb @@ -11,8 +11,8 @@ def call output.puts("cleaning up branches") git.checkout(root_name) git.remote_prune("origin") - git.gc git.delete_branches(merged_branches) + git.maintenance end private diff --git a/lib/baes/git.rb b/lib/baes/git.rb index 102553b..400b082 100644 --- a/lib/baes/git.rb +++ b/lib/baes/git.rb @@ -65,10 +65,10 @@ def remote_prune(remote) output.puts(stdout) unless stdout.empty? end - # garbage collect and raise on failure - def gc - output.puts("garbage collecting") - stdout = run_or_raise("git gc --prune=now") + # run git maintenance and raise on failure + def maintenance + output.puts("running maintenance tasks") + stdout = run_or_raise("git maintenance run") output.puts(stdout) unless stdout.empty? end diff --git a/spec/baes/actions/clean_spec.rb b/spec/baes/actions/clean_spec.rb index 3c2ae6d..2eb8729 100644 --- a/spec/baes/actions/clean_spec.rb +++ b/spec/baes/actions/clean_spec.rb @@ -2,12 +2,12 @@ RSpec.describe Baes::Actions::Clean do describe "#call" do - it "calls git gc" do + it "calls git maintenance" do FakeGit.branch_names = ["main", "my_branch"] described_class.call - expect(FakeGit.gc_called).to be(true) + expect(FakeGit.maintenance_called).to be(true) end end end diff --git a/spec/baes/actions/run_spec.rb b/spec/baes/actions/run_spec.rb index 4862873..8afbc6c 100644 --- a/spec/baes/actions/run_spec.rb +++ b/spec/baes/actions/run_spec.rb @@ -43,7 +43,7 @@ def stub3(command, stdout: "", stderr: "", success: true) described_class.call(["clean"]) - expect(FakeGit.gc_called).to be(true) + expect(FakeGit.maintenance_called).to be(true) end it "raises an error when given an invalid command" do diff --git a/spec/baes/git_spec.rb b/spec/baes/git_spec.rb index 92fcd3a..52ec681 100644 --- a/spec/baes/git_spec.rb +++ b/spec/baes/git_spec.rb @@ -186,21 +186,21 @@ def run_and_rescue end end - describe ".gc" do + describe ".maintenance" do it "prints stdout" do - stub3("git gc --prune=now", stdout: "out") + stub3("git maintenance run", stdout: "out") - described_class.gc + described_class.maintenance - expect(output.string).to eq("garbage collecting\nout\n") + expect(output.string).to eq("running maintenance tasks\nout\n") end it "does not print stdout when empty" do - stub3("git gc --prune=now", stdout: "") + stub3("git maintenance run", stdout: "") - described_class.gc + described_class.maintenance - expect(output.string).to eq("garbage collecting\n") + expect(output.string).to eq("running maintenance tasks\n") end end diff --git a/spec/support/fake_git.rb b/spec/support/fake_git.rb index be9c880..d275366 100644 --- a/spec/support/fake_git.rb +++ b/spec/support/fake_git.rb @@ -61,7 +61,7 @@ def rebase_index @rebase_index ||= 0 end - attr_reader :gc_called + attr_reader :maintenance_called attr_writer :rebase_index, :branch_names, :rebases_successful attr_accessor :current_branch_name @@ -71,8 +71,8 @@ def rebases_successful def remote_prune(_); end - def gc - @gc_called = true + def maintenance + @maintenance_called = true end def delete_branches(branch_names); end