Skip to content
This repository was archived by the owner on Apr 3, 2021. It is now read-only.

Commit 23e3070

Browse files
committed
[install] Allow installing from GitHub branch
1 parent a46997d commit 23e3070

File tree

2 files changed

+97
-19
lines changed

2 files changed

+97
-19
lines changed

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ $ podenv install --list
128128
...
129129
```
130130
131+
###### Installing Unreleased Versions
132+
133+
It's also possible to install directly from a branch found on the CocoaPods
134+
repository:
135+
136+
```shell
137+
$ podenv install --branch 0.39-stable
138+
```
139+
140+
The version inside podenv will be the branch name, for example `0.39-stable`.
141+
142+
You can explicitly use this version via the environ variable, for example:
143+
144+
```shell
145+
$ env POD_VERSION=0.39-stable pod
146+
```
147+
148+
**NOTE**: *You may also use `--repo` to install from a different GitHub
149+
remote.*
150+
131151
##### `uninstall`
132152

133153
Uninstalls a specific CocoaPods version.

libexec/podenv-install

+77-19
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,90 @@
22

33
set -e
44

5-
VERSION=$1
6-
if [ -z "$VERSION" ] ; then
7-
VERSION="$(podenv-version-name)"
8-
if [ "$VERSION" == "system" ]; then
9-
echo "Usage: podenv install <version>"
5+
check_version() {
6+
VERSION="$1"
7+
if ! curl -s https://rubygems.org/api/v1/versions/cocoapods.json | ruby -e "require 'json'; exit(JSON.parse(STDIN.read).find { |v| v['number'] == '$VERSION' }.nil? ? 1 : 0)" ; then
8+
echo "CocoaPods $VERSION does not exist."
109
exit 1
1110
fi
12-
fi
11+
}
1312

14-
if [ -d "$PODENV_ROOT/versions/$VERSION" ]; then
15-
echo "$VERSION is already installed."
16-
exit 1
17-
fi
13+
setup_environment() {
14+
VERSION="$1"
15+
DESTINATION="$PODENV_ROOT/versions/$VERSION"
16+
export GEM_HOME="$DESTINATION"
17+
}
18+
19+
install_version_gem() {
20+
VERSION="$1"
21+
gem install cocoapods -v "$VERSION" --no-document
22+
echo "$VERSION" > "$PODENV_ROOT/version"
23+
}
24+
25+
install_version_git_branch() {
26+
REPO="$1"
27+
BRANCH="$2"
1828

19-
if [ "$VERSION" == "--list" ]; then
29+
DESTINATION="$TMPDIR/podenv-$BRANCH"
30+
git clone --quiet --depth 1 --branch "$BRANCH" "$REPO" "$DESTINATION"
31+
32+
cd "$DESTINATION"
33+
gem install bundler --no-document
34+
bundle install
35+
rake install
36+
cd
37+
rm -fr "$DESTINATION"
38+
}
39+
40+
if [ "$1" == "--list" ]; then
2041
curl -s https://rubygems.org/api/v1/versions/cocoapods.json | ruby -e "require 'json'; JSON.parse(STDIN.read).each { |v| puts v['number'] }"
21-
exit 0
42+
exit
2243
fi
2344

24-
if ! curl -s https://rubygems.org/api/v1/versions/cocoapods.json | ruby -e "require 'json'; exit(JSON.parse(STDIN.read).find { |v| v['number'] == '$VERSION' }.nil? ? 1 : 0)" ; then
25-
echo "CocoaPods $VERSION does not exist."
26-
exit 1
45+
if [ -z "$TMPDIR" ]; then
46+
export TMPDIR="/tmp"
2747
fi
2848

29-
DESTINATION="$PODENV_ROOT/versions/$VERSION"
30-
export GEM_HOME="$DESTINATION"
31-
gem install cocoapods -v "$VERSION"
49+
REPO="https://github.com/CocoaPods/CocoaPods"
50+
BRANCH=""
51+
52+
while [[ $# > 1 ]]; do
53+
case "$1" in
54+
--repo)
55+
shift
56+
REPO="$1"
57+
;;
58+
--branch)
59+
shift
60+
BRANCH="$1"
61+
;;
62+
esac
63+
64+
shift
65+
done
3266

33-
echo "$VERSION" > "$PODENV_ROOT/version"
67+
if [ -z "$BRANCH" ]; then
68+
VERSION=$1
69+
70+
if [ -z "$VERSION" ] ; then
71+
VERSION="$(podenv-version-name)"
72+
if [ "$VERSION" == "system" ]; then
73+
echo "Usage: podenv install <version>"
74+
exit 1
75+
fi
76+
fi
77+
78+
if [ -d "$PODENV_ROOT/versions/$VERSION" ]; then
79+
echo "$VERSION is already installed."
80+
exit 1
81+
fi
82+
fi
83+
84+
if [ -z "$BRANCH" ]; then
85+
setup_environment "$VERSION"
86+
check_version "$VERSION"
87+
install_version_gem "$VERSION"
88+
else
89+
setup_environment "$BRANCH"
90+
install_version_git_branch "$REPO" "$BRANCH"
91+
fi

0 commit comments

Comments
 (0)