diff --git a/.travis.yml b/.travis.yml index 3db3cb76..fc1c7b13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,12 @@ language: ruby rvm: - - 1.9.3 - - 2.0.0 - - 2.1.10 - - 2.3.4 - - 2.4.3 - - 2.5.0 - - jruby-9.1.15.0 + - 2.3 + - 2.4 + - 2.5 + - jruby matrix: allow_failures: - - rvm: jruby-9.1.15.0 + - rvm: jruby fast_finish: true before_install: - gem install bundler diff --git a/CHANGELOG b/CHANGELOG.md similarity index 90% rename from CHANGELOG rename to CHANGELOG.md index 78dff72c..b24e5cfe 100644 --- a/CHANGELOG +++ b/CHANGELOG.md @@ -1,13 +1,23 @@ -== 1.3.0 +# Change Log + +## 1.5.0 + +See https://github.com/ruby-git/ruby-git/releases/tag/v1.5.0 + +## 1.4.0 + +See https://github.com/ruby-git/ruby-git/releases/tag/v1.4.0 + +## 1.3.0 * Dropping Ruby 1.8.x support -== 1.2.10 +## 1.2.10 * Adding Git::Diff.name_status * Checking and fixing encoding on commands output to prevent encoding errors afterwards -== 1.2.9 +## 1.2.9 * Adding Git.configure (to configure the git env) * Adding Git.ls_remote [Git.ls_remote(repo_path_or_url='.')] @@ -27,13 +37,13 @@ * Git.fetch - supporting --prune * Git.tag - supporting -== 1.2.8 +## 1.2.8 * Keeping the old escape format for windows users * revparse: Supporting ref names containing SHA like substrings (40-hex strings) * Fix warnings on Ruby 2.1.2 -== 1.2.7 +## 1.2.7 * Fixing mesages encoding * Fixing -f flag in git push @@ -45,7 +55,7 @@ * Git.add_tag options - supporting -a, -m and -s * Added Git.delete_tag -== 1.2.6 +## 1.2.6 * Ruby 1.9.X/2.0 fully supported * JRuby 1.8/1.9 support @@ -61,12 +71,12 @@ * Travis configuration * Licence included with the gem -== 1.0.4 +## 1.0.4 * added camping/gitweb.rb frontend * added a number of speed-ups -== 1.0.3 +## 1.0.3 * Sped up most of the operations * Added some predicate functions (commit?, tree?, etc) @@ -74,11 +84,11 @@ * Fixed a bug with using bare repositories * Updated a good amount of the documentation -== 1.0.2 +## 1.0.2 * Added methods to the git objects that might be helpful -== 1.0.1 +## 1.0.1 * Initial version diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..5b97cdca --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,94 @@ +# Contributing to ruby-git + +Thank you for your interest in contributing to this project. + +These are mostly guidelines, not rules. +Use your best judgment, and feel free to propose changes to this document in a pull request. + +#### Table Of Contents + +[How Can I Contribute?](#how-can-i-contribute) + * [Submitting Issues](#submitting-issues) + * [Contribution Process](#contribution-process) + * [Pull Request Requirements](#pull-request-requirements) + * [Code Review Process](#code-review-process) + * [Developer Certification of Origin (DCO)](#developer-certification-of-origin-dco) + + +## How Can I Contribute? + +### Submitting Issues + +We utilize **GitHub Issues** for issue tracking and contributions. You can contribute in two ways: + +1. Reporting an issue or making a feature request [here](https://github.com/ruby-git/ruby-git/issues/new). +2. Adding features or fixing bugs yourself and contributing your code to ruby-git. + +### Contribution Process + +We have a 3 step process for contributions: + +1. Commit changes to a git branch in your fork. Making sure to sign-off those changes for the [Developer Certificate of Origin](#developer-certification-of-origin-dco). +2. Create a GitHub Pull Request for your change, following the instructions in the pull request template. +3. Perform a [Code Review](#code-review-process) with the project maintainers on the pull request. + +### Pull Request Requirements +In order to ensure high quality, we require that all pull requests to this project meet these specifications: + +1. Unit Testing: We require all the new code to include unit tests, and any fixes to pass previous units. +2. Green CI Tests: We are using [Travis CI](https://travis-ci.org/ruby-git/ruby-git) to run unit tests on various ruby versions, we expect them to all pass before a pull request will be merged. +3. Up-to-date Documentation: New methods as well as updated methods should have [YARD](https://yardoc.org/) documentation added to them + +### Code Review Process + +Code review takes place in GitHub pull requests. See [this article](https://help.github.com/articles/about-pull-requests/) if you're not familiar with GitHub Pull Requests. + +Once you open a pull request, project maintainers will review your code and respond to your pull request with any feedback they might have. + +The process at this point is as follows: + +1. One thumbs-up (:+1:) is required from project maintainers. See the master maintainers document for the ruby-git project at . +2. When ready, your pull request will be merged into `master`, we may require you to rebase your PR to the latest `master`. + +### Developer Certification of Origin (DCO) + +Licensing is very important to open source projects. It helps ensure the software continues to be available under the terms that the author desired. + +ruby-git uses [the MIT license](https://github.com/ruby-git/ruby-git/blob/master/LICENSE) + +Detail about the LICENSE can be found [here](https://choosealicense.com/licenses/mit/) + +To make a good faith effort to ensure these criteria are met, ruby-git requires the Developer Certificate of Origin (DCO) process to be followed. + +The DCO is an attestation attached to every contribution made by every developer. + +In the commit message of the contribution, the developer simply adds a Signed-off-by statement and thereby agrees to the DCO, which you can find below or at . + +``` +Developer's Certificate of Origin 1.1 + +By making a contribution to this project, I certify that: + +(a) The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file; or + +(b) The contribution is based upon previous work that, to the + best of my knowledge, is covered under an appropriate open + source license and I have the right under that license to + submit that work with modifications, whether created in whole + or in part by me, under the same open source license (unless + I am permitted to submit under a different license), as + Indicated in the file; or + +(c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + +(d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including + all personal information I submit with it, including my + sign-off) is maintained indefinitely and may be redistributed + consistent with this project or the open source license(s) + involved. +``` diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..dd4fc23c --- /dev/null +++ b/ISSUE_TEMPLATE.md @@ -0,0 +1,15 @@ +### Subject of the issue +Describe your issue here. + +### Your environment +* version of git and ruby-git +* version of ruby + +### Steps to reproduce +Tell us how to reproduce this issue. + +### Expected behaviour +What did you expect to happen? + +### Actual behaviour +What actually happened? \ No newline at end of file diff --git a/MAINTAINERS.md b/MAINTAINERS.md new file mode 100644 index 00000000..43b76f74 --- /dev/null +++ b/MAINTAINERS.md @@ -0,0 +1,8 @@ +# Maintainers + +When making changes to the system, this file tells you who needs to review your patch - you need at least two maintainers to provide a :+1: on your pull request. + +### Maintainers + +* [Per Lundberg](https://github.com/perlun) +* [Vern Burton](https://github.com/tarcinil) \ No newline at end of file diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000..29510619 --- /dev/null +++ b/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,9 @@ +### Your checklist for this pull request +🚨Please review the [guidelines for contributing](../CONTRIBUTING.md) to this repository. + +- [ ] Ensure all commits include DCO sign-off. +- [ ] Ensure that your contributions pass unit testing. +- [ ] Ensure that your contributions contain documentation if applicable. + +### Description +Please describe your pull request. diff --git a/README.md b/README.md index 7dc5682c..286e355e 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,7 @@ And here are the operations that will need to write to your git repository. g.branch('new_branch').checkout g.branch('new_branch').delete g.branch('existing_branch').checkout + g.branch('master').contains?('existing_branch') g.checkout('new_branch') g.checkout(g.branch('new_branch')) @@ -226,6 +227,7 @@ And here are the operations that will need to write to your git repository. g.fetch g.fetch(g.remotes.first) + g.fetch('origin', {:ref => 'some/ref/head'} ) g.pull g.pull(Git::Repo, Git::Branch) # fetch and a merge diff --git a/VERSION b/VERSION deleted file mode 100644 index 1e754301..00000000 --- a/VERSION +++ /dev/null @@ -1,2 +0,0 @@ -1.3.0 - diff --git a/git.gemspec b/git.gemspec index bad8a496..a3c5d5d3 100644 --- a/git.gemspec +++ b/git.gemspec @@ -23,10 +23,11 @@ Gem::Specification.new do |s| s.rdoc_options = ['--charset=UTF-8'] s.files = [ - 'CHANGELOG', + 'CHANGELOG.md', + 'CONTRIBUTING.md', + 'MAINTAINERS.md', 'LICENSE', 'README.md', - 'VERSION', 'lib/git.rb', 'lib/git/author.rb', 'lib/git/base.rb', diff --git a/lib/git/branch.rb b/lib/git/branch.rb index 4f69e0cd..17573af6 100644 --- a/lib/git/branch.rb +++ b/lib/git/branch.rb @@ -60,6 +60,10 @@ def current determine_current end + def contains?(commit) + !@base.lib.branch_contains(commit, self.name).empty? + end + def merge(branch = nil, message = nil) if branch in_branch do diff --git a/lib/git/diff.rb b/lib/git/diff.rb index 19da0e92..ff819be0 100644 --- a/lib/git/diff.rb +++ b/lib/git/diff.rb @@ -127,10 +127,11 @@ def process_full_diff } final = {} current_file = nil - full_diff_utf8_encoded = @full_diff.encode("UTF-8", "binary", { - :invalid => :replace, - :undef => :replace - }) + if @full_diff.encoding.name != "UTF-8" + full_diff_utf8_encoded = @full_diff.encode("UTF-8", "binary", { :invalid => :replace, :undef => :replace }) + else + full_diff_utf8_encoded = @full_diff + end full_diff_utf8_encoded.split("\n").each do |line| if m = /^diff --git a\/(.*?) b\/(.*?)/.match(line) current_file = m[1] diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 17fe8f15..fc390af5 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -318,6 +318,9 @@ def branch_current branches_all.select { |b| b[1] }.first[0] rescue nil end + def branch_contains(commit, branch_name="") + command("branch", [branch_name, "--contains", commit]) + end # returns hash # [tree-ish] = [[line_no, match], [line_no, match2]] @@ -445,7 +448,7 @@ def config_get(name) if @git_dir Dir.chdir(@git_dir, &do_get) else - build_list.call + do_get.call end end @@ -553,6 +556,7 @@ def commit(message, opts = {}) arr_opts << '--all' if opts[:add_all] || opts[:all] arr_opts << '--allow-empty' if opts[:allow_empty] arr_opts << "--author=#{opts[:author]}" if opts[:author] + arr_opts << "--date=#{opts[:date]}" if opts[:date].is_a? String command('commit', arr_opts) end @@ -600,10 +604,12 @@ def stashes_all arr = [] filename = File.join(@git_dir, 'logs/refs/stash') if File.exist?(filename) - File.open(filename).each_with_index { |line, i| - m = line.match(/:(.*)$/) - arr << [i, m[1].strip] - } + File.open(filename) do |f| + f.each_with_index do |line, i| + m = line.match(/:(.*)$/) + arr << [i, m[1].strip] + end + end end arr end @@ -727,7 +733,10 @@ def tag(name, *opts) arr_opts << '-d' if opts[:d] || opts[:delete] arr_opts << name arr_opts << target if target - arr_opts << "-m #{opts[:m] || opts[:message]}" if opts[:m] || opts[:message] + + if opts[:m] || opts[:message] + arr_opts << '-m' << (opts[:m] || opts[:message]) + end command('tag', arr_opts) end @@ -735,6 +744,7 @@ def tag(name, *opts) def fetch(remote, opts) arr_opts = [remote] + arr_opts << opts[:ref] if opts[:ref] arr_opts << '--tags' if opts[:t] || opts[:tags] arr_opts << '--prune' if opts[:p] || opts[:prune] @@ -747,6 +757,7 @@ def push(remote, branch = 'master', opts = {}) arr_opts = [] arr_opts << '--mirror' if opts[:mirror] + arr_opts << '--delete' if opts[:delete] arr_opts << '--force' if opts[:force] || opts[:f] arr_opts << remote diff --git a/lib/git/stashes.rb b/lib/git/stashes.rb index 8bb71af5..0ebb9bed 100644 --- a/lib/git/stashes.rb +++ b/lib/git/stashes.rb @@ -13,6 +13,17 @@ def initialize(base) @stashes.unshift(Git::Stash.new(@base, message, true)) end end + + # + # Returns an multi-dimensional Array of elements that have been stash saved. + # Array is based on position and name. See Example + # + # @example Returns Array of items that have been stashed + # .all - [0, "testing-stash-all"]] + # @return [Array] + def all + @base.lib.stashes_all + end def save(message) s = Git::Stash.new(@base, message) diff --git a/lib/git/version.rb b/lib/git/version.rb index 0cc3a1e8..62fd6033 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.4.0' + VERSION='1.5.0' end diff --git a/tests/units/test_branch.rb b/tests/units/test_branch.rb index fee70abc..8f83a6d9 100644 --- a/tests/units/test_branch.rb +++ b/tests/units/test_branch.rb @@ -44,6 +44,14 @@ def test_branches_single end end + def test_true_branch_contains? + assert(@git.branch('git_grep').contains?('master')) + end + + def test_false_branch_contains? + assert(!@git.branch('master').contains?('git_grep')) + end + def test_branch_commit assert_equal(270, @git.branches[:test_branches].gcommit.size) end diff --git a/tests/units/test_lib.rb b/tests/units/test_lib.rb index 403a2877..ff5446f1 100644 --- a/tests/units/test_lib.rb +++ b/tests/units/test_lib.rb @@ -21,7 +21,20 @@ def test_commit_data assert_equal("test\n", data['message']) assert_equal(["546bec6f8872efa41d5d97a369f669165ecda0de"], data['parent']) end - + + def test_commit_with_date + create_file("#{@wdir}/test_file_1", 'content tets_file_1') + @lib.add('test_file_1') + + author_date = Time.new(2016, 8, 3, 17, 37, 0, "-03:00") + + @lib.commit('commit with date', date: author_date.strftime('%Y-%m-%dT%H:%M:%S %z')) + + data = @lib.commit_data('HEAD') + + assert_equal("Scott Chacon #{author_date.strftime("%s %z")}", data['author']) + end + def test_checkout assert(@lib.checkout('test_checkout_b',{:new_branch=>true})) assert(@lib.checkout('master')) diff --git a/tests/units/test_remotes.rb b/tests/units/test_remotes.rb index 1b9a7892..3e90c3b5 100644 --- a/tests/units/test_remotes.rb +++ b/tests/units/test_remotes.rb @@ -122,6 +122,34 @@ def test_fetch assert(loc.tags.map(&:name).include?('test-tag-in-deleted-branch')) end end + + def test_fetch_ref_adds_ref_option + in_temp_dir do |path| + loc = Git.clone(@wbare, 'local') + rem = Git.clone(@wbare, 'remote', :config => 'receive.denyCurrentBranch=ignore') + loc.add_remote('testrem', rem) + + loc.chdir do + new_file('test-file1', 'gonnaCommitYou') + loc.add + loc.commit('master commit 1') + first_commit_sha = loc.log.first.sha + + new_file('test-file2', 'gonnaCommitYouToo') + loc.add + loc.commit('master commit 2') + second_commit_sha = loc.log.first.sha + + # Make sure fetch message only has the first commit when we fetch the first commit + assert(loc.fetch('origin', {:ref => first_commit_sha}).include?(first_commit_sha)) + assert(!loc.fetch('origin', {:ref => first_commit_sha}).include?(second_commit_sha)) + + # Make sure fetch message only has the second commit when we fetch the second commit + assert(loc.fetch('origin', {:ref => second_commit_sha}).include?(second_commit_sha)) + assert(!loc.fetch('origin', {:ref => second_commit_sha}).include?(first_commit_sha)) + end + end + end def test_push in_temp_dir do |path| diff --git a/tests/units/test_stashes.rb b/tests/units/test_stashes.rb index 2306061b..c47ab1d9 100644 --- a/tests/units/test_stashes.rb +++ b/tests/units/test_stashes.rb @@ -32,5 +32,27 @@ def test_stash_unstash end end end + + def test_stashes_all + in_temp_dir do |path| + g = Git.clone(@wbare, 'stash_test') + Dir.chdir('stash_test') do + assert_equal(0, g.branch.stashes.size) + new_file('test-file1', 'blahblahblah1') + new_file('test-file2', 'blahblahblah2') + assert(g.status.untracked.assoc('test-file1')) + + g.add + + assert(g.status.added.assoc('test-file1')) + + g.branch.stashes.save('testing-stash-all') + + stashes = g.branch.stashes.all + + assert(stashes[0].include?('testing-stash-all')) + end + end + end end \ No newline at end of file diff --git a/tests/units/test_tags.rb b/tests/units/test_tags.rb index fde0683c..cbd707f8 100644 --- a/tests/units/test_tags.rb +++ b/tests/units/test_tags.rb @@ -65,12 +65,21 @@ def test_tags assert_equal(tag1.tagger.name, 'Test User') assert_equal(tag1.tagger.email, 'test@email.com') assert_true((Time.now - tag1.tagger.date) < 10) - assert_equal(tag1.message, ' test message') - + assert_equal(tag1.message, 'test message') + tag2 = r2.tag('fifth') assert_false(tag2.annotated?) assert_equal(tag2.tagger, nil) assert_equal(tag2.message, nil) end end + + def test_tag_message_not_prefixed_with_space + in_temp_dir do |path| + repo = Git.clone(@wbare, 'repo1') + repo.add_tag('donkey', :annotated => true, :message => 'hello') + tag = repo.tag('donkey') + assert_equal(tag.message, 'hello') + end + end end