Browse Source

assign a <name> to each dependency

pull/3/head
Brett Langdon 10 years ago
parent
commit
fea0201205
4 changed files with 169 additions and 77 deletions
  1. +55
    -28
      bin/git-vendor
  2. +52
    -17
      man/git-vendor.1
  3. +33
    -17
      man/git-vendor.html
  4. +29
    -15
      man/git-vendor.md

+ 55
- 28
bin/git-vendor View File

@ -9,9 +9,9 @@ _usage()
cat <<EOF cat <<EOF
Usage: Usage:
git vendor --help git vendor --help
git vendor add <repository> <ref>
git vendor list
git vendor update <repository> <ref>
git vendor add [--prefix <dir>] <name> <repository> [<ref>]
git vendor list [<name>]
git vendor update <name> [<ref>]
EOF EOF
} }
@ -30,18 +30,25 @@ case "$command" in
*) >&2 echo "error: unknown command \"$command\"" && _usage && exit 1 ;; *) >&2 echo "error: unknown command \"$command\"" && _usage && exit 1 ;;
esac esac
vendor_dirs_from_log()
prefix="vendor"
if [ "$1" == "--prefix" ]; then
prefix="$2"
shift; shift
fi
vendor_names_from_log()
{ {
dir=
git log --grep="^git-vendor-dir: vendor/.*\$" \
name=
git log --grep="^git-vendor-name: .*\$" \
--pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD | --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD |
while read a b junk; do while read a b junk; do
case "$a" in case "$a" in
START) ;; START) ;;
git-vendor-dir:) dir="$b" ;;
git-vendor-name:) name="$b" ;;
END) END)
echo "$dir"
dir=
echo "$name"
name=
;; ;;
esac esac
done done
@ -49,47 +56,59 @@ vendor_dirs_from_log()
cmd_add() cmd_add()
{ {
repository="$1"
ref="$2"
if [ $# -ne 2 ];
name="$1"
repository="$2"
ref="master"
if [ "$3" != "" ]; then
ref="$3"
fi
if [ $# -lt 2 ];
then then
die "Incorrect options provided: git vendor add <repository> <ref>"
die "Incorrect options provided: git vendor add <name> <repository> [<ref>]"
fi fi
dir="vendor/$(echo "$repository" | sed -E 's/^[a-zA-Z]+((:\/\/)|@)//' | sed 's/:/\//' | sed -E 's/\.git$//')"
dir="$prefix/$(echo "$repository" | sed -E 's/^[a-zA-Z]+((:\/\/)|@)//' | sed 's/:/\//' | sed -E 's/\.git$//')"
message="\ message="\
Add '$dir/' from '$repository $ref'
Add \"$name\" from \"$repository@$ref\"
git-vendor-name: $name
git-vendor-dir: $dir git-vendor-dir: $dir
git-vendor-repository: $repository git-vendor-repository: $repository
git-vendor-ref: $ref git-vendor-ref: $ref
" "
set -x
git subtree add --prefix "$dir" --message "$message" "$repository" "$ref" --squash git subtree add --prefix "$dir" --message "$message" "$repository" "$ref" --squash
} }
cmd_list() cmd_list()
{ {
vendorDirs=($(vendor_dirs_from_log | sort -u))
for dir in "${vendorDirs[@]}";
showOnly="$1"
vendorNames=($(vendor_names_from_log | sort -u))
for name in "${vendorNames[@]}";
do do
git log -1 --grep="^git-vendor-dir: $dir\$" \
git log -1 --grep="^git-vendor-name: $name\$" \
--pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD | --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD |
while read a b junk; do while read a b junk; do
case "$a" in case "$a" in
START) commit="$b" ;; START) commit="$b" ;;
git-vendor-name:) name="$b" ;;
git-vendor-dir:) dir="$b" ;; git-vendor-dir:) dir="$b" ;;
git-vendor-ref:) ref="$b" ;; git-vendor-ref:) ref="$b" ;;
git-vendor-repository:) repository="$b" ;; git-vendor-repository:) repository="$b" ;;
END) END)
if [[ ! -z "$repository" ]]; if [[ ! -z "$repository" ]];
then then
echo "$dir"
echo "\tcommit:\t$commit"
echo "\tdir:\t$dir"
echo "\tref:\t$ref"
echo "\trepo:\t$repository"
echo ""
if [[ -z "$showOnly" ]] || [ "$showOnly" == "$name" ]; then
echo "$name@$ref:"
echo "\tname:\t$name"
echo "\tdir:\t$dir"
echo "\trepo:\t$repository"
echo "\tref:\t$ref"
echo "\tcommit:\t$commit"
echo ""
fi
fi fi
name=
dir= dir=
ref= ref=
commit= commit=
@ -103,20 +122,28 @@ cmd_list()
cmd_update() cmd_update()
{ {
dir="$1"
ref="$2"
git log --grep="^git-vendor-dir: $dir\$" \
name="$1"
ref="master"
if [ "$2" != "" ]; then
ref="$2"
fi
if [ $# -lt 1]; then
die "Incorrect options provided: git vendor upate <name> [<ref>]"
fi
git log -1 --grep="^git-vendor-name: $name\$" \
--pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD | --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD |
while read a b junk; do while read a b junk; do
case "$a" in case "$a" in
START) ;; START) ;;
git-vendor-dir:) dir="$b" ;;
git-vendor-repository:) repository="$b" ;; git-vendor-repository:) repository="$b" ;;
END) END)
if [[ ! -z "$repository" ]]; if [[ ! -z "$repository" ]];
then then
message="\ message="\
Update '$dir/' from '$repository $ref'
Update \"$name\" from \"$repository@$ref\"
git-vendor-name: $name
git-vendor-dir: $dir git-vendor-dir: $dir
git-vendor-repository: $repository git-vendor-repository: $repository
git-vendor-ref: $ref git-vendor-ref: $ref


