ruby/rubygems · error · Bundler::InvalidOption

--#{options.key?(:branch) ? "branch" : "ref"} can only be us

Error message

--#{options.key?(:branch) ? "branch" : "ref"} can only be used with git sources

What it means

Error "--#{options.key?(:branch) ? "branch" : "ref"} can only be used with git sources" thrown in ruby/rubygems.

Source

Thrown at lib/bundler/plugin/installer.rb:57

          definition.remotely!
        else
          definition.with_cache!
        end

        specs = definition.specs

        install_from_specs(specs)
      end

      private

      def check_sources_consistency!(options)
        if (options.keys & [:source, :git, :path]).length > 1
          raise InvalidOption, "Only one of --source, --git, or --path may be specified"
        end

        if (options.key?(:branch) || options.key?(:ref)) && !options.key?(:git)
          raise InvalidOption, "--#{options.key?(:branch) ? "branch" : "ref"} can only be used with git sources"
        end

        if options.key?(:branch) && options.key?(:ref)
          raise InvalidOption, "--branch and --ref can't be both specified"
        end
      end

      def install_git(names, version, options)
        source_list = SourceList.new
        source = source_list.add_git_source({ "uri" => options[:git],
                                              "branch" => options[:branch],
                                              "ref" => options[:ref] })

        install_all_sources(names, version, source_list, source)
      end

      def install_path(names, version, path)
        source_list = SourceList.new

View on GitHub (pinned to 86cbb817a3)

When it happens

Trigger: Thrown at lib/bundler/plugin/installer.rb:57 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ruby/rubygems@86cbb817a3 (2026-08-23). Data as JSON: /api/errors/328b8fc95d52576a. Report an issue: GitHub.