{"record":{"id":"348d8816301b3417","repo":"ruby/rubygems","slug":"you-cannot-specify-branch-unless-git-or","errorCode":null,"errorMessage":"You cannot specify `--branch` unless `--git` or `--github` is specified.","messagePattern":"You cannot specify `--branch` unless `--git` or `--github` is specified\\.","errorType":"validation","errorClass":"InvalidOption","httpStatus":null,"severity":"error","filePath":"lib/bundler/cli/add.rb","lineNumber":45,"sourceCode":"    def perform_bundle_install\n      Installer.install(Bundler.root, Bundler.definition)\n      Bundler.load.cache if Bundler.app_cache.exist?\n    end\n\n    def inject_dependencies\n      dependencies = gems.map {|g| Bundler::Dependency.new(g, version, options) }\n\n      Injector.inject(dependencies,\n        conservative_versioning: options[:version].nil?, # Perform conservative versioning only when version is not specified\n        pessimistic: options[:pessimistic],\n        strict: options[:strict])\n    end\n\n    def validate_options!\n      raise InvalidOption, \"You cannot specify `--git` and `--github` at the same time.\" if options[\"git\"] && options[\"github\"]\n\n      unless options[\"git\"] || options[\"github\"]\n        raise InvalidOption, \"You cannot specify `--branch` unless `--git` or `--github` is specified.\" if options[\"branch\"]\n\n        raise InvalidOption, \"You cannot specify `--ref` unless `--git` or `--github` is specified.\" if options[\"ref\"]\n      end\n\n      raise InvalidOption, \"You cannot specify `--branch` and `--ref` at the same time.\" if options[\"branch\"] && options[\"ref\"]\n\n      raise InvalidOption, \"You cannot specify `--strict` and `--pessimistic` at the same time.\" if options[:strict] && options[:pessimistic]\n\n      # raise error when no gems are specified\n      raise InvalidOption, \"Please specify gems to add.\" if gems.empty?\n\n      version.to_a.each do |v|\n        raise InvalidOption, \"Invalid gem requirement pattern '#{v}'\" unless Gem::Requirement::PATTERN.match?(v.to_s)\n      end\n    end\n  end\nend\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/ruby/rubygems/blob/86cbb817a38ce8477b181c17467a703ded3f2be8/lib/bundler/cli/add.rb#L27-L63","documentation":"Error \"You cannot specify `--branch` unless `--git` or `--github` is specified.\" thrown in ruby/rubygems.","triggerScenarios":"Thrown at lib/bundler/cli/add.rb:45 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"86cbb817a38ce8477b181c17467a703ded3f2be8","analyzedAt":"2026-08-23T06:27:48.159Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}