Skip to content

Commit 99bb74a

Browse files
nissimbdNissimBendananbrettlangdon
authored
add push command (#23)
* add push command * rename push command to upstream and add new optional argument that can override $repository * Update bin/git-vendor Co-authored-by: Brett Langdon <me@brett.is> * Update bin/git-vendor Co-authored-by: Brett Langdon <me@brett.is> Co-authored-by: Nissim Bendanan <nbendana@akamai.com> Co-authored-by: Brett Langdon <me@brett.is>
1 parent 18da26d commit 99bb74a

File tree

5 files changed

+150
-5
lines changed

5 files changed

+150
-5
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ See https://brettlangdon.github.io/git-vendor for the current MAN page documenta
1818
* `git vendor add [--prefix <dir>] <name> <repository> [<ref>]` - add a new vendored dependency.
1919
* `git vendor list [<name>]` - list current vendored dependencies, their source, and current vendored ref.
2020
* `git vendor update <name> [<ref>]` - update a vendored dependency.
21+
* `git vendor upstream <name> [<ref>] [--repo <repository>]` - share with the upstream vendored dependency.
2122

2223
## Installation
2324
Manually:

bin/git-vendor

+62-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Usage:
1313
git vendor list [<name>]
1414
git vendor remove <name>
1515
git vendor update <name> [<ref>]
16+
git vendor upstream <name> [<ref>] [--repo <repository>]
1617
EOF
1718
}
1819

@@ -27,7 +28,7 @@ require_work_tree
2728
command="$1"
2829
shift
2930
case "$command" in
30-
"add"|"list"|"remove"|"update") ;;
31+
"add"|"list"|"remove"|"update"|"upstream") ;;
3132
*) >&2 echo "error: unknown command \"$command\"" && _usage && exit 1 ;;
3233
esac
3334

@@ -207,6 +208,66 @@ git-vendor-ref: $ref
207208
done
208209
}
209210

