ernie-research/MEnvData-SWE huggingface dataset:
Repository: rubyzip/rubyzip (Ruby)

Issue:
read remainder of entry through input stream fails if a partial read has already been performed.
/lib/zip/ioextras/abstract_input_stream.rb line 22 does not check number_of_bytes for nil before using it.  If the output buffer is not empty due to a partial read on the stream, and a read with no parameters is performed then NoMethodError is raised instead of returning the remainder of the stream.  Can be reproduced via this pseudocode:

z = Zip::File.open('my-zip-file.zip')
e = z.entries.first # Assume first entry is a file
s = e.get_input_stream  # get an input stream to read the file entry
l = s.readline # read the first line of the entry
r = s.read # read remainder of entry
#<NoMethodError: undefined method `<=' for nil:NilClass>


Discussion:
Thanks for spotting this. I think the linked PR will fix this.



Patch:
diff --git a/Changelog.md b/Changelog.md
index cb4a893e..ab862d3f 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,5 +1,7 @@
 # X.X.X (Next)
 
+- Fix input stream partial read error. [#462](https://github.com/rubyzip/rubyzip/pull/462)
+
 Tooling:
 
 - Update rubocop again and run it in CI. [#444](https://github.com/rubyzip/rubyzip/pull/444)
diff --git a/lib/zip/ioextras/abstract_input_stream.rb b/lib/zip/ioextras/abstract_input_stream.rb
index 8392d240..848dcae3 100644
--- a/lib/zip/ioextras/abstract_input_stream.rb
+++ b/lib/zip/ioextras/abstract_input_stream.rb
@@ -19,7 +19,7 @@ def initialize
 
       def read(number_of_bytes = nil, buf = '')
         tbuf = if @output_buffer.bytesize > 0
-                 if number_of_bytes <= @output_buffer.bytesize
+                 if number_of_bytes && number_of_bytes <= @output_buffer.bytesize
                    @output_buffer.slice!(0, number_of_bytes)
                  else
                    number_of_bytes -= @output_buffer.bytesize if number_of_bytes


Test patch:
diff --git a/test/input_stream_test.rb b/test/input_stream_test.rb
index 773ee6b5..34042ba9 100644
--- a/test/input_stream_test.rb
+++ b/test/input_stream_test.rb
@@ -179,4 +179,14 @@ def test_ungetc
       assert_equal('$VERBOSE =', zis.read(10))
     end
   end
+
+  def test_readline_then_read
+    ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
+      zis.get_next_entry
+      assert_equal("#!/usr/bin/env ruby\n", zis.readline)
+      refute(zis.eof?)
+      refute_empty(zis.read) # Also should not raise an error.
+      assert(zis.eof?)
+    end
+  end
 end
Repository: ruby-syntax-tree/syntax_tree (Ruby)

Issue:
Rightward assignment `=>` converted to `in` when preceded by `in` in a prior line
Example:

```ruby
puts SyntaxTree.format <<~RUBY
  if a in Integer
    puts "a is integer"
  end

  b => [Integer => c]
RUBY
```

emits:

```ruby
puts "a is integer" if a in Integer

b in [Integer => c]
```

---

However, as long as you don't use `in` earlier in scope, the `b` line correctly isn't modified

```ruby
puts SyntaxTree.format "b => [Integer => c]"
```

emits

```ruby
b => [Integer => c]
````

Happy to take a crack at fixing if you can point me in the right direction.


Discussion:
Thanks for the report! This was actually pretty in the weeds of how the parser works so I went ahead and fixed it myself. The PR is linked, and it'll be out in the next release.



Patch:
diff --git a/lib/syntax_tree/parser.rb b/lib/syntax_tree/parser.rb
index 8af0b8ed..ed9de499 100644
--- a/lib/syntax_tree/parser.rb
+++ b/lib/syntax_tree/parser.rb
@@ -910,7 +910,12 @@ def on_case(value, consequent)
           location: keyword.location.to(consequent.location)
         )
       else
-        operator = find_token(Kw, "in", consume: false) || find_token(Op, "=>")
+        operator =
+          if (keyword = find_token(Kw, "in", consume: false))
+            tokens.delete(keyword)
+          else
+            find_token(Op, "=>")
+          end
 
         RAssign.new(
           value: value,


Test patch:
diff --git a/test/fixtures/rassign.rb b/test/fixtures/rassign.rb
index ce749550..3db52b18 100644
--- a/test/fixtures/rassign.rb
+++ b/test/fixtures/rassign.rb
@@ -20,3 +20,6 @@
   ConstantConstantConstant,
   ConstantConstantConstant
 ]
+%
+a in Integer
+b => [Integer => c]
Repository: basecamp/kamal (Ruby)

Issue:
`kamal app exec` without `--interactive` or `--reuse` does not allow to load env file
When upgrading to Kamal 1.0.0, we noticed our `kamal app exec 'bin/rails db:migrate'` command we run during deployment stopped working, because the environment variables are not available.

Running `kamal app exec --version=xyz --destination=staging --interactive 'bin/rails console'` works just fine. Without the `--interactive` option, it crashes with an error, saying it couldn't find an environment variable (`REDIS_URL` in our case).

Looking at the commands that are being executed, it seems that with `--interactive` the `--env-file` option is passed to the docker command, whereas without the `--interactive` option, the `--env-file` option is not passed. When using the interactive option, the command is executed with 

```
KAMAL.app(role: KAMAL.primary_role).execute_in_new_container_over_ssh(cmd, host: KAMAL.primary_host)
```

(note the `role: KAMAL.primary_role`) and without the flag, it is executed with 
```
KAMAL.app.execute_in_new_container(cmd)
```

It seems there is no way to pass/use a role when not using `--interactive` or `--reuse`.

I'm happy to open a PR, but I'm not entirely sure what the intentions behind `app exec` without these flags are. There is a global `--roles` option which could be used here, but the description for it is "Run commands on these roles instead of all (separate by comma)", so not sure if this would be correct.


Discussion:

Patch:
diff --git a/lib/kamal/cli/app.rb b/lib/kamal/cli/app.rb
index 601d485e6..fae607fcf 100644
--- a/lib/kamal/cli/app.rb
+++ b/lib/kamal/cli/app.rb
@@ -147,8 +147,12 @@ def exec(cmd)
       using_version(version_or_latest) do |version|
         say "Launching command with version #{version} from new container...", :magenta
         on(KAMAL.hosts) do |host|
-          execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on app version #{version}"), verbosity: :debug
-          puts_by_host host, capture_with_info(*KAMAL.app.execute_in_new_container(cmd))
+          roles = KAMAL.roles_on(host)
+
+          roles.each do |role|
+            execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on app version #{version}"), verbosity: :debug
+            puts_by_host host, capture_with_info(*KAMAL.app(role: role).execute_in_new_container(cmd))
+          end
         end
       end
     end


Test patch:
diff --git a/test/cli/app_test.rb b/test/cli/app_test.rb
index c70b8ed49..fd1064213 100644
--- a/test/cli/app_test.rb
+++ b/test/cli/app_test.rb
@@ -159,7 +159,7 @@ class CliAppTest < CliTestCase
 
   test "exec" do
     run_command("exec", "ruby -v").tap do |output|
-      assert_match "docker run --rm dhh/app:latest ruby -v", output
+      assert_match "docker run --rm --env-file .kamal/env/roles/app-web.env dhh/app:latest ruby -v", output
     end
   end
Repository: rails/jquery-rails (Ruby)

Issue:
Why we must have semicolon
I use `assert_select_jquery` to test my code and I debug the gem I get this pattern

```
   77:     patterns << argumentless_pattern unless jquery_opt
   78:
   79:     matched_pattern = nil
   80:     patterns.each do |pattern|
   81:       debugger
=> 82:       if response.body.match(Regexp.new(pattern))
   83:         matched_pattern = pattern
   84:         break
   85:       end
   86:     end
(byebug) pattern
"(?:jQuery|\\$)\\(['\"]#cart['\"]\\)\\.html\\(['\"]((\\\\\"|[^\"])*)['\"]\\);"
```

The pattern content the `;` , So my code  never pass the test.

```
$('#cart').html("<%=j render(@cart) %>")
```

If I add the `;` to it , it can pass the test.

```
$('#cart').html("<%=j render(@cart) %>");
```

I think the `;`  in the pattern should be optional, right?


Discussion:
right. Mind to open a PR?
@rafaelfranca OK let me try. Thank you for your reply.
@rafaelfranca I already open a PR.



Patch:
diff --git a/lib/jquery/assert_select.rb b/lib/jquery/assert_select.rb
index bae783e0..debf99d1 100644
--- a/lib/jquery/assert_select.rb
+++ b/lib/jquery/assert_select.rb
@@ -49,7 +49,7 @@ module Rails::Dom::Testing::Assertions::SelectorAssertions
 
   PATTERN_HTML  = "['\"]((\\\\\"|\\\\'|[^\"'])*)['\"]"
   PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
-  SKELETAL_PATTERN = "(?:jQuery|\\$)\\(%s\\)\\.%s\\(%s\\);"
+  SKELETAL_PATTERN = "(?:jQuery|\\$)\\(%s\\)\\.%s\\(%s\\)[;]?"
 
   def assert_select_jquery(*args, &block)
     jquery_method = args.first.is_a?(Symbol) ? args.shift : nil


Test patch:
diff --git a/test/assert_select_jquery_test.rb b/test/assert_select_jquery_test.rb
index ed93d519..90c6dcb0 100644
--- a/test/assert_select_jquery_test.rb
+++ b/test/assert_select_jquery_test.rb
@@ -1,3 +1,4 @@
+require 'ostruct'
 require_relative 'test_helper'
 require_relative '../lib/jquery/assert_select'
 
@@ -19,6 +20,9 @@ class AssertSelectJQueryTest < ActiveSupport::TestCase
     $("#cart tr:not(.total_line) > *").remove();
     $("[href|=\"val\"][href$=\"val\"][href^=\"val\"]").remove();
     $("tr + td, li").remove();
+
+    // without semicolon
+    $("#browser_cart").hide("blind", 1000)
   JS
 
   setup do
@@ -28,6 +32,7 @@ class AssertSelectJQueryTest < ActiveSupport::TestCase
   def test_target_as_receiver
     assert_nothing_raised do
       assert_select_jquery :show, :blind, '#card'
+      assert_select_jquery :hide, :blind, '#browser_cart'
       assert_select_jquery :html, '#id' do
         assert_select 'p', 'something'
       end
Repository: rgeo/rgeo (Ruby)

Issue:
Polygon centroid has different SRID
`RGeo::Geographic::SphericalPolygonImpl#centroid` always returns new point with default SRID = 4055. 

https://github.com/rgeo/rgeo/blob/master/lib/rgeo/geographic/spherical_feature_methods.rb#L235

### Steps to reproduce

```ruby
> factory = RGeo::Geographic.spherical_factory(srid: 4326)
> point1 = factory.point(0, 0)
> point2 = factory.point(0, 1)
> point3 = factory.point(1, 0)
> exterior = factory.linear_ring([point1, point2, point3, point1])
> polygon = factory.polygon(exterior)

> polygon.centroid.srid
=> 4055
> polygon.srid
=> 4326
```

### Expected behavior

`RGeo::Geographic::SphericalPolygonImpl#centroid` can use existing `RGeo::Geographic::SphericalPolygonImpl#factory` to build centroid point

### Actual behavior

It happens because `module RGeo::Geographic::SphericalPolygonImpl` builds point with new factory with default SRID = 4055.

### System configuration

**Ruby version**: ruby 2.7.4p191

**OS**: Mac OS X 10.15.7



Discussion:

Patch:
diff --git a/History.md b/History.md
index c8e8f949..bd827dc4 100644
--- a/History.md
+++ b/History.md
@@ -7,6 +7,7 @@
 **Bug Fixes**
 
 * Fix memory leak on failing geometry collection creation #301
+* Use polygon factory on build polygon centroid #306
 
 ### 3.0.0-rc.1 / 2022-03-22
 
diff --git a/lib/rgeo/geographic/spherical_feature_methods.rb b/lib/rgeo/geographic/spherical_feature_methods.rb
index 9c8829f8..551c41ff 100644
--- a/lib/rgeo/geographic/spherical_feature_methods.rb
+++ b/lib/rgeo/geographic/spherical_feature_methods.rb
@@ -232,7 +232,7 @@ def centroid
         centroid_lat /= (6.0 * signed_area)
         centroid_lng /= (6.0 * signed_area)
 
-        RGeo::Geographic.spherical_factory.point(centroid_lat, centroid_lng)
+        factory.point(centroid_lat, centroid_lng)
       end
     end
   end


Test patch:
diff --git a/test/spherical_geographic/polygon_test.rb b/test/spherical_geographic/polygon_test.rb
index b1cb3241..007d7516 100644
--- a/test/spherical_geographic/polygon_test.rb
+++ b/test/spherical_geographic/polygon_test.rb
@@ -28,4 +28,16 @@ def test_centroid
     polygon = @factory.polygon(exterior)
     assert_equal @factory.point(1.0/3.0, 1.0/3.0), polygon.centroid
   end
+
+  def test_centroid_srid
+    factory = RGeo::Geographic.spherical_factory(srid: 4326)
+
+    point1 = factory.point(0, 0)
+    point2 = factory.point(0, 1)
+    point3 = factory.point(1, 0)
+    exterior = factory.linear_ring([point1, point2, point3, point1])
+    polygon = factory.polygon(exterior)
+
+    assert_equal 4326, polygon.centroid.srid
+  end
 end
Repository: weppos/publicsuffix-ruby (Ruby)

Issue:
Ruby 2.7 warning about PublicSuffix::List.default
Seen in testing:
```
.../publicsuffix-ruby/lib/public_suffix/list.rb:51: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
.../publicsuffix-ruby/lib/public_suffix/list.rb:69: warning: The called method `parse' is defined here
```


Discussion:
FYI, Ruby 2.8.0-dev does not perform deprecation warnings and implicit conversions.
https://github.com/ruby/ruby/pull/2794

With this change, the following error occurs in Ruby 2.8.0-dev.

```console
% ruby -v
ruby 2.8.0dev (2020-01-05T05:35:14Z master 54fd50c951) [x86_64-darwin17]
% bundle exec rake
(snip)

Error:
AcceptanceTest#test_ignore_private:
ArgumentError: wrong number of arguments (given 2, expected 1)
    /Users/koic/src/github.com/weppos/publicsuffix-ruby/lib/public_suffix/list.rb:69:in `parse'
    /Users/koic/src/github.com/weppos/publicsuffix-ruby/lib/public_suffix/list.rb:51:in `default'
    /Users/koic/src/github.com/weppos/publicsuffix-ruby/lib/public_suffix.rb:69:in `parse'
    /Users/koic/src/github.com/weppos/publicsuffix-ruby/lib/public_suffix.rb:143:in `domain'
    /Users/koic/src/github.com/weppos/publicsuffix-ruby/test/acceptance_test.rb:105:in `block in test_ignore_private'
    /Users/koic/src/github.com/weppos/publicsuffix-ruby/test/acceptance_test.rb:101:in `each'
    /Users/koic/src/github.com/weppos/publicsuffix-ruby/test/acceptance_test.rb:101:in `test_ignore_private'
```

I look forward to this patch release of public_suffix gem because that resolves the error of Ruby 2.8.0-dev CI matrix in dependent gems.
@koic are you able to confirm that https://github.com/weppos/publicsuffix-ruby/pull/168 will solve your issue in Ruby 2.8.0-dev?
Actually, I believe I can confirm it does given the CI run completed.
4.0.3 packaged and released. Thanks.
Thanks for your prompt reply! Yeah, #168 solved my issue in Ruby 2.8.0-dev.
BTW, rubygems.org doesn't seem to have released 4.0.3 yet. Could you please confirm at your convenience?
https://rubygems.org/gems/public_suffix

It should be released now.
Thank you!



Patch:
diff --git a/lib/public_suffix/list.rb b/lib/public_suffix/list.rb
index c573b4cf..f281d1d3 100644
--- a/lib/public_suffix/list.rb
+++ b/lib/public_suffix/list.rb
@@ -48,7 +48,7 @@ class List
     #
     # @return [PublicSuffix::List]
     def self.default(**options)
-      @default ||= parse(File.read(DEFAULT_LIST_PATH), options)
+      @default ||= parse(File.read(DEFAULT_LIST_PATH), **options)
     end
 
     # Sets the default rule list to +value+.


Test patch:
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 1d5468c3..4f8a4477 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -10,7 +10,7 @@
 
 require "minitest/autorun"
 require "minitest/reporters"
-require "mocha/setup"
+require "mocha/minitest"
 
 Minitest::Reporters.use! Minitest::Reporters::DefaultReporter.new(color: true)
Repository: ruby/rubygems (Ruby)

Issue:
Warn duplicated dependency specifications
I believe we should show a warning when building gems with duplicated dependency specifications, such as

```
spec.add_runtime_dependency "rails", "~> 3.0", "~> 3.0"
```

Because they might indicate a typo.

Also, although probably trickier to fix in general, we could also warn redundant dependency specifications, such as

```
spec.add_runtime_dependency "rails", "> 0", ">= 3.0.0"
```


Discussion:
I'm not sure but I think this is much easier to do this as a part of RuboCop instead?
@deivid-rodriguez should we do that again only during build time?
Yeah, this idea is meant as a tool for gem authors to avoid bugs in their dependency requirements.

@utkarsh2102 It could be made a `rubocop` rule indeed. The difference would be that not everybody would benefit from it by default, but it's an interesting idea... :thinking: 



Patch:
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index af08a8333c22..95a2ca772557 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -560,6 +560,10 @@ def add_development_dependency(gem, *requirements)
   #   spec.add_runtime_dependency 'example', '~> 1.1', '>= 1.1.4'
 
   def add_runtime_dependency(gem, *requirements)
+    if requirements.uniq.size != requirements.size
+      warn "WARNING: duplicated #{gem} dependency #{requirements}"
+    end
+
     add_dependency_with_type(gem, :runtime, requirements)
   end
 


Test patch:
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index 0733899be044..572ba26b7e0e 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -3060,6 +3060,13 @@ def test_unresolved_specs_with_versions
     end
   end
 
+  def test_duplicate_runtime_dependency
+    expected = "WARNING: duplicated b dependency [\"~> 3.0\", \"~> 3.0\"]\n"
+    assert_output nil, expected do
+      @a1.add_runtime_dependency "b", "~> 3.0", "~> 3.0"
+    end
+  end
+
   def set_orig(cls)
     s_cls = cls.singleton_class
     s_cls.send :alias_method, :orig_unresolved_deps , :unresolved_deps
Repository: ruby-syntax-tree/syntax_tree (Ruby)

Issue:
Long chain of << expressions doesn't get cut off
e.g.

```ruby
long_name << longer_name << really_long_name << really_longer_name << even_longer_name << and_a_final_long_name
```

Expected:

```ruby
long_name << longer_name << really_long_name << really_longer_name <<
  even_longer_name << and_a_final_long_name
```


Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d3fd9964..bb8425bd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
 - The `nesting` field on the results of the indexing operation is no longer a single flat array. Instead it is an array of arrays, where each array is a single nesting level. This more accurately reflects the nesting of the nodes in the tree. For example, `class Foo::Bar::Baz; end` would result in `[Foo, Bar, Baz]`, but that incorrectly implies that you can see constants at each of those levels. Now this would result in `[[Foo, Bar, Baz]]` to indicate that it can see either the top level or constants within the scope of `Foo::Bar::Baz` only.
 - When formatting hashes that have omitted values and mixed hash rockets with labels, the formatting now maintains whichever delimiter was used in the source. This is because forcing the use of hash rockets with omitted values results in a syntax error.
 - Handle the case where a bare hash is used after the `break`, `next`, or `return` keywords. Previously this would result in hash labels which is not valid syntax. Now it maintains the delimiters used in the source.
+- The `<<` operator will now break on chained `<<` expressions. Previously it would always stay flat.
 
 ## [6.0.0] - 2023-02-10
 
diff --git a/lib/syntax_tree/node.rb b/lib/syntax_tree/node.rb
index 2dbe3a79..c4bc1495 100644
--- a/lib/syntax_tree/node.rb
+++ b/lib/syntax_tree/node.rb
@@ -2097,10 +2097,7 @@ def format(q)
         q.group { q.format(left) }
         q.text(" ") unless power
 
-        if operator == :<<
-          q.text("<< ")
-          q.format(right)
-        else
+        if operator != :<<
           q.group do
             q.text(operator.name)
             q.indent do
@@ -2108,6 +2105,17 @@ def format(q)
               q.format(right)
             end
           end
+        elsif left.is_a?(Binary) && left.operator == :<<
+          q.group do
+            q.text(operator.name)
+            q.indent do
+              power ? q.breakable_empty : q.breakable_space
+              q.format(right)
+            end
+          end
+        else
+          q.text("<< ")
+          q.format(right)
         end
       end
     end


Test patch:
diff --git a/test/fixtures/binary.rb b/test/fixtures/binary.rb
index f8833cdc..4cb56cbf 100644
--- a/test/fixtures/binary.rb
+++ b/test/fixtures/binary.rb
@@ -3,6 +3,11 @@
 %
 foo << bar
 %
+foo << barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr << barrrrrrrrrrrrr << barrrrrrrrrrrrrrrrrr
+-
+foo << barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr << barrrrrrrrrrrrr <<
+  barrrrrrrrrrrrrrrrrr
+%
 foo**bar
 %
 foo * barrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Repository: rails/importmap-rails (Ruby)

Issue:
Confusing message on 'update'
When I run update I see a confusing message. It doesn't seem to be complete
```
bin/importmap update

Couldn't find any packages in [["@babel/runtime", "@lit/reactive-element", "@videojs/vhs-utils", "keycode", "lit", "lit-element", "lit-html", "m3u8-parser", "mpd-parser", "video.js"]] on
```

When I look for outdated packages it finds them:
```
bin/importmap outdated
| Package               | Current | Latest |
|-----------------------|---------|--------|
| @babel/runtime        | 7.23.5  | 7.23.7 |
| @lit/reactive-element | 1.6.3   | 2.0.2  |
| @videojs/vhs-utils    | 3.0.5   | 4.0.0  |
| keycode               | 2.2.0   | 2.2.1  |
| lit                   | 2.8.0   | 3.1.0  |
| lit-element           | 3.3.3   | 4.0.2  |
| lit-html              | 2.8.0   | 3.1.0  |
| m3u8-parser           | 6.2.0   | 7.1.0  |
| mpd-parser            | 1.2.2   | 1.3.0  |
| video.js              | 8.6.1   | 8.9.0  |
  10 outdated packages found
```

This is on version 2.0.1




Discussion:
Can confirm this happening on Rails 7.2.1 for me.

Changing this https://github.com/rails/importmap-rails/blob/0a6330133b75a72d7c5d07fe87c2fce50d76b997/lib/importmap/commands.rb#L95

to be ...

```ruby
pin *outdated_packages.map(&:name)
```

...fixed it for me locally.
Please do open a PR, @arni1981 



Patch:
diff --git a/lib/importmap/commands.rb b/lib/importmap/commands.rb
index 350cc42..fc59e72 100644
--- a/lib/importmap/commands.rb
+++ b/lib/importmap/commands.rb
@@ -92,7 +92,7 @@ def outdated
   desc "update", "Update outdated package pins"
   def update
     if (outdated_packages = npm.outdated_packages).any?
-      pin outdated_packages.map(&:name)
+      pin(*outdated_packages.map(&:name))
     else
       puts "No outdated packages found"
     end


Test patch:
diff --git a/test/commands_test.rb b/test/commands_test.rb
index 8a3155a..1efd210 100644
--- a/test/commands_test.rb
+++ b/test/commands_test.rb
@@ -20,6 +20,22 @@ class CommandsTest < ActiveSupport::TestCase
     assert_includes JSON.parse(out), "imports"
   end
 
+  test "update command prints message of no outdated packages" do
+    out, _err = run_importmap_command("update")
+    assert_includes out, "No outdated"
+  end
+
+  test "update command prints confirmation of pin with outdated packages" do
+    @tmpdir = Dir.mktmpdir
+    FileUtils.cp_r("#{__dir__}/dummy", @tmpdir)
+    Dir.chdir("#{@tmpdir}/dummy")
+    FileUtils.cp("#{__dir__}/fixtures/files/outdated_import_map.rb", "#{@tmpdir}/dummy/config/importmap.rb")
+    FileUtils.cp("#{__dir__}/../lib/install/bin/importmap", "bin")
+
+    out, _err = run_importmap_command("update")
+    assert_includes out, "Pinning"
+  end
+
   private
     def run_importmap_command(command, *args)
       capture_subprocess_io { system("bin/importmap", command, *args, exception: true) }
Repository: soutaro/steep (Ruby)

Issue:
SyntaxError when parsing anonymous block forwarding
Using Steep 0.52, I run into a syntax error when using anonymous block forwarding:

Example code:
```rb
  def nav_orders_link(organization, options = {}, &)
    path = orders_path(organization)
    options[:rel] = 'noopener'

    link_to(t('navigation.orders'), path, options, &)
  end
```

Steep output:
```sh
app/helpers/navigation_helper.rb:50:51: [error] SyntaxError: unexpected token tRPAREN
│ Diagnostic ID: Ruby::SyntaxError
│
└   def nav_orders_link(organization, options = {}, &)
                                                     ~
```

Changing the `&` to `&block` fixes the issue.


Discussion:

Patch:
diff --git a/lib/steep/type_construction.rb b/lib/steep/type_construction.rb
index 237b4df9e..fd8fe0982 100644
--- a/lib/steep/type_construction.rb
+++ b/lib/steep/type_construction.rb
@@ -2299,7 +2299,8 @@ def synthesize(node, hint: nil, condition: false)
           yield_self do
             value = node.children[0]
 
-            if hint.is_a?(AST::Types::Proc) && value.type == :sym
+            case
+            when hint.is_a?(AST::Types::Proc) && value && value.type == :sym
               if hint.one_arg?
                 # Assumes Symbol#to_proc implementation
                 param_type = hint.type.params.required[0]
@@ -2333,9 +2334,18 @@ def synthesize(node, hint: nil, condition: false)
               else
                 Steep.logger.error "Passing multiple args through Symbol#to_proc is not supported yet"
               end
+            when value == nil
+              type = AST::Types::Proc.new(
+                type: method_context.method_type.block.type,
+                location: nil,
+                block: nil
+              )
+              if method_context.method_type.block.optional?
+                type = AST::Types::Union.build(types: [type, AST::Builtin.nil_type])
+              end
             end
 
-            type ||= synthesize(node.children[0], hint: hint).type
+            type ||= synthesize(value, hint: hint).type
 
             add_typing node, type: type
           end


Test patch:
diff --git a/test/type_construction_test.rb b/test/type_construction_test.rb
index 0ea3b3cbf..610a37ce5 100644
--- a/test/type_construction_test.rb
+++ b/test/type_construction_test.rb
@@ -9121,4 +9121,26 @@ module Mod
       end
     end
   end
+
+  def test_anonymouse_block_forwarding
+    with_checker(<<RBS) do |checker|
+class AnonBlockForwarding
+  def foo: () { (String) -> void } -> void
+end
+RBS
+      source = parse_ruby(<<RUBY)
+class AnonBlockForwarding
+  def foo(&)
+    ["a", "b"].each(&)
+  end
+end
+RUBY
+
+      with_standard_construction(checker, source) do |construction, typing|
+        type, _ = construction.synthesize(source.node)
+
+        assert_no_error(typing)
+      end
+    end
+  end
 end
Repository: ruby-syntax-tree/syntax_tree (Ruby)

Issue:
Rightward assignment inside "case ... when" produces invalid syntax
Hey there!

I noticed the following behaviour, when using rightward assignment `=>` inside a `case ... when`:
```ruby
puts SyntaxTree.format <<~RUBY
  case [0]
  when 0
    { a: 0 } => { a: }
    puts a
  end
RUBY
```

produces:

```ruby
[0] =>
  when 0
    case { a: 0 }
    a:
    end
    puts a
```

It seems like the rightward assignment is moved to the top... producing an invalid ruby syntax.
Do you know where this may come from?

Regards,


Discussion:
Ahh this is a problem with the parser. Just found the fix, thanks!
Works like a charm! Thanks 👏🎉



Patch:
diff --git a/lib/syntax_tree/parser.rb b/lib/syntax_tree/parser.rb
index 85f6661e..fcefed30 100644
--- a/lib/syntax_tree/parser.rb
+++ b/lib/syntax_tree/parser.rb
@@ -995,22 +995,11 @@ def on_call(receiver, operator, message)
     # :call-seq:
     #   on_case: (untyped value, untyped consequent) -> Case | RAssign
     def on_case(value, consequent)
-      if (keyword = find_keyword(:case))
-        tokens.delete(keyword)
-
-        Case.new(
-          keyword: keyword,
-          value: value,
-          consequent: consequent,
-          location: keyword.location.to(consequent.location)
-        )
-      else
-        operator =
-          if (keyword = find_keyword(:in))
-            tokens.delete(keyword)
-          else
-            consume_operator(:"=>")
-          end
+      if value && (operator = find_keyword(:in) || find_operator(:"=>")) &&
+           (value.location.end_char...consequent.location.start_char).cover?(
+             operator.location.start_char
+           )
+        tokens.delete(operator)
 
         node =
           RAssign.new(
@@ -1022,6 +1011,15 @@ def on_case(value, consequent)
 
         PinVisitor.visit(node, tokens)
         node
+      else
+        keyword = consume_keyword(:case)
+
+        Case.new(
+          keyword: keyword,
+          value: value,
+          consequent: consequent,
+          location: keyword.location.to(consequent.location)
+        )
       end
     end
 


Test patch:
diff --git a/test/fixtures/rassign.rb b/test/fixtures/rassign.rb
index 3db52b18..3d357351 100644
--- a/test/fixtures/rassign.rb
+++ b/test/fixtures/rassign.rb
@@ -23,3 +23,9 @@
 %
 a in Integer
 b => [Integer => c]
+%
+case [0]
+when 0
+  { a: 0 } => { a: }
+  puts a
+end
Repository: ruby/rake (Ruby)

Issue:
FileUtils#sh occurs TypeError when using hash style options.
Until rake v.11.1.2, we can run sh commands with hash style option, like the follow. But we have "TypeError" now.

```
task :dir do
  sh "pwd", {chdir: "/home"}, { vernbose: true }
end
# before rake v.11.1.2 #=> /home [OK]
# after rake v.11.2.0  #=> TypeError: no implicit conversion of Hash into String [Error]
```

On the other hand, to write codes same as previous one like the follow, it doesn't work before v.11.1.2.

```
task :dir do
  verbose(true) do
    sh "pwd", {chdir: "/home"}
  end
end
# before rake v.11.1.2 #=> ArgumentError: no such option: chdir [Error]
# after rake v.11.2.0  #=> /home [OK]
```

Is it spec or bug?

### information : About the "TypeError: no implicit conversion of Hash into String"

```
task :dir do
  sh "pwd", {chdir: "/home"}, { vernbose: true }
end
# before rake v.11.1.2 #=> /home
# after rake v.11.2.0  #=> TypeError: no implicit conversion of Hash into String
```

We have the "TypeError: no implicit conversion of Hash into String" error from v.11.2.0.

The error occurs on the lib/rake/file_utils.rb:56 line.
It looks like to become occur from this code changes.
https://github.com/ruby/rake/pull/138/commits/226b8a0dbfca92dfb4202dcf589b53400584d6f3#diff-f7fcb87d482d055b9df1e86fd76ae06fR56

The code use Kernel#system method. After the change, arguments for system method is increasing.

v.11.1.2 
```
system('pwd',  {chdir: "/home"})
#=> /home
```

v.11.2.0
```
system('pwd',  {chdir: "/home"}, {})
#=> TypeError: no implicit conversion of Hash into String
```



Discussion:

Patch:
diff --git a/lib/rake/file_utils.rb b/lib/rake/file_utils.rb
index aa065e8b4..3e56710e2 100644
--- a/lib/rake/file_utils.rb
+++ b/lib/rake/file_utils.rb
@@ -50,7 +50,7 @@ def sh(*cmd, &block)
     Rake.rake_output_message sh_show_command cmd if verbose
 
     unless noop
-      res = system(*cmd, options)
+      res = (Hash === cmd.last) ? system(*cmd) : system(*cmd, options)
       status = $?
       status = Rake::PseudoStatus.new(1) if !res && status.nil?
       shell_runner.call(res, status)


Test patch:
diff --git a/test/test_rake_file_utils.rb b/test/test_rake_file_utils.rb
index 218c25415..00ef76e41 100644
--- a/test/test_rake_file_utils.rb
+++ b/test/test_rake_file_utils.rb
@@ -180,6 +180,15 @@ def test_sh_with_spawn_options
     assert_equal "echocommand.rb\n", r.read
   end
 
+  def test_sh_with_hash_option
+    skip "JRuby does not support spawn options" if jruby?
+    check_expansion
+
+    verbose(false) {
+      sh "#{RUBY} check_expansion.rb", {chdir: "."}, { verbose: false }
+    }
+  end
+
   def test_sh_failure
     shellcommand
Repository: sinatra/sinatra (Ruby)

Issue:
`NoMethodError` when using `content_type` params with `Integer` value
This app

```ruby
require "bundler/inline"

gemfile(true) do
  gem "nio4r"
  gem "sinatra", require: "sinatra/base"
end

class App < Sinatra::Base
  get "/" do
    content_type "foo/bar", baz: 1
    body "OK"
  end
end

run App
```

Blows up like this

```shell
$ puma content_type_bug.ru -p 8888
Puma starting in single mode...
* Puma version: 6.5.0 ("Sky's Version")
* Ruby version: ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [arm64-darwin23]
*  Min threads: 0
*  Max threads: 5
*  Environment: development
*          PID: 12998
Resolving dependencies...
* Listening on http://0.0.0.0:8888
Use Ctrl-C to stop
2025-01-05 09:52:35 - NoMethodError - undefined method `=~' for an instance of Integer (NoMethodError):
	/Users/dentarg/.arm64_rubies/3.3.6/lib/ruby/gems/3.3.0/gems/sinatra-4.1.1/lib/sinatra/base.rb:401:in `block in content_type'
	/Users/dentarg/.arm64_rubies/3.3.6/lib/ruby/gems/3.3.0/gems/sinatra-4.1.1/lib/sinatra/base.rb:400:in `each'
	/Users/dentarg/.arm64_rubies/3.3.6/lib/ruby/gems/3.3.0/gems/sinatra-4.1.1/lib/sinatra/base.rb:400:in `map'
	/Users/dentarg/.arm64_rubies/3.3.6/lib/ruby/gems/3.3.0/gems/sinatra-4.1.1/lib/sinatra/base.rb:400:in `content_type'
	content_type_bug.ru:10:in `block in <class:App>'
```


Discussion:

Patch:
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 7eef6533c..f0bccd8ae 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -398,7 +398,7 @@ def content_type(type = nil, params = {})
       unless params.empty?
         mime_type << (mime_type.include?(';') ? ', ' : ';')
         mime_type << params.map do |key, val|
-          val = val.inspect if val =~ /[";,]/
+          val = val.inspect if val.to_s =~ /[";,]/
           "#{key}=#{val}"
         end.join(', ')
       end


Test patch:
diff --git a/test/base_test.rb b/test/base_test.rb
index 2bccf2e92..66265156c 100644
--- a/test/base_test.rb
+++ b/test/base_test.rb
@@ -181,5 +181,17 @@ class TestMiddlewareContentLength < Sinatra::Base
       response = request_content_length.get('/forward')
       assert_equal '28', response['Content-Length']
     end
+
+    it 'formats integer values correctly in Content-Type parameters' do
+      mock_app do
+        get('/') do
+          content_type "foo/bar", baz: 1
+          'Ok'
+        end
+      end
+
+      get '/'
+      assert_equal 'foo/bar;baz=1', response['Content-Type']
+    end
   end
 end
Repository: freerange/mocha (Ruby)

Issue:
Object.mocha_inspect not compatible with classes that define a 'format' method
It looks like setting an expectation on a class that defines a `format` method results in an `ArgumentError`. 

Take the following test case:

```
class ObjectTest < ActiveSupport::TestCase

  class DummyClass
    attr_reader :format
  end

  test 'dummy class expectations' do
    dummy_class = DummyClass.new
    dummy_class.expects(:foo)
  end

end
```

Running it:

```
ObjectTest
  test_dummy_class_expectations                                  ERROR (0.13s)
ArgumentError:         ArgumentError: wrong number of arguments (2 for 0)

```

This is because `mocha_inspect` calls the `format` method:

```
def mocha_inspect
  address = __id__ * 2
  address += 0x100000000 if address < 0
  inspect =~ /#</ ? "#<#{self.class}:0x#{format('%x', address)}>" : inspect
end
```

Would you consider changing that to call `Kernel.format` directly? This way it won't interfere with any instance methods on the object being inspected. If so, let me know and I'll be happy to put together a PR.



Discussion:
@hoffmanilya Thanks for reporting this issue. It'd be great if you could put a PR together to fix it by calling `Kernel.format` directly. Thanks! 👍 



Patch:
diff --git a/lib/mocha/inspect.rb b/lib/mocha/inspect.rb
old mode 100644
new mode 100755
index 7574fbd6e..478651ee4
--- a/lib/mocha/inspect.rb
+++ b/lib/mocha/inspect.rb
@@ -5,7 +5,7 @@ module ObjectMethods
     def mocha_inspect
       address = __id__ * 2
       address += 0x100000000 if address < 0
-      inspect =~ /#</ ? "#<#{self.class}:0x#{format('%x', address)}>" : inspect
+      inspect =~ /#</ ? "#<#{self.class}:0x#{Kernel.format('%x', address)}>" : inspect
     end
   end
 


Test patch:
diff --git a/test/unit/object_inspect_test.rb b/test/unit/object_inspect_test.rb
old mode 100644
new mode 100755
index c17c18446..faaf727a0
--- a/test/unit/object_inspect_test.rb
+++ b/test/unit/object_inspect_test.rb
@@ -45,4 +45,14 @@ def test_should_use_underscored_id_instead_of_object_id_or_id_so_that_they_can_b
 
     assert_equal [:__id__], calls.uniq
   end
+
+  def test_should_not_call_object_instance_format_method
+    object = Object.new
+    class << object
+      def format(*)
+        'internal_format'
+      end
+    end
+    assert_no_match(/internal_format/, object.mocha_inspect)
+  end
 end
Repository: fakefs/fakefs (Ruby)

Issue:
File.readlink does not raise ENOENT on non-existent file
The following code should raise `ENOENT` instead of `NoMethodError: Undefined method 'target' for nil`.
```
File.readlink('does_not_exist')
```



Discussion:

3.0.4





Patch:
diff --git a/lib/fakefs/file.rb b/lib/fakefs/file.rb
index 88a1ca6..c86ab60 100644
--- a/lib/fakefs/file.rb
+++ b/lib/fakefs/file.rb
@@ -187,6 +187,7 @@ def self.dirname(*args)
 
     def self.readlink(path)
       symlink = FileSystem.find(path)
+      raise Errno::ENOENT unless symlink
       symlink.target
     end
 


Test patch:
diff --git a/test/fakefs_test.rb b/test/fakefs_test.rb
index f0b2bac..895a81e 100644
--- a/test/fakefs_test.rb
+++ b/test/fakefs_test.rb
@@ -3392,6 +3392,12 @@ def test_rename_non_existing_file_to_itself_raises_error
     assert !File.exist?('/foo')
   end
 
+  def test_readlink_non_existent_raises_ENOENT
+    assert_raises(Errno::ENOENT) do
+      File.readlink('does_not_exist')
+    end
+  end
+
   def test_rename_renames_a_directories
     Dir.mkdir('/foo')
     File.write '/foo/file', 'content'
Repository: ruby/debug (Ruby)

Issue:
Unexpectedly stepping into prelude methods like `binding.irb`
**Your environment**

* `ruby -v`: `1.7.0`
* `rdbg -v`: `3.1.2`

**Describe the bug**

`step` command can step into Ruby's prelude methods, like `binding.irb`.

```
rdbg -e 's' test.rb
[1, 3] in test.rb
=>   1| binding.irb
     2|
     3| a = 1
=>#0    <main> at test.rb:1
(rdbg:commands) s
# No sourcefile available for <internal:prelude>
=>#0    Binding#irb at <internal:prelude>:19
  #1    <main> at test.rb:1
(rdbg)
```

But looking at the code, [it should be skipped by `skip_internal_path?`](https://github.com/ruby/debug/blob/83031643de9d0df176666edf56e75982e3f8831f/lib/debug/thread_client.rb#L31-L33).

**To Reproduce**

```rb
# test.rb
binding.irb

a = 1 # not important
```

```
$ rdbg -e 's' test.rb
```

**Expected behavior**

It shouldn't step into the prelude method but directly into IRB's internal.

**Additional context**

This is because [`skip_location?` appends `!eval:` to the frame path](https://github.com/ruby/debug/blob/master/lib/debug/thread_client.rb#L36), so `path.start_with?('<internal:')` failed to match it.



Discussion:

Patch:
diff --git a/lib/debug/thread_client.rb b/lib/debug/thread_client.rb
index bfb2c3ee4..cd79a3205 100644
--- a/lib/debug/thread_client.rb
+++ b/lib/debug/thread_client.rb
@@ -29,7 +29,7 @@ def skip_config_skip_path?(path)
     end
 
     def skip_internal_path?(path)
-      path.start_with?(__dir__) || path.start_with?('<internal:')
+      path.start_with?(__dir__) || path.delete_prefix('!eval:').start_with?('<internal:')
     end
 
     def skip_location?(loc)


Test patch:
diff --git a/test/console/control_flow_commands_test.rb b/test/console/control_flow_commands_test.rb
index dd46301b8..93b00f4e0 100644
--- a/test/console/control_flow_commands_test.rb
+++ b/test/console/control_flow_commands_test.rb
@@ -493,6 +493,20 @@ def test_unit_method_in_the_same_line
     end
   end
 
+  class SkipStepOnInternalCodeTest < ConsoleTestCase
+    def test_skip_step_on_internal_code
+      code = <<~RUBY
+      1| _a = 1.abs # step here and it should not step into Integer#abs's internal source
+      2| _b = _a.abs
+      RUBY
+      debug_code code do
+        type 's'
+        assert_line_num 2
+        type 'c'
+      end
+    end
+  end
+
   #
   # Tests that next/finish work for a deep call stack.
   # We use different logic for computing frame depth when the call stack is above/below 4096.
Repository: sinatra/sinatra (Ruby)

Issue:
`NoMethodError - undefined method '=~' for 1:Integer`
```ruby
# config.ru
require "sinatra/base"

class App < Sinatra::Base
  get "/" do
    uri(1)
  end
end

run App
```

```
arm64 $ bundle exec puma
Puma starting in single mode...
* Puma version: 6.1.0 (ruby 3.2.1-p31) ("The Way Up")
*  Min threads: 0
*  Max threads: 5
*  Environment: development
*          PID: 59431
* Listening on http://0.0.0.0:9292
Use Ctrl-C to stop
2023-02-26 19:10:10 - NoMethodError - undefined method `=~' for 1:Integer:
	/Users/dentarg/src/sinatra/sinatra/lib/sinatra/base.rb:320:in `uri'
	config.ru:5:in `block in <class:App>'
```

https://github.com/sinatra/sinatra/blob/50b8398dd7bcd5d5c187da51b23a939c5f3de210/lib/sinatra/base.rb#L317-L334


Discussion:
Before 3.2.0, a warning was printed (if you ran with warnings enabled)

```
arm64 $ RUBYOPT=-W bundle exec puma
Puma starting in single mode...
* Puma version: 6.1.0 (ruby 3.1.3-p185) ("The Way Up")
*  Min threads: 0
*  Max threads: 5
*  Environment: development
*          PID: 60791
* Listening on http://0.0.0.0:9292
Use Ctrl-C to stop
/Users/dentarg/src/sinatra/sinatra/lib/sinatra/base.rb:320: warning: deprecated Object#=~ is called on Integer; it always returns nil
```



Patch:
diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 9a2cd954c9..4982034b51 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -317,7 +317,7 @@ def redirect(uri, *args)
     # Generates the absolute URI for a given path in the app.
     # Takes Rack routers and reverse proxies into account.
     def uri(addr = nil, absolute = true, add_script_name = true)
-      return addr if addr =~ /\A[a-z][a-z0-9+.\-]*:/i
+      return addr if addr.to_s =~ /\A[a-z][a-z0-9+.\-]*:/i
 
       uri = [host = String.new]
       if absolute


Test patch:
diff --git a/test/helpers_test.rb b/test/helpers_test.rb
index 50ee677872..ee1298b213 100644
--- a/test/helpers_test.rb
+++ b/test/helpers_test.rb
@@ -1845,6 +1845,12 @@ def obj.is_a?(thing) 60.is_a?(thing) end
       assert_equal 'http://example.org/foo/bar', body
     end
 
+    it 'handles integer input' do
+      mock_app { get('/') { uri 123 }}
+      get '/'
+      assert_equal 'http://example.org/123', body
+    end
+
     it 'handles absolute URIs' do
       mock_app { get('/') { uri 'http://google.com' }}
       get '/'
Repository: ruby-git/ruby-git (Ruby)

Issue:
Open git repository from child directory of git repository
### Subject of the issue

I am looking to open a repository when not in the root directory of that repository. Using the `git` CLI I can call `git status` and other commands with no issue but `Git.open` fails.

How can we run `git rev-parse --show-toplevel` with this library? This works but kind of defeats the purpose of this gem:

```rb
Git.open(`git rev-parse --show-toplevel`.chomp)
```

### Your environment
* git version 2.34.1
* ruby-git 1.12.0
* ruby 3.1.2

### Steps to reproduce
Attempt to open git repository from child directory.

### Expected behaviour
Repository opens by looking up the directory tree to find the closest parent directory with a `.git` directory in it.

### Actual behaviour
```rb
Git.open(Dir.pwd)
# /paht/to/repo/projects/childdir/.git: path does not exist (ArgumentError)
```


Discussion:

Patch:
diff --git a/lib/git/base.rb b/lib/git/base.rb
index 8e77403a..2e4e153e 100644
--- a/lib/git/base.rb
+++ b/lib/git/base.rb
@@ -58,9 +58,26 @@ def self.init(directory = '.', options = {})
       self.new(options)
     end
 
+    def self.root_of_worktree(working_dir)
+      result = working_dir
+      status = nil
+      Dir.chdir(working_dir) do
+        git_cmd = "#{Git::Base.config.binary_path} -c core.quotePath=true -c color.ui=false rev-parse --show-toplevel 2>&1"
+        result = `#{git_cmd}`.chomp
+        status = $?
+      end
+      raise ArgumentError, "'#{working_dir}' is not in a git working tree" unless status.success?
+      result
+    end
+
     # (see Git.open)
     def self.open(working_dir, options = {})
+      raise ArgumentError, "'#{working_dir}' is not a directory" unless Dir.exist?(working_dir)
+
+      working_dir = root_of_worktree(working_dir) unless options[:repository]
+
       normalize_paths(options, default_working_directory: working_dir)
+
       self.new(options)
     end
 


Test patch:
diff --git a/tests/units/test_init.rb b/tests/units/test_init.rb
index 3fa23d0b..99a87593 100644
--- a/tests/units/test_init.rb
+++ b/tests/units/test_init.rb
@@ -13,6 +13,20 @@ def test_open_simple
     assert_match(/^C?:?#{File.join(@wdir, '.git', 'index')}$/, g.index.path)
   end
 
+  def test_open_from_non_root_dir
+    in_temp_dir do |path|
+      `git init`
+      File.write('file.txt', 'test')
+      `git add file.txt`
+      `git commit -m "initial commit "`
+      Dir.mkdir('subdir')
+      Dir.chdir('subdir') do
+        g = Git.open('.')
+        assert_equal(path, g.dir.to_s)
+      end
+    end
+  end
+
   def test_open_opts
     clone_working_repo
     index = File.join(TEST_FIXTURES, 'index')
Repository: ruby/rdoc (Ruby)

Issue:
"Document-method: []" is not handled correctly
_Also submitted under https://bugs.ruby-lang.org/issues/13275_

RDoc doesn't handle Document-method directives for #[] correctly. When multiple directives are given, "Document-method: []" shows up as a code block, at the beginning of the docs for the method of the directive before:

```
$ cat document-method-test.c 
/*
 * Document-method: foo
 * Document-method: []
 * Document-method: bar
 *
 * Does nothing.
 */
static VALUE
rb_my_method(void)
{

}

rb_cFoo = rb_define_class("Foo", rb_cObject);
rb_define_method(rb_cFoo, "foo", rb_my_method, 0);
rb_define_method(rb_cFoo, "bar", rb_my_method, 0);
rb_define_method(rb_cFoo, "[]", rb_my_method, 0);
```

The directive affects the docs for #foo:

```
$ rdoc --ri document-method-test.c -o mydoc
$ ri Foo.foo -d mydoc

Foo.foo

(from /.../.../mydoc)
------------------------------------------------------------------------------
  foo()

------------------------------------------------------------------------------

  Document-method: []

Does nothing.
```

When the order of the Document-method directives is changed, with Document-method: [] as the first one, everything is rendered correctly.

\[Real life example: https://docs.ruby-lang.org/en/2.3.0/Proc.html#method-i-call,
_in the meantime fixed with above workaround in r57767 and related backports_\]


Discussion:

Patch:
diff --git a/lib/rdoc/text.rb b/lib/rdoc/text.rb
index 7e714be0ad..def80d98a3 100644
--- a/lib/rdoc/text.rb
+++ b/lib/rdoc/text.rb
@@ -169,7 +169,7 @@ def strip_stars text
 
     encoding = text.encoding
 
-    text = text.gsub %r%Document-method:\s+[\w:.#=!?]+%, ''
+    text = text.gsub %r%Document-method:\s+[\w:.#=!?|^&<>~+-/*\%@`\[\]]+%, ''
 
     space = ' '
     space = RDoc::Encoding.change_encoding space, encoding if encoding


Test patch:
diff --git a/test/test_rdoc_text.rb b/test/test_rdoc_text.rb
index 9f0e9480d3..8b137c701f 100644
--- a/test/test_rdoc_text.rb
+++ b/test/test_rdoc_text.rb
@@ -377,6 +377,32 @@ def test_strip_stars_document_method
     assert_equal expected, strip_stars(text)
   end
 
+  def test_strip_stars_document_method_special
+    text = <<-TEXT
+/*
+ * Document-method: Zlib::GzipFile#mtime=
+ * Document-method: []
+ * Document-method: `
+ * Document-method: |
+ * Document-method: &
+ * Document-method: <=>
+ * Document-method: =~
+ * Document-method: +
+ * Document-method: -
+ * Document-method: +@
+ *
+ * A comment
+ */
+    TEXT
+
+    expected = <<-EXPECTED
+
+   A comment
+    EXPECTED
+
+    assert_equal expected, strip_stars(text)
+  end
+
   def test_strip_stars_encoding
     text = <<-TEXT
 /*