From 0d57a6762dd9b7f98eb43f3e75f8a8869cbfcf85 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Wed, 10 Apr 2024 11:03:08 -0400 Subject: [PATCH] Move `GitWorktree#pull` to a public method There doesn't appear to be another public way to update an existing cloned git repo. --- app/models/git_repository.rb | 2 +- lib/git_worktree.rb | 8 ++++---- spec/lib/git_worktree_spec.rb | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/git_repository.rb b/app/models/git_repository.rb index b4bd3b00123..06d2073ef21 100644 --- a/app/models/git_repository.rb +++ b/app/models/git_repository.rb @@ -114,7 +114,7 @@ def update_repo with_worktree do |worktree| message = "Updating #{url} in #{directory_name}..." _log.info(message) - worktree.send(:pull) + worktree.pull _log.info("#{message}...Complete") end @updated_repo = true diff --git a/lib/git_worktree.rb b/lib/git_worktree.rb index 8a5ff84ad4d..ec01b6884a4 100644 --- a/lib/git_worktree.rb +++ b/lib/git_worktree.rb @@ -263,6 +263,10 @@ def checkout end end + def pull + lock { fetch_and_merge } + end + def with_remote_options if @ssh_private_key @ssh_private_key_file = Tempfile.new @@ -328,10 +332,6 @@ def fetch end end - def pull - lock { fetch_and_merge } - end - def merge_and_push(commit) rebase = false push_lock do diff --git a/spec/lib/git_worktree_spec.rb b/spec/lib/git_worktree_spec.rb index 412a8058c07..700e5a97072 100644 --- a/spec/lib/git_worktree_spec.rb +++ b/spec/lib/git_worktree_spec.rb @@ -232,7 +232,7 @@ def open_existing_repo expect(c_repo.file_list).to match_array(@ae_db.file_list) @ae_db.mv_file_with_new_contents('A/File1.YamL', 'A/File11.YamL', "Hello") @ae_db.save_changes("file renamed in master") - c_repo.send(:pull) + c_repo.pull expect(c_repo.file_list).to match_array(@ae_db.file_list) FileUtils.rm_rf(dirname) if Dir.exist?(dirname) end @@ -247,14 +247,14 @@ def open_existing_repo end end - describe "#pull (private)" do + describe "#pull" do it "fetches the repo with proxy options" do _dir, worktree = clone(@master_url) expect(worktree.instance_variable_get(:@repo)).to receive(:fetch).with("origin", hash_including(:proxy_url => proxy_url)) worktree.instance_variable_set(:@proxy_url, proxy_url) - worktree.send(:pull) + worktree.pull end end end