Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ The build process may be configured through the following environment variables:
| `RUBY_MAKE_INSTALL_OPTS` | Additional `make install` options (applies only to Ruby source). |
| `NO_COLOR` | Disable ANSI colors in output. The default is to use colors for output connected to a terminal. |
| `CLICOLOR_FORCE` | Use ANSI colors in output even when not connected to a terminal. |
| `RUBY_REPO` | The URL of the git repository to use when building `ruby-dev` |
| `RUBY_REF` | The git branch (or revision) to use when building `ruby-dev`, e.g. `some-branch@af12decf` |

#### Applying Patches

Expand Down
28 changes: 23 additions & 5 deletions bin/ruby-build
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,18 @@ fetch_git() {
local git_url="$2"
local git_ref="$3"

local git_branch=${git_ref}
local git_sha=''
if [[ "${git_ref}" = *@* ]]; then
git_branch="$(echo "${git_ref}" | cut -d@ -f 1)"
git_sha="$(echo "${git_ref}" | cut -d@ -f 2)"
fi

local depth_args=("--depth" "1")
if [[ -n "${git_sha}" ]]; then
depth_args=()
fi

log_info "Cloning ${git_url}..."

if ! type git &>/dev/null; then
Expand All @@ -582,18 +594,24 @@ fetch_git() {
local cache_dir
cache_dir="$RUBY_BUILD_CACHE_PATH/$(sanitize "$git_url")"
if [ -e "$cache_dir" ]; then
log_command git -C "$cache_dir" fetch --force "$git_url" "+${git_ref}:${git_ref}" 2>&3
log_command git -C "$cache_dir" fetch --force "$git_url" "+${git_branch}:${git_branch}" 2>&3
else
log_command git clone --bare --branch "$git_ref" "$git_url" "$cache_dir" 2>&3
log_command git clone --bare --single-branch --branch "$git_branch" "$git_url" "$cache_dir" 2>&3
fi
git_url="$cache_dir"
fi

if [ -e "$package_name" ]; then
log_command git -C "$package_name" fetch --depth 1 origin "+${git_ref}" 2>&3
log_command git -C "$package_name" checkout -q -B "$git_ref" "origin/${git_ref}" 2>&3
log_command git -C "$package_name" fetch "${depth_args[@]}" origin "+${git_ref}" 2>&3
if [ -z "${git_sha}" ]; then
log_command git -C "$package_name" checkout -q -B "$git_branch" "origin/${git_branch}" 2>&3
fi
else
log_command git clone --depth 1 --branch "$git_ref" "$git_url" "$package_name" 2>&3
log_command git clone "${depth_args[@]}" --single-branch --branch "$git_branch" "$git_url" "$package_name" 2>&3
fi

if [ -n "${git_sha}" ]; then
log_command git -C "$package_name" checkout -q "$git_sha" 2>&3
fi
}

Expand Down
2 changes: 1 addition & 1 deletion share/ruby-build/ruby-dev
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
install_package "openssl-3.5.4" "https://github.com/openssl/openssl/releases/download/openssl-3.5.4/openssl-3.5.4.tar.gz#967311f84955316969bdb1d8d4b983718ef42338639c621ec4c34fddef355e99" openssl --if needs_openssl:1.1.1-3.x.x
install_git "ruby-master" "https://github.com/ruby/ruby.git" "master" autoconf enable_shared standard_install_with_bundled_gems
install_git "ruby-master" "${RUBY_REPO:-https://github.com/ruby/ruby.git}" "${RUBY_REF:-master}" autoconf enable_shared standard_install_with_bundled_gems
29 changes: 28 additions & 1 deletion test/fetch.bats
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ setup() {
}

@test "fetching from git repository" {
stub git "clone --depth 1 --branch master http://example.com/packages/package.git package-dev : mkdir package-dev"
stub git "clone --depth 1 --single-branch --branch master http://example.com/packages/package.git package-dev : mkdir package-dev"

run_inline_definition <<DEF
install_git "package-dev" "http://example.com/packages/package.git" master copy
Expand All @@ -48,6 +48,19 @@ DEF
unstub git
}

@test "fetching from git repository at specific ref" {
stub git \
"clone --single-branch --branch my-branch http://example.com/packages/package.git package-dev : mkdir package-dev" \
"-C package-dev checkout -q deadbeef : true"

run_inline_definition <<DEF
install_git "package-dev" "http://example.com/packages/package.git" my-branch@deadbeef copy
DEF
assert_success
assert_output_contains "Cloning http://example.com/packages/package.git..."
unstub git
}

@test "updating existing git repository" {
mkdir -p "${RUBY_BUILD_BUILD_PATH}/package-dev"
stub git \
Expand All @@ -61,3 +74,17 @@ DEF
assert_output_contains "Cloning http://example.com/packages/package.git..."
unstub git
}

@test "updating existing git repository at specific ref" {
mkdir -p "${RUBY_BUILD_BUILD_PATH}/package-dev"
stub git \
"-C package-dev fetch origin +my-branch@deadbeef : true" \
"-C package-dev checkout -q deadbeef : true"

run_inline_definition <<DEF
install_git "package-dev" "http://example.com/packages/package.git" my-branch@deadbeef copy
DEF
assert_success
assert_output_contains "Cloning http://example.com/packages/package.git..."
unstub git
}