diff --git a/CHANGELOG.md b/CHANGELOG.md index 92821c76..b31fed33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,30 @@ # Change Log +## v3.0.1 (2025-05-14) + +[Full Changelog](https://github.com/ruby-git/ruby-git/compare/v3.0.0..v3.0.1) + +Changes since v3.0.0: + +* b47eedc Improved error message of rev_parse +* 9d44146 chore: update the development dependency on the minitar gem +* f407b92 feat: set the locale to en_US.UTF-8 for git commands +* b060e47 test: verify that command line envionment variables are set as expected +* 1a5092a chore: release v3.0.0 + +## v3.0.0 (2025-02-27) + +[Full Changelog](https://github.com/ruby-git/ruby-git/compare/v2.3.3..v3.0.0) + +Changes since v2.3.3: + +* 534fcf5 chore: use ProcessExecuter.run instead of the implementing it in this gem +* 629f3b6 feat: update dependenices +* 501d135 feat: add support for Ruby 3.4 and drop support for Ruby 3.0 +* 38c0eb5 build: update the CI build to use current versions to TruffleRuby and JRuby +* d3f3a9d chore: add frozen_string_literal: true magic comment + ## v2.3.3 (2024-12-04) [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v2.3.2..v2.3.3) diff --git a/git.gemspec b/git.gemspec index a81ba60b..f8c49bdc 100644 --- a/git.gemspec +++ b/git.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'rchardet', '~> 1.9' s.add_development_dependency 'create_github_release', '~> 2.1' - s.add_development_dependency 'minitar', '~> 0.12' + s.add_development_dependency 'minitar', '~> 1.0' s.add_development_dependency 'mocha', '~> 2.7' s.add_development_dependency 'rake', '~> 13.2' s.add_development_dependency 'test-unit', '~> 3.6' diff --git a/lib/git/lib.rb b/lib/git/lib.rb index a2ea79b2..b62d69c1 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -333,7 +333,7 @@ def full_log_commits(opts = {}) def rev_parse(revision) assert_args_are_not_options('rev', revision) - command('rev-parse', revision) + command('rev-parse', '--revs-only', '--end-of-options', revision, '--') end # For backwards compatibility with the old method name @@ -1547,7 +1547,8 @@ def env_overrides 'GIT_DIR' => @git_dir, 'GIT_WORK_TREE' => @git_work_dir, 'GIT_INDEX_FILE' => @git_index_file, - 'GIT_SSH' => Git::Base.config.git_ssh + 'GIT_SSH' => Git::Base.config.git_ssh, + 'LC_ALL' => 'en_US.UTF-8' } end diff --git a/lib/git/version.rb b/lib/git/version.rb index b0ad1154..eb507c85 100644 --- a/lib/git/version.rb +++ b/lib/git/version.rb @@ -3,5 +3,5 @@ module Git # The current gem version # @return [String] the current gem version. - VERSION='2.3.3' + VERSION='3.0.1' end diff --git a/tests/test_helper.rb b/tests/test_helper.rb index c0a95174..067fa633 100644 --- a/tests/test_helper.rb +++ b/tests/test_helper.rb @@ -131,7 +131,7 @@ def append_file(name, contents) # # @return [void] # - def assert_command_line_eq(expected_command_line, method: :command, mocked_output: nil) + def assert_command_line_eq(expected_command_line, method: :command, mocked_output: nil, include_env: false) actual_command_line = nil command_output = '' @@ -140,7 +140,11 @@ def assert_command_line_eq(expected_command_line, method: :command, mocked_outpu git = Git.init('test_project') git.lib.define_singleton_method(method) do |*cmd, **opts, &block| - actual_command_line = [*cmd, opts] + if include_env + actual_command_line = [env_overrides, *cmd, opts] + else + actual_command_line = [*cmd, opts] + end mocked_output end @@ -149,6 +153,8 @@ def assert_command_line_eq(expected_command_line, method: :command, mocked_outpu end end + expected_command_line = expected_command_line.call if expected_command_line.is_a?(Proc) + assert_equal(expected_command_line, actual_command_line) command_output diff --git a/tests/units/test_command_line_env_overrides.rb b/tests/units/test_command_line_env_overrides.rb new file mode 100644 index 00000000..a89da4d4 --- /dev/null +++ b/tests/units/test_command_line_env_overrides.rb @@ -0,0 +1,48 @@ + +# frozen_string_literal: true + +require 'test_helper' + +class TestCommandLineEnvOverrides < Test::Unit::TestCase + test 'it should set the expected environment variables' do + expected_command_line = nil + expected_command_line_proc = ->{ expected_command_line } + assert_command_line_eq(expected_command_line_proc, include_env: true) do |git| + expected_env = { + 'GIT_DIR' => git.lib.git_dir, + 'GIT_INDEX_FILE' => git.lib.git_index_file, + 'GIT_SSH' => nil, + 'GIT_WORK_TREE' => git.lib.git_work_dir, + 'LC_ALL' => 'en_US.UTF-8' + } + expected_command_line = [expected_env, 'checkout', {}] + + git.checkout + end + end + + test 'it should set the GIT_SSH environment variable from Git::Base.config.git_ssh' do + expected_command_line = nil + expected_command_line_proc = ->{ expected_command_line } + + saved_git_ssh = Git::Base.config.git_ssh + begin + Git::Base.config.git_ssh = 'ssh -i /path/to/key' + + assert_command_line_eq(expected_command_line_proc, include_env: true) do |git| + expected_env = { + 'GIT_DIR' => git.lib.git_dir, + 'GIT_INDEX_FILE' => git.lib.git_index_file, + 'GIT_SSH' => 'ssh -i /path/to/key', + 'GIT_WORK_TREE' => git.lib.git_work_dir, + 'LC_ALL' => 'en_US.UTF-8' + } + expected_command_line = [expected_env, 'checkout', {}] + + git.checkout + end + ensure + Git::Base.config.git_ssh = saved_git_ssh + end + end +end diff --git a/tests/units/test_lib.rb b/tests/units/test_lib.rb index fb319be8..af613d1f 100644 --- a/tests/units/test_lib.rb +++ b/tests/units/test_lib.rb @@ -199,7 +199,7 @@ def test_rev_parse_with_bad_revision end def test_rev_parse_with_unknown_revision - assert_raise(Git::FailedError) do + assert_raise_with_message(Git::FailedError, /exit 128, stderr: "fatal: bad revision 'NOTFOUND'"/) do @lib.rev_parse('NOTFOUND') end end