Commit 8c3ad3c3 authored by Mislav Marohnić's avatar Mislav Marohnić
Browse files

Merge pull request #549 from yyuu/fix-fetch-git-with-keep

Fix `fetch_git` with `--keep`
parents 9b7679ad 07ef88d7
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -367,7 +367,14 @@ fetch_git() {
      popd >&4
    fi

    if [ -e "${package_name}" ]; then
      ( cd "${package_name}"
        git fetch --depth 1 origin "+${git_ref}"
        git checkout -q -B "$git_ref" "origin/${git_ref}"
      ) >&4 2>&1
    else
      git clone --depth 1 --branch "$git_ref" "$git_url" "${package_name}" >&4 2>&1
    fi
  else
    echo "error: please install \`git\` and try again" >&2
    exit 1
+38 −0
Original line number Diff line number Diff line
@@ -4,6 +4,11 @@ load test_helper
export RUBY_BUILD_SKIP_MIRROR=1
export RUBY_BUILD_CACHE_PATH=

setup() {
  export RUBY_BUILD_BUILD_PATH="${TMP}/source"
  mkdir -p "${RUBY_BUILD_BUILD_PATH}"
}

@test "failed download displays error message" {
  stub curl false

@@ -12,3 +17,36 @@ export RUBY_BUILD_CACHE_PATH=
  assert_output_contains "> http://example.com/packages/package-1.0.0.tar.gz"
  assert_output_contains "error: failed to download package-1.0.0.tar.gz"
}

@test "fetching from git repository" {
  stub git "clone --depth 1 --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
DEF
  assert_success
  assert_output <<OUT
Cloning http://example.com/packages/package.git...
Installing package-dev...
Installed package-dev to ${TMP}/install
OUT
  unstub git
}

@test "updating existing git repository" {
  mkdir -p "${RUBY_BUILD_BUILD_PATH}/package-dev"
  stub git \
    "fetch --depth 1 origin +master : true" \
    "checkout -q -B master origin/master : true"

  run_inline_definition <<DEF
install_git "package-dev" "http://example.com/packages/package.git" master copy
DEF
  assert_success
  assert_output <<OUT
Cloning http://example.com/packages/package.git...
Installing package-dev...
Installed package-dev to ${TMP}/install
OUT
  unstub git
}