Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fnmatch patterns has preblem in diff #882

Open
OuYangJinTing opened this issue Aug 3, 2021 · 0 comments
Open

fnmatch patterns has preblem in diff #882

OuYangJinTing opened this issue Aug 3, 2021 · 0 comments

Comments

@OuYangJinTing
Copy link

OuYangJinTing commented Aug 3, 2021

Summary

When target file path has a space(eg: 'README.md '), Rugged::Tree.diff(..., paths: ['README.md ']).patches return empty array.
This should be a problem caused by the ext or libgit2, but I have not learn C language and I can't fix it.
Can you help me deal with it? Thanks.

Steps to reproduce

# frozen_string_literal: true

require 'bundler/inline'

gemfile(true) do
  source 'https://gems.ruby-china.com'

  gem 'minitest'
  gem 'rugged'
end

require 'minitest/autorun'
require 'rugged'

class DiffBugTest < Minitest::Test
  def setup
    author = committer = { name: 'foobar', email: 'foobar@test.com', time: Time.now }
    @repository = Rugged::Repository.init_at('/tmp/rugged_test_repository.git', true)

    @repository.index << { path: 'A', mode: 0o100644, oid: @repository.write('A file', :blob)}
    @repository.index << { path: 'B ', mode: 0o100644, oid: @repository.write('B file', :blob)} # NOTE: 'B ' path has a space
    @first_oid = Rugged::Commit.create(
      @repository,
      author: author,
      committer: committer,
      message: 'First commit',
      parents: [],
      tree: @repository.index.write_tree,
    )

    @repository.index << { path: 'A', mode: 0o100644, oid: @repository.write('Modified A file', :blob)}
    @repository.index << { path: 'B ', mode: 0o100644, oid: @repository.write('Modified B file', :blob)} # NOTE: 'B ' path has a space
    @second_oid = Rugged::Commit.create(
      @repository,
      author: author,
      committer: committer,
      message: 'Second commit',
      parents: [@first_oid],
      tree: @repository.index.write_tree,
    )
  end

  # NOTE: 'B ' path has a space
  def test_path_end_with_space
    # Success
    assert_equal 2, @repository.diff(@first_oid, @second_oid).patches.size
    assert_equal 2, @repository.diff(@first_oid, @second_oid, paths: ['A', 'B '], disable_pathspec_match: true).patches.size

    # Failure
    assert_equal 2, @repository.diff(@first_oid, @second_oid, paths: ['A', 'B ']).patches.size # => Missing 'B ' patch
  end
end

PS: English is not my native language; please excuse typing errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant