From 51fdf24ff8c93d49cf91d35c0a3ccf73fffbd574 Mon Sep 17 00:00:00 2001 From: Dylan Rainwater Date: Fri, 17 Mar 2023 16:34:00 -0400 Subject: [PATCH] Add support for `--update-head-ok` to `fetch` Signed-off-by: Dylan Rainwater Signed-off-by: Dylan Rainwater --- README.md | 1 + lib/git/lib.rb | 1 + tests/units/test_remotes.rb | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 188ab73e..ec97d4cd 100644 --- a/README.md +++ b/README.md @@ -311,6 +311,7 @@ g.fetch g.fetch(g.remotes.first) g.fetch('origin', {:ref => 'some/ref/head'} ) g.fetch(all: true, force: true, depth: 2) +g.fetch('origin', {:'update-head-ok' => true}) g.pull g.pull(Git::Repo, Git::Branch) # fetch and a merge diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 8efd05a4..78e4fafb 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -951,6 +951,7 @@ def fetch(remote, opts) arr_opts << '--prune' if opts[:p] || opts[:prune] arr_opts << '--prune-tags' if opts[:P] || opts[:'prune-tags'] arr_opts << '--force' if opts[:f] || opts[:force] + arr_opts << '--update-head-ok' if opts[:u] || opts[:'update-head-ok'] arr_opts << '--unshallow' if opts[:unshallow] arr_opts << '--depth' << opts[:depth] if opts[:depth] arr_opts << '--' if remote || opts[:ref] diff --git a/tests/units/test_remotes.rb b/tests/units/test_remotes.rb index d119754e..9084460b 100644 --- a/tests/units/test_remotes.rb +++ b/tests/units/test_remotes.rb @@ -147,6 +147,13 @@ def test_fetch_cmd_with_all_with_other_args assert_command_line(expected_command_line, git_cmd, git_cmd_args) end + def test_fetch_cmd_with_update_head_ok + expected_command_line = ['fetch', '--update-head-ok'] + git_cmd = :fetch + git_cmd_args = [:'update-head-ok' => true] + assert_command_line(expected_command_line, git_cmd, git_cmd_args) + end + def test_fetch_command_injection test_file = 'VULNERABILITY_EXISTS' vulnerability_exists = false