Skip to content

Commit 0ff36d1

Browse files
committed
feat: Enable cloning branches with --branch option. Closes #20 and closes #30
Previously, the branch was passed in with 'ref'. This was removed (tests removed)
1 parent dd64bb6 commit 0ff36d1

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

docs/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The location of the root `bpm` folder. Defaults to `"${XDG_DATA_HOME:-$HOME/.loc
88

99
### `BPM_FULL_CLONE`
1010

11-
Set to a non-null string to clone the full repository history instead of only the last commit. By default, only the latest commit is cloned (`--depth=1`)
11+
Set to a non-null string to clone the full repository history instead of only the last commit. By default, only the latest commit is cloned (`--depth=1`). The only exception to this is when a specific version is specified with `@v0.1.0` notation. When that is specified, the whole history is downloaded
1212

1313
### `BPM_PREFIX`
1414

pkg/lib/commands/do-add.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
do-add() {
44
local flag_ssh='no'
55
local flag_all='no'
6+
local flag_branch=
67

78
util.setup_mode
89

@@ -15,6 +16,13 @@ do-add() {
1516
--all)
1617
flag_all='yes'
1718
;;
19+
--branch=*)
20+
IFS='=' read -r discard flag_branch <<< "$arg"
21+
22+
if [ -z "$flag_branch" ]; then
23+
die "Branch cannot be empty"
24+
fi
25+
;;
1826
*)
1927
pkgs+=("$arg")
2028
;;
@@ -61,7 +69,7 @@ do-add() {
6169
fi
6270

6371
log.info "Adding '$repoSpec'"
64-
do-plumbing-clone "$uri" "$site/$package" "$ref"
72+
do-plumbing-clone "$uri" "$site/$package" "$ref" "$flag_branch"
6573
do-plumbing-add-deps "$site/$package"
6674
do-plumbing-link-bins "$site/$package"
6775
do-plumbing-link-completions "$site/$package"

pkg/lib/commands/do-plumbing-clone.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ do-plumbing-clone() {
44
local uri="$1"
55
local id="$2"
66
local ref="$3"
7+
local branch="$4"
78

89
ensure.non_zero 'uri' "$uri"
910
ensure.non_zero 'id' "$id"
1011

12+
# TODO this is invalid in the test suite
1113
if [ -e "$BPM_PACKAGES_PATH/$id" ]; then
1214
die "Package '$id' is already present"
1315
fi
1416

1517
local -a git_args=(--recursive)
1618

17-
if [ -z "${BPM_FULL_CLONE+x}" ]; then
19+
if [[ -z "${BPM_FULL_CLONE+x}" && -z "$ref" ]]; then
1820
git_args+=(--depth=1)
1921
fi
2022

21-
if [ -n "$ref" ]; then
22-
git_args+=(--branch "$ref")
23+
if [ -n "$branch" ]; then
24+
git_args+=(--single-branch --branch "$branch")
2325
fi
2426

2527
git_args+=("$uri")

tests/do-plumbing-clone.bats

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
load 'util/init.sh'
44

55
@test "install a specific version" {
6+
skip
7+
68
test_util.stub_command git
79

810
run do-plumbing-clone https://site/username/package.git username/package version
@@ -81,3 +83,12 @@ load 'util/init.sh'
8183
assert_success
8284
assert_line -n 1 "git clone --recursive --depth=1 git@site:username/package.git $BPM_PACKAGES_PATH/username/package"
8385
}
86+
87+
@test "setting branch works" {
88+
test_util.stub_command git
89+
90+
run do-plumbing-clone https://github.com/username/package.git github.com/username/package '' a_branch
91+
92+
assert_success
93+
assert_line -n 1 "git clone --recursive --depth=1 --single-branch --branch a_branch https://github.com/username/package.git $BPM_PACKAGES_PATH/github.com/username/package"
94+
}

0 commit comments

Comments
 (0)