+ 52
- 17
man/git-vendor.1 View File

@ -1,37 +1,40 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "GIT\-VENDOR" "1" "January 2016" "" ""
.TH "GIT\-VENDOR" "1" "January 2016" "" "Git Vendor"
. .
.SH "NAME" .SH "NAME"
\fBgit\-vendor\fR \- manage vendored dependency subtrees \fBgit\-vendor\fR \- manage vendored dependency subtrees
. .
.SH "SYNOPSIS" .SH "SYNOPSIS"
\fBgit\-vendor add <repository> <ref>\fR
\fBgit\-vendor add [\-\-prefix <dir>] <name> <repository> [<ref>]\fR
. .
.P .P
\fBgit\-vendor list\fR
\fBgit\-vendor list [<name>]\fR
. .
.P .P
\fBgit\-vendor update <dir> <ref>\fR
\fBgit\-vendor update <name> [<ref>]\fR
. .
.SH "DESCRIPTION" .SH "DESCRIPTION"
Manage any repository dependencies under \fB/vendor/<repository>\fR with \fBgit\-subtree\fR\.
Manage any repository dependencies with \fBgit\-subtree\fR\.
.
.P
\fBgit\-vendor\fR follows the same vendoring pattern that is used in the Go community\. Dependencies are stored under \fBvendor/<repository_uri>\fR\. For example, the dependency of \fBhttps://github\.com/brettlangdon/forge\.git\fR will be stored under \fBvendor/github\.com/brettlangdon/forge\fR by default\.
. .
.P .P
\fBgit\-vendor\fR is unable to \fBlist\fR or \fBupdate\fR any dependencies it has not added, the reason is that \fBgit\-vendor\fR adds special commit messages so that it can track existing dependencies\. \fBgit\-vendor\fR is unable to \fBlist\fR or \fBupdate\fR any dependencies it has not added, the reason is that \fBgit\-vendor\fR adds special commit messages so that it can track existing dependencies\.
. .
.SH "COMMANDS" .SH "COMMANDS"
add <repository> <ref>
add [\-\-prefix <dir>] <name> <repository> [<ref>]
. .
.P .P
Add a new vendored dependency Add a new vendored dependency
. .
.P .P
list
list [\fIname\fR]
. .
.P .P
List all existing vendored dependencies and their current version
List all existing vendored dependencies and their current version\. Limit show dependency to \fB<name>\fR if provided\.
. .
.P .P
update <dir> <ref> update <dir> <ref>
@ -40,6 +43,18 @@ update <dir> <ref>
Update the vendored dependency to a different version Update the vendored dependency to a different version
. .
.SH "OPTIONS" .SH "OPTIONS"
\-\-prefix <dir>
.
.P
Directory to pull dependencies in under (e\.g\. \fBvendor\fR or \fBthird_party\fR, etc)\. [default: \fBvendor\fR]
.
.P
<name>
.
.P
A name to provide the vendored dependency to use when listing/updating\.
.
.P
<repository> <repository>
. .
.P .P
@ -49,35 +64,55 @@ The repository url to vendor\. e\.g\. \fBhttps://github\.com/<username>/<repo\-n
<ref> <ref>
. .
.P .P
The ref to vendor\. e\.g\. \fBmaster\fR, \fBv1\.0\.2\fR, etc
The ref to vendor\. e\.g\. \fBmaster\fR, \fBv1\.0\.2\fR, etc\. [default: \fBmaster\fR]
. .
.P
<dir>
.SH "EXAMPLES"
Adding a new dependency at a specific git tagged version:
.
.IP "" 4
.
.nf
$ git vendor add forge https://github\.com/brettlangdon/forge v0\.1\.4
.
.fi
.
.IP "" 0
. .
.P .P
The vendor directory for the dependency\. e\.g\. \fBvendor/github\.com/<username>/<repo\-name>\fR\.
Adding a new dependency under a different directory than \fBvendor/\fR:
. .
.SH "EXAMPLES"
Adding a new dependency:
.IP "" 4
.
.nf
$ git vendor add \-\-prefix third_party forge https://github\.com/brettlangdon/forge
.
.fi
.
.IP "" 0
.
.P
Updating an existing dependency to a specific git tagged version:
. .
.IP "" 4 .IP "" 4
. .
.nf .nf
$ git vendor add https://github\.com/brettlangdon/forge v0\.1\.4
$ git vendor update forge v0\.1\.7
. .
.fi .fi
. .
.IP "" 0 .IP "" 0
. .
.P .P
Updating an existing dependency:
Updating a dependency to \fBmaster\fR:
. .
.IP "" 4 .IP "" 4
. .
.nf .nf
$ git vendor update vendor/github\.com/brettlangdon/forge v0\.1\.7
$ git vendor update forge
. .
.fi .fi
. .


