Skip to content

Commit 0b4b1f2

Browse files
committed
Feature: accept pull request URLs as github source
Very often github source is used to temporarily use a modified gem while a PR upstream is being reviewed. So for instance ruby/bigdecimal#211 will look like: ```ruby gem "bigdecimal", github: "casperisfine/bigdecimal", branch: "git-gem" # ruby/bigdecimal#200 ``` It's annoying because you have to fiddle with the branch name, which is copied as `casperisfine:git-gem`, etc etc. If I could simply use the PR URL like this: ``` gem "bigdecimal", github: "ruby/bigdecimal#211" ``` It would make a very common task for me so much simpler.
1 parent a5a1c7f commit 0b4b1f2

28 files changed

+114
-28
lines changed

bundler/lib/bundler/dsl.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,17 @@ def add_git_sources
278278
warn_deprecated_git_source(:github, <<-'RUBY'.strip, 'Change any "reponame" :github sources to "username/reponame".')
279279
"https://github.com/#{repo_name}.git"
280280
RUBY
281-
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
282-
"https://github.com/#{repo_name}.git"
281+
if repo_name =~ %r{\Ahttps://github\.com/(\w+/\w+)/pull/(\d+)\z}
282+
{
283+
"git" => "https://github.com/#{$1}.git",
284+
"branch" => "refs/pull/#{$2}/head",
285+
"ref" => nil,
286+
"tag" => nil,
287+
}
288+
else
289+
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
290+
"https://github.com/#{repo_name}.git"
291+
end
283292
end
284293

285294
git_source(:gist) do |repo_name|
@@ -365,7 +374,11 @@ def normalize_options(name, version, opts)
365374

366375
git_name = (git_names & opts.keys).last
367376
if @git_sources[git_name]
368-
opts["git"] = @git_sources[git_name].call(opts[git_name])
377+
git_opts = @git_sources[git_name].call(opts[git_name])
378+
git_opts = { "git" => git_opts } if git_opts.is_a?(String)
379+
opts.merge!(git_opts) do |key, _gemfile_value, _git_source_value|
380+
raise GemfileError, %(The :#{key} option can't be used with `#{git_name}: #{opts[git_name].inspect}`)
381+
end
369382
end
370383

371384
%w[git path].each do |type|

bundler/lib/bundler/man/bundle-add.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "BUNDLE\-ADD" "1" "November 2021" "" ""
4+
.TH "BUNDLE\-ADD" "1" "December 2021" "" ""
55
.
66
.SH "NAME"
77
\fBbundle\-add\fR \- Add gem to the Gemfile and run bundle install

bundler/lib/bundler/man/bundle-binstubs.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "BUNDLE\-BINSTUBS" "1" "November 2021" "" ""
4+
.TH "BUNDLE\-BINSTUBS" "1" "December 2021" "" ""
55
.
66
.SH "NAME"
77
\fBbundle\-binstubs\fR \- Install the binstubs of the listed gems

bundler/lib/bundler/man/bundle-cache.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "BUNDLE\-CACHE" "1" "November 2021" "" ""
4+
.TH "BUNDLE\-CACHE" "1" "December 2021" "" ""
55
.
66
.SH "NAME"
77
\fBbundle\-cache\fR \- Package your needed \fB\.gem\fR files into your application

bundler/lib/bundler/man/bundle-check.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "BUNDLE\-CHECK" "1" "November 2021" "" ""
4+
.TH "BUNDLE\-CHECK" "1" "December 2021" "" ""
55
.
66
.SH "NAME"
77
\fBbundle\-check\fR \- Verifies if dependencies are satisfied by installed gems

bundler/lib/bundler/man/bundle-clean.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "BUNDLE\-CLEAN" "1" "November 2021" "" ""
4+
.TH "BUNDLE\-CLEAN" "1" "December 2021" "" ""
55
.
66
.SH "NAME"
77
\fBbundle\-clean\fR \- Cleans up unused gems in your bundler directory

bundler/lib/bundler/man/bundle-config.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "BUNDLE\-CONFIG" "1" "November 2021" "" ""
4+
.TH "BUNDLE\-CONFIG" "1" "December 2021" "" ""
55
.
66
.SH "NAME"
77
\fBbundle\-config\fR \- Set bundler configuration options

bundler/lib/bundler/man/bundle-doctor.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "BUNDLE\-DOCTOR" "1" "November 2021" "" ""
4+
.TH "BUNDLE\-DOCTOR" "1" "December 2021" "" ""
55
.
66
.SH "NAME"
77
\fBbundle\-doctor\fR \- Checks the bundle for common problems

bundler/lib/bundler/man/bundle-exec.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "BUNDLE\-EXEC" "1" "November 2021" "" ""
4+
.TH "BUNDLE\-EXEC" "1" "December 2021" "" ""
55
.
66
.SH "NAME"
77
\fBbundle\-exec\fR \- Execute a command in the context of the bundle

bundler/lib/bundler/man/bundle-gem.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.\" generated with Ronn/v0.7.3
22
.\" http://github.com/rtomayko/ronn/tree/0.7.3
33
.
4-
.TH "BUNDLE\-GEM" "1" "November 2021" "" ""
4+
.TH "BUNDLE\-GEM" "1" "December 2021" "" ""
55
.
66
.SH "NAME"
77
\fBbundle\-gem\fR \- Generate a project skeleton for creating a rubygem

0 commit comments

Comments
 (0)