Skip to content
New issue

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

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

Already on GitHub? # to your account

Port brew --repository to Bash #17726

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions Library/Homebrew/cmd/--repository.rb

This file was deleted.

44 changes: 44 additions & 0 deletions Library/Homebrew/cmd/--repository.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#: * `--repository`, `--repo` [<tap> ...]
#:
#: Display where Homebrew's Git repository is located.
#:
#: If <user>`/`<repo> are provided, display where tap <user>`/`<repo>'s directory is located.

# HOMEBREW_REPOSITORY, HOMEBREW_LIBRARY are set by brew.sh
# shellcheck disable=SC2154

tap_path() {
local tap="$1"
local user
local repo
local part

user="$(echo "${tap%%/*}" | tr '[:upper:]' '[:lower:]')"
repo="$(echo "${tap#*/}" | tr '[:upper:]' '[:lower:]')"

for part in "${user}" "${repo}"
do
if [[ -z "${part}" || "${part}" == *"/"* ]]
then
odie "Invalid tap name: ${tap}"
fi
done

repo="${repo#(home|linux)brew-}"
echo "${HOMEBREW_LIBRARY}/Taps/${user}/homebrew-${repo}"
}

homebrew---repository() {
local tap

if [[ "$#" -eq 0 ]]
then
echo "${HOMEBREW_REPOSITORY}"
return
fi

for tap in "$@"
do
tap_path "${tap}"
done
}
11 changes: 3 additions & 8 deletions Library/Homebrew/test/cmd/--repository_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# frozen_string_literal: true

require "cmd/--repository"
require "cmd/shared_examples/args_parse"

RSpec.describe Homebrew::Cmd::Repository do
it_behaves_like "parseable arguments"

RSpec.describe "brew --repository", type: :system do
it "prints Homebrew's repository", :integration_test do
expect { brew_sh "--repository" }
.to output("#{ENV.fetch("HOMEBREW_REPOSITORY")}\n").to_stdout
Expand All @@ -14,8 +9,8 @@
end

it "prints a Tap's repository", :integration_test do
expect { brew "--repository", "foo/bar" }
.to output("#{HOMEBREW_LIBRARY}/Taps/foo/homebrew-bar\n").to_stdout
expect { brew_sh "--repository", "foo/bar" }
.to output("#{ENV.fetch("HOMEBREW_LIBRARY")}/Taps/foo/homebrew-bar\n").to_stdout
.and not_to_output.to_stderr
.and be_a_success
end
Expand Down
Loading