Skip to content

Commit

Permalink
switch to git maintenance (#101)
Browse files Browse the repository at this point in the history
This is a bit higher level and probably a bit less aggressive.
  • Loading branch information
mockdeep authored Sep 16, 2024
1 parent 133d1a8 commit fe36bb5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/baes/actions/clean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/baes/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/baes/actions/clean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion spec/baes/actions/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions spec/baes/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions spec/support/fake_git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit fe36bb5

Please sign in to comment.