diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index c50680c8..ad2ea03a 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -40,3 +40,6 @@ jobs: - name: Run Build run: bundle exec rake default + + - name: Test Gem + run: bundle exec rake test:gem diff --git a/CHANGELOG.md b/CHANGELOG.md index e7e7963b..ae998e92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ # Change Log +## 1.9.0 + +See https://github.com/ruby-git/ruby-git/releases/tag/v1.9.0 + ## 1.8.1 See https://github.com/ruby-git/ruby-git/releases/tag/v1.8.1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 929b80b2..4f147fe0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -78,12 +78,14 @@ In order to ensure high quality, all pull requests must meet these requirements: ### Unit tests * All changes must be accompanied by new or modified unit tests - * The entire test suite must pass when `bundle exec rake test` is run from the - project's local working copy - -### Continuous Integration - * All tests must pass in the project's [Travis CI](https://travis-ci.org/ruby-git/ruby-git) - build before the pull request will be merged + * The entire test suite must pass when `bundle exec rake default` is run from the + project's local working copy. + +### Continuous integration + * All tests must pass in the project's [GitHub Continuous Integration build](https://github.com/ruby-git/ruby-git/actions?query=workflow%3ACI) + before the pull request will be merged. + * The [Continuous Integration workflow](https://github.com/ruby-git/ruby-git/blob/master/.github/workflows/continuous_integration.yml) + runs both `bundle exec rake default` and `bundle exec rake test:gem` from the project's [Rakefile](https://github.com/ruby-git/ruby-git/blob/master/Rakefile). ### Documentation * New and updated public methods must have [YARD](https://yardoc.org/) diff --git a/README.md b/README.md index 0ff9a0a5..bc651c34 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,7 @@ g.revparse('v2.5:Makefile') g.branches # returns Git::Branch objects g.branches.local +g.current_branch g.branches.remote g.branches[:master].gcommit g.branches['origin/master'].gcommit diff --git a/Rakefile b/Rakefile index cda2f8cf..acfa2bb0 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ require 'bundler/gem_tasks' +require 'English' require "#{File.expand_path(File.dirname(__FILE__))}/lib/git/version" @@ -41,4 +42,15 @@ unless RUBY_PLATFORM == 'java' # default_tasks << :yardstick end +default_tasks << :build + task default: default_tasks + +desc 'Build and install the git gem and run a sanity check' +task :'test:gem' => :install do + output = `ruby -e "require 'git'; g = Git.open('.'); puts g.log.size"`.chomp + raise 'Gem test failed' unless $CHILD_STATUS.success? + raise 'Expected gem test to return an integer' unless output =~ /^\d+$/ + + puts 'Gem Test Succeeded' +end diff --git a/lib/git/base.rb b/lib/git/base.rb index fbca5f1b..6e7c7a10 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -137,13 +137,14 @@ def chdir # :yields: the Git::Path #g.config('user.name', 'Scott Chacon') # sets value #g.config('user.email', 'email@email.com') # sets value + #g.config('user.email', 'email@email.com', file: 'path/to/custom/config) # sets value in file #g.config('user.name') # returns 'Scott Chacon' #g.config # returns whole config hash - def config(name = nil, value = nil) - if(name && value) + def config(name = nil, value = nil, options = {}) + if name && value # set value - lib.config_set(name, value) - elsif (name) + lib.config_set(name, value, options) + elsif name # return value lib.config_get(name) else @@ -387,7 +388,7 @@ def each_conflict(&block) # :yields: file, your_version, their_version # @git.pull('upstream', 'develope') # pulls from upstream/develop # def pull(remote='origin', branch='master') - self.lib.pull(remote, branch) + self.lib.pull(remote, branch) end # returns an array of Git:Remote objects diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 191b8a74..8dcb4f8a 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -583,8 +583,12 @@ def show(objectish=nil, path=nil) ## WRITE COMMANDS ## - def config_set(name, value) - command('config', name, value) + def config_set(name, value, options = {}) + if options[:file].to_s.empty? + command('config', name, value) + else + command('config', '--file', options[:file], name, value) + end end def global_config_set(name, value) @@ -642,6 +646,7 @@ def remove(path = '.', opts = {}) # :date # :no_verify # :allow_empty_message + # :gpg_sign # # @param [String] message the commit message to be used # @param [Hash] opts the commit options to be used @@ -655,6 +660,7 @@ def commit(message, opts = {}) arr_opts << "--date=#{opts[:date]}" if opts[:date].is_a? String arr_opts << '--no-verify' if opts[:no_verify] arr_opts << '--allow-empty-message' if opts[:allow_empty_message] + arr_opts << '--gpg-sign' if opts[:gpg_sign] == true || "--gpg-sign=#{opts[:gpg_sign]}" if opts[:gpg_sign] command('commit', arr_opts) end diff --git a/lib/git/version.rb b/lib/git/version.rb index 05b60fb1..6fe493dc 100644 --- a/lib/git/version.rb +++ b/lib/git/version.rb @@ -1,5 +1,5 @@ module Git # The current gem version # @return [String] the current gem version. - VERSION='1.8.1' + VERSION='1.9.0' end diff --git a/tests/units/test_config.rb b/tests/units/test_config.rb index a1753831..c04c8530 100644 --- a/tests/units/test_config.rb +++ b/tests/units/test_config.rb @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../test_helper' +require_relative '../test_helper' class TestConfig < Test::Unit::TestCase def setup @@ -26,7 +26,20 @@ def test_set_config g.config('user.name', 'bully') assert_equal('bully', g.config('user.name')) end - end + end + + def test_set_config_with_custom_file + in_temp_dir do |_path| + custom_config_path = "#{Dir.pwd}/bare/.git/custom-config" + g = Git.clone(@wbare, 'bare') + assert_not_equal('bully', g.config('user.name')) + g.config('user.name', 'bully', file: custom_config_path) + assert_not_equal('bully', g.config('user.name')) + g.config('include.path', custom_config_path) + assert_equal('bully', g.config('user.name')) + assert_equal("[user]\n\tname = bully\n", File.read(custom_config_path)) + end + end def test_env_config with_custom_env_variables do diff --git a/tests/units/test_show.rb b/tests/units/test_show.rb new file mode 100644 index 00000000..c44d81d4 --- /dev/null +++ b/tests/units/test_show.rb @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../test_helper' + +class TestShow < Test::Unit::TestCase + def test_do_not_chomp_contents + in_temp_dir do + file_name = 'README.md' + expected_contents = "hello\nworld\n\n" + + g = Git.init + g.commit('Initial commit', allow_empty: true) + new_file(file_name, expected_contents) + g.add(file_name) + # Show the file from the index by prefixing the file namne with a colon + contents = g.show(":#{file_name}") + assert_equal(expected_contents, contents) + end + end +end diff --git a/tests/units/test_worktree.rb b/tests/units/test_worktree.rb index 2b509726..f5141c8d 100644 --- a/tests/units/test_worktree.rb +++ b/tests/units/test_worktree.rb @@ -32,23 +32,24 @@ def create_temp_repo(clone_path) def setup @git = Git.open(git_working_dir) - + @commit = @git.object('1cc8667014381') @tree = @git.object('1cc8667014381^{tree}') @blob = @git.object('v2.5:example.txt') - + @worktrees = @git.worktrees end - + def test_worktrees_all assert(@git.worktrees.is_a?(Git::Worktrees)) assert(@git.worktrees.first.is_a?(Git::Worktree)) assert_equal(@git.worktrees.size, 2) end - + def test_worktrees_single worktree = @git.worktrees.first - assert_equal(worktree.dir, @git.dir.to_s) + git_dir = Pathname.new(@git.dir.to_s).realpath.to_s + assert_equal(worktree.dir, git_dir) assert_equal(worktree.gcommit, SAMPLE_LAST_COMMIT) end