man/git-vendor.1.html → man/git-vendor.html View File


+ 29
- 15
man/git-vendor.md View File

@ -3,27 +3,29 @@ git-vendor(1) -- manage vendored dependency subtrees
## SYNOPSIS ## SYNOPSIS
`git-vendor add <repository> <ref>`
`git-vendor add [--prefix <dir>] <name> <repository> [<ref>]`
`git-vendor list`
`git-vendor list [<name>]`
`git-vendor update <dir> <ref>`
`git-vendor update <name> [<ref>]`
## DESCRIPTION ## DESCRIPTION
Manage any repository dependencies under `/vendor/<repository>` with `git-subtree`.
Manage any repository dependencies with `git-subtree`.
`git-vendor` follows the same vendoring pattern that is used in the Go community. Dependencies are stored under `vendor/<repository_uri>`. For example, the dependency of `https://github.com/brettlangdon/forge.git` will be stored under `vendor/github.com/brettlangdon/forge` by default.
`git-vendor` is unable to `list` or `update` any dependencies it has not added, the reason is that `git-vendor` adds special commit messages so that it can track existing dependencies. `git-vendor` is unable to `list` or `update` any dependencies it has not added, the reason is that `git-vendor` adds special commit messages so that it can track existing dependencies.
## COMMANDS ## COMMANDS
add &lt;repository&gt; &lt;ref&gt;
add [--prefix &lt;dir&gt;] &lt;name&gt; &lt;repository&gt; [&lt;ref&gt;]
Add a new vendored dependency Add a new vendored dependency
list
list [<name>]
List all existing vendored dependencies and their current version
List all existing vendored dependencies and their current version. Limit show dependency to `<name>` if provided.
update &lt;dir&gt; &lt;ref&gt; update &lt;dir&gt; &lt;ref&gt;
@ -32,27 +34,39 @@ git-vendor(1) -- manage vendored dependency subtrees
## OPTIONS ## OPTIONS
--prefix &lt;dir&gt;
Directory to pull dependencies in under (e.g. `vendor` or `third_party`, etc). [default: `vendor`]
&lt;name&gt;
A name to provide the vendored dependency to use when listing/updating.
&lt;repository&gt; &lt;repository&gt;
The repository url to vendor. e.g. `https://github.com/<username>/<repo-name>` (supports `http://`, `https://` `git://` and `git@` protocols). The repository url to vendor. e.g. `https://github.com/<username>/<repo-name>` (supports `http://`, `https://` `git://` and `git@` protocols).
&lt;ref&gt; &lt;ref&gt;
The ref to vendor. e.g. `master`, `v1.0.2`, etc
The ref to vendor. e.g. `master`, `v1.0.2`, etc. [default: `master`]
&lt;dir&gt;
## EXAMPLES
The vendor directory for the dependency. e.g. `vendor/github.com/<username>/<repo-name>`.
Adding a new dependency at a specific git tagged version:
## EXAMPLES
$ git vendor add forge https://github.com/brettlangdon/forge v0.1.4
Adding a new dependency under a different directory than `vendor/`:
$ git vendor add --prefix third_party forge https://github.com/brettlangdon/forge
Adding a new dependency:
Updating an existing dependency to a specific git tagged version:
$ git vendor add https://github.com/brettlangdon/forge v0.1.4
$ git vendor update forge v0.1.7
Updating an existing dependency:
Updating a dependency to `master`:
$ git vendor update vendor/github.com/brettlangdon/forge v0.1.7
$ git vendor update forge
List all existing dependencies: List all existing dependencies:


Loading…
Cancel
Save