From 87a300e71da0c4fe6efc7b62710ad6a68e123524 Mon Sep 17 00:00:00 2001 From: Elton Gao Date: Fri, 1 Sep 2023 00:11:39 -0400 Subject: [PATCH] rubocop --- lib/git-fastclone.rb | 15 ++++++++------- spec/git_fastclone_runner_spec.rb | 9 +++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/git-fastclone.rb b/lib/git-fastclone.rb index a8b60fb..c8ccd02 100644 --- a/lib/git-fastclone.rb +++ b/lib/git-fastclone.rb @@ -225,9 +225,9 @@ def clone(url, rev, src_dir, config) # Only checkout if we're changing branches to a non-default branch if rev - fail_on_error('git', 'checkout', '--quiet', rev.to_s, quiet: !verbose, - print_on_failure: print_git_errors, - :chdir => File.join(abs_clone_path, src_dir)) + fail_on_error('git', 'checkout', '--quiet', rev.to_s, quiet: !verbose, + print_on_failure: print_git_errors, + chdir: File.join(abs_clone_path, src_dir)) end update_submodules(src_dir, url) @@ -251,8 +251,8 @@ def update_submodules(pwd, url) submodule_url_list = [] output = '' output = fail_on_error('git', 'submodule', 'init', quiet: !verbose, - print_on_failure: print_git_errors, - :chdir => File.join(abs_clone_path, pwd)) + print_on_failure: print_git_errors, + chdir: File.join(abs_clone_path, pwd)) output.split("\n").each do |line| submodule_path, submodule_url = parse_update_info(line) @@ -270,7 +270,8 @@ def thread_update_submodule(submodule_url, submodule_path, threads, pwd) with_git_mirror(submodule_url) do |mirror, _| cmd = ['git', 'submodule', verbose ? nil : '--quiet', 'update', '--reference', mirror.to_s, submodule_path.to_s].compact - fail_on_error(*cmd, quiet: !verbose, print_on_failure: print_git_errors, :chdir => File.join(abs_clone_path, pwd)) + fail_on_error(*cmd, quiet: !verbose, print_on_failure: print_git_errors, + chdir: File.join(abs_clone_path, pwd)) end update_submodules(File.join(pwd, submodule_path), submodule_url) @@ -347,7 +348,7 @@ def store_updated_repo(url, mirror, repo_name, fail_hard) end cmd = ['git', 'remote', verbose ? '--verbose' : nil, 'update', '--prune'].compact - fail_on_error(*cmd, quiet: !verbose, print_on_failure: print_git_errors, :chdir => mirror) + fail_on_error(*cmd, quiet: !verbose, print_on_failure: print_git_errors, chdir: mirror) reference_updated[repo_name] = true rescue RunnerExecutionRuntimeError => e diff --git a/spec/git_fastclone_runner_spec.rb b/spec/git_fastclone_runner_spec.rb index ba583be..b90d4fd 100644 --- a/spec/git_fastclone_runner_spec.rb +++ b/spec/git_fastclone_runner_spec.rb @@ -91,7 +91,6 @@ def create_lockfile_double before(:each) do allow(runner_execution_double).to receive(:fail_on_error) {} allow(Dir).to receive(:pwd) { '/pwd' } - allow(Dir).to receive(:chdir).and_yield allow(subject).to receive(:with_git_mirror).and_yield('/cache', 0) expect(subject).to receive(:clear_clone_dest_if_needed).once {} end @@ -99,7 +98,7 @@ def create_lockfile_double it 'should clone correctly' do expect(subject).to receive(:fail_on_error).with( 'git', 'checkout', '--quiet', 'PH', - { quiet: true, print_on_failure: false } + { chdir: '/pwd/.', print_on_failure: false, quiet: true } ) { runner_execution_double } expect(subject).to receive(:fail_on_error).with( 'git', 'clone', '--quiet', '--reference', '/cache', 'PH', '/pwd/.', @@ -113,7 +112,7 @@ def create_lockfile_double subject.verbose = true expect(subject).to receive(:fail_on_error).with( 'git', 'checkout', '--quiet', 'PH', - { quiet: false, print_on_failure: false } + { chdir: '/pwd/.', print_on_failure: false, quiet: false } ) { runner_execution_double } expect(subject).to receive(:fail_on_error).with( 'git', 'clone', '--verbose', '--reference', '/cache', 'PH', '/pwd/.', @@ -338,7 +337,6 @@ def create_lockfile_double it 'should correctly update the hash' do allow(subject).to receive(:fail_on_error) - allow(Dir).to receive(:chdir) {} subject.reference_updated = placeholder_hash subject.store_updated_repo(placeholder_arg, placeholder_arg, placeholder_arg, false) @@ -389,7 +387,6 @@ def try_with_git_mirror(responses, results) expected_command = expected_commands.shift expect(command).to eq(expected_command) } - allow(Dir).to receive(:chdir).and_yield allow(subject).to receive(:print_formatted_error) {} allow(subject).to receive(:reference_repo_dir).and_return(test_reference_repo_dir) @@ -404,7 +401,7 @@ def clone_cmds(verbose: false) [ ['git', 'clone', verbose ? '--verbose' : '--quiet', '--mirror', test_url_valid, test_reference_repo_dir], - ['cd', test_reference_repo_dir, '&&', 'git', 'remote', verbose ? '--verbose' : nil, 'update', + ['git', 'remote', verbose ? '--verbose' : nil, 'update', '--prune'].compact ] end