Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add push command #23

Merged
merged 4 commits into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ See https://brettlangdon.github.io/git-vendor for the current MAN page documenta
* `git vendor add [--prefix <dir>] <name> <repository> [<ref>]` - add a new vendored dependency.
* `git vendor list [<name>]` - list current vendored dependencies, their source, and current vendored ref.
* `git vendor update <name> [<ref>]` - update a vendored dependency.
* `git vendor upstream <name> [<ref>] [--repo <repository>]` - share with the upstream vendored dependency.

## Installation
Manually:
Expand Down
63 changes: 62 additions & 1 deletion bin/git-vendor
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Usage:
git vendor list [<name>]
git vendor remove <name>
git vendor update <name> [<ref>]
git vendor upstream <name> [<ref>] [--repo <repository>]
EOF
}

Expand All @@ -27,7 +28,7 @@ require_work_tree
command="$1"
shift
case "$command" in
"add"|"list"|"remove"|"update") ;;
"add"|"list"|"remove"|"update"|"upstream") ;;
*) >&2 echo "error: unknown command \"$command\"" && _usage && exit 1 ;;
esac

Expand Down Expand Up @@ -207,6 +208,66 @@ git-vendor-ref: $ref
done
}

cmd_upstream()
{
require_clean_work_tree
while [ $# -gt 0 ] ; do
case $1 in
--repo)
repository_arg="$2"
shift # argument value
;;
*)
if [ -z "$name" ]; then
name="$1"
elif [ -z "$ref" ]; then
ref="$1"
fi
;;
esac
shift # current argument
done
if [ -z "$name" ]; then
die "Incorrect options provided: git vendor upstream <name> [<ref>] [--repo <repository>]"
fi
if [ -z "$ref" ]; then
ref="master"
fi
vendor_git_log_from_name "$name" |
while read a b junk; do
case "$a" in
START) ;;
git-vendor-dir:) dir="$b" ;;
git-vendor-repository:) repository="$b" ;;
END)
# Make sure the dependency exists on disk
if [ ! -d "$dir" ]; then
die "Dependency \"$1\" is missing from \"$dir\""
fi

# And hasn't been renamed
logname=$(vendor_name_from_dir "$dir")
if [ "$name" != "$logname" ]; then
die "Dependency \"$1\" was renamed \"$logname\""
fi

if [ ! -z "$repository_arg" ];
then
# override the repository read from the commit logs
# with the one read from the command line arguments
repository="$repository_arg"
fi

if [ ! -z "$repository" ];
then
git subtree push --prefix "$dir" "$repository" "$ref"
break
fi
;;
esac
done
}

cmd_remove()
{
require_clean_work_tree
Expand Down
2 changes: 1 addition & 1 deletion etc/bash_completion.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_git_vendor()
{
__gitcomp "add list update"
__gitcomp "add list update upstream"
}
63 changes: 62 additions & 1 deletion man/git-vendor.1
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
.P
\fBgit\-vendor update <name> [<ref>]\fR
.
.P
\fBgit\-vendor upstream <name> [<ref>]\fR
.
.SH "DESCRIPTION"
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
\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, \fBupdate\fR or \fBupstream\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"
add [\-\-prefix <dir>] <name> <repository> [<ref>]
Expand All @@ -51,6 +54,12 @@ update <dir> <ref>
.P
Update the vendored dependency to a different version\.
.
.P
upstream <dir> <ref>
.
.P
Push the vendored dependency changes to the source repository\.
.
.SH "OPTIONS"
\-\-prefix <dir>
.
Expand Down Expand Up @@ -128,6 +137,58 @@ $ git vendor update forge
.IP "" 0
.
.P
Upstream changes to the source repository to a (new) branch \fBmy_changes\fR:
.
.IP "" 4
.
.nf

$ git vendor upstream forge my_changes
.
.fi
.
.IP "" 0
.
.P
Upstream changes to the source repository to \fBmaster\fR:
.
.IP "" 4
.
.nf

$ git vendor upstream forge
.
.fi
.
.IP "" 0
.
.P
Upstream changes to another repository to a (new) branch \fBmy_changes\fR:
.
.IP "" 4
.
.nf

$ git vendor upstream forge my_changes --repo https://github.com/user/another.git
.
.fi
.
.IP "" 0
.
.P
Upstream changes to another repository to \fBmaster\fR:
.
.IP "" 4
.
.nf

$ git vendor upstream forge --repo https://github.com/user/another.git
.
.fi
.
.IP "" 0
.
.P
Removing a dependency:
.
.IP "" 4
Expand Down
26 changes: 24 additions & 2 deletions man/git-vendor.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ git-vendor(1) -- manage vendored dependency subtrees

`git-vendor update <name> [<ref>]`

`git-vendor upstream <name> [<ref>]`

## DESCRIPTION

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`, `update` or `upstream` any dependencies it has not added, the reason is that `git-vendor` adds special commit messages so that it can track existing dependencies.

## COMMANDS

Expand All @@ -37,6 +39,10 @@ git-vendor(1) -- manage vendored dependency subtrees

Update the vendored dependency to a different version.

upstream &lt;dir&gt; &lt;ref&gt;

Push the vendored dependency changes to the source repository.


## OPTIONS

Expand All @@ -46,7 +52,7 @@ git-vendor(1) -- manage vendored dependency subtrees

&lt;name&gt;

A name to provide the vendored dependency to use when listing/updating.
A name to provide the vendored dependency to use when listing/updating/pushing.
brettlangdon marked this conversation as resolved.
Show resolved Hide resolved

&lt;repository&gt;

Expand Down Expand Up @@ -74,6 +80,22 @@ git-vendor(1) -- manage vendored dependency subtrees

$ git vendor update forge

Upstream changes to the source repository to `master`:

$ git vendor upstream forge

Upstream changes to the source repository to a (new) branch my_changes:

$ git vendor upstream forge my_changes

Upstream changes to another repository to `master`:

$ git vendor upstream forge --repo https://github.com/user/another.git

Upstream changes to another repository to a (new) branch my_changes:

$ git vendor upstream forge my_changes --repo https://github.com/user/another.git

Removing a dependency:

$ git vendor remove forge
Expand Down