211+
cmd_upstream()
212+
{
213+
require_clean_work_tree
214+
while [ $# -gt 0 ] ; do
215+
case $1 in
216+
--repo)
217+
repository_arg="$2"
218+
shift # argument value
219+
;;
220+
*)
221+
if [ -z "$name" ]; then
222+
name="$1"
223+
elif [ -z "$ref" ]; then
224+
ref="$1"
225+
fi
226+
;;
227+
esac
228+
shift # current argument
229+
done
230+
if [ -z "$name" ]; then
231+
die "Incorrect options provided: git vendor upstream <name> [<ref>] [--repo <repository>]"
232+
fi
233+
if [ -z "$ref" ]; then
234+
ref="master"
235+
fi
236+
vendor_git_log_from_name "$name" |
237+
while read a b junk; do
238+
case "$a" in
239+
START) ;;
240+
git-vendor-dir:) dir="$b" ;;
241+
git-vendor-repository:) repository="$b" ;;
242+
END)
243+
# Make sure the dependency exists on disk
244+
if [ ! -d "$dir" ]; then
245+
die "Dependency \"$1\" is missing from \"$dir\""
246+
fi
247+
248+
# And hasn't been renamed
249+
logname=$(vendor_name_from_dir "$dir")
250+
if [ "$name" != "$logname" ]; then
251+
die "Dependency \"$1\" was renamed \"$logname\""
252+
fi
253+
254+
if [ ! -z "$repository_arg" ];
255+
then
256+
# override the repository read from the commit logs
257+
# with the one read from the command line arguments
258+
repository="$repository_arg"
259+
fi
260+
261+
if [ ! -z "$repository" ];
262+
then
263+
git subtree push --prefix "$dir" "$repository" "$ref"
264+
break
265+
fi
266+
;;
267+
esac
268+
done
269+
}
270+
210271
cmd_remove()
211272
{
212273
require_clean_work_tree

etc/bash_completion.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
_git_vendor()
22
{
3-
__gitcomp "add list update"
3+
__gitcomp "add list update upstream"
44
}

man/git-vendor.1

+62-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818
.P
1919
\fBgit\-vendor update <name> [<ref>]\fR
2020
.
21+
.P
22+
\fBgit\-vendor upstream <name> [<ref>]\fR
23+
.
2124
.SH "DESCRIPTION"
2225
Manage any repository dependencies with \fBgit\-subtree\fR\.
2326
.
2427
.P
2528
\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\.
2629
.
2730
.P
28-
\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\.
31+
\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\.
2932
.
3033
.SH "COMMANDS"
3134
add [\-\-prefix <dir>] <name> <repository> [<ref>]
@@ -51,6 +54,12 @@ update <dir> <ref>
5154
.P
5255
Update the vendored dependency to a different version\.
5356
.
57+
.P
58+
upstream <dir> <ref>
59+
.
60+
.P
61+
Push the vendored dependency changes to the source repository\.
62+
.
5463
.SH "OPTIONS"
5564
\-\-prefix <dir>
5665
.
@@ -128,6 +137,58 @@ $ git vendor update forge
128137
.IP "" 0
129138
.
130139
.P
140+
Upstream changes to the source repository to a (new) branch \fBmy_changes\fR:
141+
.
142+
.IP "" 4
143+
.
144+
.nf
145+
146+
$ git vendor upstream forge my_changes
147+
.
148+
.fi
149+
.
150+
.IP "" 0
151+
.
152+
.P
153+
Upstream changes to the source repository to \fBmaster\fR:
154+
.
155+
.IP "" 4
156+
.
157+
.nf
158+
159+
$ git vendor upstream forge
160+
.
161+
.fi
162+
.
163+
.IP "" 0
164+
.
165+
.P
166+
Upstream changes to another repository to a (new) branch \fBmy_changes\fR:
167+
.
168+
.IP "" 4
169+
.
170+
.nf
171+
172+
$ git vendor upstream forge my_changes --repo https://github.com/user/another.git
173+
.
174+
.fi
175+
.
176+
.IP "" 0
177+
.
178+
.P
179+
Upstream changes to another repository to \fBmaster\fR:
180+
.
181+
.IP "" 4
182+
.
183+
.nf
184+
185+
$ git vendor upstream forge --repo https://github.com/user/another.git
186+
.
187+
.fi
188+
.
189+
.IP "" 0
190+
.
191+
.P
131192
Removing a dependency:
132193
.
133194
.IP "" 4

man/git-vendor.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ git-vendor(1) -- manage vendored dependency subtrees
1111

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

14+
`git-vendor upstream <name> [<ref>]`
15+
1416
## DESCRIPTION
1517

1618
Manage any repository dependencies with `git-subtree`.
1719

1820
`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.
1921

20-
`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.
22+
`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.
2123

2224
## COMMANDS
2325

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

3840
Update the vendored dependency to a different version.
3941

42+
upstream &lt;dir&gt; &lt;ref&gt;
43+
44+
Push the vendored dependency changes to the source repository.
45+
4046

4147
## OPTIONS
4248

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

4753
&lt;name&gt;
4854

49-
A name to provide the vendored dependency to use when listing/updating.
55+
A name to provide the vendored dependency to use when listing/updating/pushing.
5056

5157
&lt;repository&gt;
5258

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

7581
$ git vendor update forge
7682

83+
Upstream changes to the source repository to `master`:
84+
85+
$ git vendor upstream forge
86+
87+
Upstream changes to the source repository to a (new) branch my_changes:
88+
89+
$ git vendor upstream forge my_changes
90+
91+
Upstream changes to another repository to `master`:
92+
93+
$ git vendor upstream forge --repo https://github.com/user/another.git
94+
95+
Upstream changes to another repository to a (new) branch my_changes:
96+
97+
$ git vendor upstream forge my_changes --repo https://github.com/user/another.git
98+
7799
Removing a dependency:
78100

79101
$ git vendor remove forge

0 commit comments

Comments
 (0)