git @ Cat's Eye Technologies shelf / 0.2
Merge pull request #1 from catseye/develop-0.2 Release version 0.2 Chris Pressey authored 4 years ago GitHub committed 4 years ago
2 changed file(s) with 301 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
00 shelf
11 =====
22
3 *Version 0.1. Subject to change in backwards-incompatible ways.*
3 *Version 0.2. Subject to change in backwards-incompatible ways.*
44
55 Cat's Eye Technologies' **shelf** is "a package installer which
66 neither packages nor installs". It aims to be a replacement for
5252
5353 Remove, from all link farms, any links that are broken.
5454
55 * `shelf_build` *DIR*
55 * `shelf_build` *DIR* [*DIR* ...]
5656
5757 Make a best-effort guess at how to build the sources in *DIR*, and try to
58 build them using that method.
58 build them using that method. One or more *DIR*s may be given.
59
60 * `shelf_test` *DIR* [*DIR* ...]
61
62 Make a best-effort guess at how to run tests for the project in *DIR*, then
63 run the tests using that method. One or more *DIR*s may be given.
5964
6065 * `shelf_pwd` *NAME*
6166
7277 Essentially the same as `which` but, if the found file is a symbolic link,
7378 display the filename that the link points to as well.
7479
80 * `shelf_dockgh` *USER/PROJECT*
81
82 Convenience command which, given the user (or organization) and repository
83 name of a repository on Github, clones that repository using `git`, then
84 runs `shelf_build` and `shelf_link` on the clone's directory. This makes
85 the most sense if the current directory is on the `SHELF_PATH`, but no
86 check is made.
87
88 * `shelf_push` *DEST* *DIR* [*DIR* ...]
89
90 Pushes changes from the project in *DIR* to the project of the same basename
91 in *DEST*. Currently only supports git repos. Always pushes the changes to
92 a branch in *DEST* whose name is the name of the current branch in *DIR; if
93 there is no such branch configured in *DEST*, an error occurs. *DEST* should
94 be a directory on the `SHELF_PATH`.
95
96 * `shelf_fanout` *DIR*
97
98 Executes a `shelf_push` to every directory on the `SHELF_PATH` that contains
99 a project directory that has the same basename as *DIR*.
100
101 ### Catalog files
102
103 In the context of shelf, a _catalog file_ is a text file with one entry per line.
104 Each entry consists of a directory name, optionally followed by an `@` symbol
105 followed by a tag name.
106
107 Several commands operate on catalog files, which are usually supplied via
108 standard input. Some of these commands ignore the tag names.
109
110 * `shelf_populate_from_distfiles` *DIR* < *CATALOG*
111
112 Given a directory *DIR* containing tarballs of the project listed in
113 *CATALOG*, extract each of those tarballs to a directory of the same
114 name in the current directory (assumed to be on `SHELF_PATH`.)
115
116 * `shelf_populate_from_git` *PREFIX* < *CATALOG*
117
118 For each of the projects listed in *CATALOG*, prefix *PREFIX* to its
119 name and attempt to clone that named object with `git` to a repository
120 directory in the current directory (assumed to be on `SHELF_PATH`.)
121
122 * `shelf_cast` *DIR* < *CATALOG*
123
124 When executed from a directory containing repositories listed in *CATALOG*,
125 create a non-version-controlled directory in *DIR* from each of the listed
126 repositories.
127
128 * `shelf_pin` < *CATALOG*
129
130 When executed from a directory containing repositories listed in *CATALOG*,
131 checks out each repository named in the catalog at the tag or branch given
132 by its tag name.
133
134 * `shelf_unpin` < *CATALOG*
135
136 When executed from a directory containing repositories listed in *CATALOG*,
137 checks out each repository named in the catalog at the tip of its `master`
138 branch.
139
75140 ### Environment variables
76141
77142 * `SHELF_VERBOSE`
166166 done
167167 }
168168
169 shelf_build() {
170 cwd=`pwd`
171
172 dir=`_shelf_abspath_dir "$1"`
173 cd $dir
174
169 _shelf_build() {
170 # argument must be absolute path of current directory
171 dir=$1
172 pwd
175173 # if build command is defined for this, then run it, else
176174 if [ -x "build.sh" ]; then
177175 ./build.sh
192190 else
193191 echo "No heuristic to build this source"
194192 fi
195
196 result=$?
197
198 cd $cwd
199 return $result
193 }
194
195 shelf_build() {
196 if [ "X$1" = X ]; then
197 echo "Usage: shelf_build {dir}"
198 return 1
199 fi
200
201 failures=""
202
203 for dir in $*; do
204 project=$dir
205 dir=`_shelf_abspath_dir "$dir"`
206 (cd $dir && _shelf_build $dir)
207 if [ $? -ne 0 ]; then
208 failures="$failures $project"
209 fi
210 done
211
212 if [ "X$failures" = X ]; then
213 return 0
214 else
215 echo "Failures: $failures"
216 return 1
217 fi
218 }
219
220 _shelf_test() {
221 pwd
222 # if test command is defined for this, then run it, else
223 if [ -x "test.sh" ]; then
224 ./test.sh
225 else
226 echo "No test found for this source"
227 fi
228 }
229
230 shelf_test() {
231 if [ "X$1" = X ]; then
232 echo "Usage: shelf_test {dir}"
233 return 1
234 fi
235
236 failures=""
237
238 for dir in $*; do
239 project=$dir
240 dir=`_shelf_abspath_dir "$dir"`
241 (cd $dir && _shelf_test)
242 if [ $? -ne 0 ]; then
243 failures="$failures $project"
244 fi
245 done
246
247 if [ "X$failures" = X ]; then
248 return 0
249 else
250 echo "Failures: $failures"
251 return 1
252 fi
253 }
254
255 _shelf_push() {
256 src=$1
257 dest=$2
258 if [ "$src" = "$dest" ]; then
259 echo "'$dest' is same as source directory"
260 return 0
261 fi
262 if [ ! -d "$dest/.git" ]; then
263 echo "'$dest' is not a git repository"
264 return 1
265 fi
266 branch=`(cd $src && git symbolic-ref --short HEAD)`
267 if [ "X$branch" = X ]; then
268 echo "Couldn't determine branch"
269 return 1
270 fi
271 (cd $dest && git checkout $branch && git pull $src $branch)
272 }
273
274 shelf_push() {
275 if [ "X$1" = X ]; then
276 echo "Usage: shelf_push dest_shelf {dir}"
277 return 1
278 fi
279
280 dest_shelf=$1
281 shift
282
283 if [ "X$1" = X ]; then
284 echo "Usage: shelf_push dest_shelf {dir}"
285 return 1
286 fi
287
288 failures=""
289
290 for dir in $*; do
291 dir=`_shelf_abspath_dir "$dir"`
292 base=`basename "$dir"`
293
294 _shelf_push $dir "$dest_shelf/$base"
295
296 if [ $? -ne 0 ]; then
297 failures="$failures $base"
298 fi
299 done
300
301 if [ "X$failures" = X ]; then
302 return 0
303 else
304 echo "Failures: $failures"
305 return 1
306 fi
307 }
308
309 shelf_fanout() {
310 path=`echo "$SHELF_PATH" | sed -e 's/:/ /g'`
311
312 project=$1
313 dir=`_shelf_abspath_dir "$dir"`
314 base=`basename "$dir"`
315
316 for shelf in $path; do
317 if [ "$dir" = "$shelf/$base" ]; then
318 continue
319 fi
320 if [ -d "$shelf/$base" ]; then
321 echo "--> $shelf/$base"
322 _shelf_push $dir "$shelf/$base"
323 fi
324 done
200325 }
201326
202327 shelf_pwd() {
233358 echo "$w"
234359 fi
235360 }
361
362 shelf_populate_from_distfiles() {
363 # ... taken from The-Platform ...
364
365 src_dir="$1"
366 while read -r line; do
367 project=`echo $line | awk '{split($0,a,"@"); print a[1]}'`
368 tag=`echo $line | awk '{split($0,a,"@"); print a[2]}'`
369 if [ -e "$src_dir/$project.tar.gz" ]; then
370 tar zxvf $src_dir/$project.tar.gz
371 elif [ -e "$src_dir/$project.tgz" ]; then
372 tar zxvf $src_dir/$project.tgz
373 fi
374 #shelf_build $project
375 #shelf_link $project
376 done
377 }
378
379 shelf_populate_from_git() {
380 git_prefix="$1"
381 while read -r line; do
382 project=`echo $line | awk '{split($0,a,"@"); print a[1]}'`
383 tag=`echo $line | awk '{split($0,a,"@"); print a[2]}'`
384
385 # ... taken from Funicular ...
386
387 url="$git_prefix$project"
388 dest=`basename $url`
389
390 if [ ! -d $dest ]; then
391 git clone $url $dest
392 fi
393
394 branch=`cd $dest && git rev-parse --abbrev-ref HEAD`
395 if [ "X$branch" != "XHEAD" ]; then
396 (cd $dest && git pull)
397 fi
398
399 if [ "X$tag" != X ]; then
400 (cd $dest && git checkout $tag)
401 fi
402
403 #shelf_build $project
404 #shelf_link $project
405 done
406 }
407
408 shelf_cast() {
409 projection_dir=`_shelf_abspath_dir "$1"`
410
411 while read -r line; do
412 project=`echo $line | awk '{split($0,a,"@"); print a[1]}'`
413 tag=`echo $line | awk '{split($0,a,"@"); print a[2]}'`
414
415 dest_project=$project
416 if [ "X$SHELF_LOWERCASE" != X ]; then
417 dest_project=`echo $dest_project | tr '[:upper:]' '[:lower:]'`
418 fi
419
420 rm -rf "$projection_dir/$dest_project"
421 (cd $project && git archive --format=tar --prefix=$dest_project/ HEAD | (cd $projection_dir && tar xf -) )
422 done
423 }
424
425 shelf_pin() {
426 while read -r line; do
427 project=`echo $line | awk '{split($0,a,"@"); print a[1]}'`
428 tag=`echo $line | awk '{split($0,a,"@"); print a[2]}'`
429
430 dest="$project"
431 if [ -d $dest ]; then
432 if [ "X$tag" != X ]; then
433 (cd $dest && git checkout $tag)
434 fi
435 fi
436 done
437 }
438
439 shelf_unpin() {
440 while read -r line; do
441 project=`echo $line | awk '{split($0,a,"@"); print a[1]}'`
442 tag=`echo $line | awk '{split($0,a,"@"); print a[2]}'`
443
444 dest="$project"
445 if [ -d $dest ]; then
446 (cd $dest && git checkout master)
447 fi
448 done
449 }
450
451 shelf_dockgh() {
452 url="https://github.com/$1.git"
453 git clone $url
454 project=`basename $1`
455 shelf_build $project || return 1
456 shelf_link $project || return 1
457 }