Skip to content

Commit 8af4389

Browse files
feat: Implement git-get command (#1045)
* feat: Add `git-get` command * Update Commands.md Co-authored-by: 罗泽轩 <[email protected]> * fix: Use Git config to store value * improve `git-get` description * fix: Add `--global` to git invocation * Enable passing options to `git clone` * fix: Ordering of checks --------- Co-authored-by: 罗泽轩 <[email protected]>
1 parent 34609bd commit 8af4389

12 files changed

+252
-6
lines changed

Commands.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [`git force-clone`](#git-force-clone)
2929
- [`git fork`](#git-fork)
3030
- [`git fresh-branch`](#git-fresh-branch)
31+
- [`git get`](#git-get)
3132
- [`git gh-pages`](#git-gh-pages)
3233
- [`git graft`](#git-graft)
3334
- [`git guilt`](#git-guilt)
@@ -889,6 +890,15 @@ Create empty local branch `docs`:
889890
$ git fresh-branch docs
890891
```
891892
893+
## git get
894+
895+
Clone repository into a subdirectory of the configured path, `"$HOME/some-dir"`:
896+
897+
```bash
898+
$ git config --global --add git-extras.get.clone-path "$HOME/some-dir"
899+
$ git get 'https://github.com/hyperupcall/bake'
900+
```
901+
892902
## git guilt
893903
894904
Calculate the change in blame between two revisions

bin/git-get

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
_usage() {
4+
printf '%s\n' "usage: ${0##*/} <url>
5+
usage: ${0##*/} --help
6+
7+
Clone a repository in a particular directory."
8+
}
9+
10+
if (( $# == 0 )); then
11+
_usage
12+
exit 0
13+
fi
14+
15+
for arg; do
16+
if [ "$arg" = '-h' ] || [ "$arg" = '--help' ]; then
17+
_usage
18+
exit 0
19+
fi
20+
done
21+
22+
url=$1
23+
if ! shift; then
24+
printf 'ERROR: Failed to shift' >&2
25+
exit 1
26+
fi
27+
28+
clone_path=$(git config --get git-extras.get.clone-path)
29+
30+
if [ -z "$clone_path" ]; then
31+
printf 'ERROR: %s\n' "Git configuration key 'git-extras.get.clone-path' must be set to a directory to clone under" >&2
32+
exit 1
33+
fi
34+
35+
dirname=${url%/}
36+
dirname=${url%.git}
37+
dirname=${dirname##*/}
38+
39+
mkdir -p "$clone_path"
40+
git clone "$url" "$clone_path/$dirname" "$@"

etc/git-extras-completion.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
373373
force-clone:'overwrite local repositories with clone' \
374374
fork:'fork a repo on GitHub' \
375375
fresh-branch:'create fresh branches' \
376+
get:'clone a repository in a directory' \
376377
gh-pages:'create the GitHub pages branch' \
377378
graft:'merge and destroy a given branch' \
378379
guilt:'calculate change between two revisions' \

etc/git-extras.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ set __fish_git_extras_commands \
2727
"force-clone:overwrite local repositories with clone" \
2828
"fork:Fork a repo on github" \
2929
"fresh-branch:Create fresh branches" \
30+
"get:Clone a repository in a directory" \
3031
"gh-pages:Create the GitHub Pages branch" \
3132
"graft:Merge and destroy a given branch" \
3233
"guilt:calculate change between two revisions" \

man/git-extras.1

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" generated with Ronn-NG/v0.9.1
22
.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
3-
.TH "GIT\-EXTRAS" "1" "December 2021" "" "Git Extras"
3+
.TH "GIT\-EXTRAS" "1" "May 2023" "" "Git Extras"
44
.SH "NAME"
55
\fBgit\-extras\fR \- Awesome GIT utilities
66
.SH "SYNOPSIS"
@@ -20,7 +20,7 @@ Self update\.
2020
.SH "ENVIRONMENT AND CONFIGURATION VARIABLES"
2121
\fBgit config \-\-add git\-extras\.default\-branch $BRANCH\fR
2222
.P
23-
Change the default branch to \fB$BRANCH\fR\. If \fBgit\-extras\.default\-branch\fR isn\'t set, \fBinit\.defaultBranch\fR is used instead\. If none of them are set it defaults to \fBmain\fR\.
23+
Change the default branch to \fB$BRANCH\fR\. If \fBgit\-extras\.default\-branch\fR isn't set, \fBinit\.defaultBranch\fR is used instead\. If none of them are set it defaults to \fBmain\fR\.
2424
.SH "COMMANDS"
2525
.IP "\[ci]" 4
2626
\fBgit\-abort(1)\fR Abort current git operation
@@ -31,6 +31,8 @@ Change the default branch to \fB$BRANCH\fR\. If \fBgit\-extras\.default\-branch\
3131
.IP "\[ci]" 4
3232
\fBgit\-authors(1)\fR Generate authors report
3333
.IP "\[ci]" 4
34+
\fBgit\-browse\-ci(1)\fR \fIView the web page for the current repository\fR
35+
.IP "\[ci]" 4
3436
\fBgit\-browse(1)\fR \fIView the web page for the current repository\fR
3537
.IP "\[ci]" 4
3638
\fBgit\-brv(1)\fR List branches sorted by their last commit date
@@ -47,7 +49,7 @@ Change the default branch to \fB$BRANCH\fR\. If \fBgit\-extras\.default\-branch\
4749
.IP "\[ci]" 4
4850
\fBgit\-commits\-since(1)\fR Show commit logs since some date
4951
.IP "\[ci]" 4
50-
\fBgit\-contrib(1)\fR Show user\'s contributions
52+
\fBgit\-contrib(1)\fR Show user's contributions
5153
.IP "\[ci]" 4
5254
\fBgit\-count(1)\fR Show commit count
5355
.IP "\[ci]" 4
@@ -77,6 +79,8 @@ Change the default branch to \fB$BRANCH\fR\. If \fBgit\-extras\.default\-branch\
7779
.IP "\[ci]" 4
7880
\fBgit\-fresh\-branch(1)\fR Create fresh branches
7981
.IP "\[ci]" 4
82+
\fBgit\-get(1)\fR Clone a Git repository under a configured directory
83+
.IP "\[ci]" 4
8084
\fBgit\-gh\-pages(1)\fR Create the GitHub Pages branch
8185
.IP "\[ci]" 4
8286
\fBgit\-graft(1)\fR Merge and destroy a given branch
@@ -115,7 +119,7 @@ Change the default branch to \fB$BRANCH\fR\. If \fBgit\-extras\.default\-branch\
115119
.IP "\[ci]" 4
116120
\fBgit\-pull\-request(1)\fR Create pull request for GitHub project
117121
.IP "\[ci]" 4
118-
\fBgit\-reauthor(1)\fR Rewrite history to change author\'s identity
122+
\fBgit\-reauthor(1)\fR Rewrite history to change author's identity
119123
.IP "\[ci]" 4
120124
\fBgit\-rebase\-patch(1)\fR Rebases a patch
121125
.IP "\[ci]" 4
@@ -145,7 +149,7 @@ Change the default branch to \fB$BRANCH\fR\. If \fBgit\-extras\.default\-branch\
145149
.IP "\[ci]" 4
146150
\fBgit\-show\-unmerged\-branches(1)\fR Show unmerged branches
147151
.IP "\[ci]" 4
148-
\fBgit\-squash(1)\fR squash N last changes up to a ref\'ed commit
152+
\fBgit\-squash(1)\fR squash N last changes up to a ref'ed commit
149153
.IP "\[ci]" 4
150154
\fBgit\-stamp(1)\fR Stamp the last commit message
151155
.IP "\[ci]" 4

man/git-extras.html

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-extras.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ git-extras(1) -- Awesome GIT utilities
5555
- **git-force-clone(1)** overwrite local repositories with clone
5656
- **git-fork(1)** Fork a repo on github
5757
- **git-fresh-branch(1)** Create fresh branches
58+
- **git-get(1)** Clone a Git repository under a configured directory
5859
- **git-gh-pages(1)** Create the GitHub Pages branch
5960
- **git-graft(1)** Merge and destroy a given branch
6061
- **git-guilt(1)** calculate change between two revisions

man/git-get.1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.\" generated with Ronn-NG/v0.9.1
2+
.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
3+
.TH "GIT\-GET" "1" "May 2023" "" "Git Extras"
4+
.SH "NAME"
5+
\fBgit\-get\fR \- Clone a Git repository under a directory
6+
.SH "SYNOPSIS"
7+
\fBgit\-get\fR
8+
.SH "DESCRIPTION"
9+
Clones a Git repository under the directory specified by the Git configuration \fBgit\-extras\.get\.clone\-path\fR
10+
.SH "EXAMPLES"
11+
.nf
12+
$ git config \-\-add git\-extras\.get\.clone\-path "$HOME/some\-dir"
13+
$ git get 'https://github\.com/hyperupcall/bake'
14+
Cloning into '/home/<user>/some\-dir/bake'\|\.\|\.\|\.
15+
remote: Enumerating objects: 1199, done\.
16+
remote: Counting objects: 100% (378/378), done\.
17+
remote: Compressing objects: 100% (174/174), done\.
18+
remote: Total 1199 (delta 163), reused 357 (delta 146), pack\-reused 821
19+
Receiving objects: 100% (1199/1199), 3\.05 MiB | 9\.85 MiB/s, done\.
20+
Resolving deltas: 100% (515/515), done\.
21+
$
22+
.fi
23+
.SH "AUTHOR"
24+
Written by Edwin Kofler <\fIedwin@kofler\.dev\fR>
25+
.SH "REPORTING BUGS"
26+
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
27+
.SH "SEE ALSO"
28+
<\fIhttps://github\.com/tj/git\-extras\fR>

man/git-get.html

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-get.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
git-get(1) -- Clone a Git repository under a configured directory
2+
=================================================
3+
4+
## SYNOPSIS
5+
6+
`git-get`
7+
8+
## DESCRIPTION
9+
10+
Clones a Git repository under the directory specified by the Git configuration `git-extras.get.clone-path`
11+
12+
## EXAMPLES
13+
14+
$ git config --add git-extras.get.clone-path "$HOME/some-dir"
15+
$ git get 'https://github.com/hyperupcall/bake'
16+
Cloning into '/home/<user>/some-dir/bake'...
17+
remote: Enumerating objects: 1199, done.
18+
remote: Counting objects: 100% (378/378), done.
19+
remote: Compressing objects: 100% (174/174), done.
20+
remote: Total 1199 (delta 163), reused 357 (delta 146), pack-reused 821
21+
Receiving objects: 100% (1199/1199), 3.05 MiB | 9.85 MiB/s, done.
22+
Resolving deltas: 100% (515/515), done.
23+
$
24+
25+
## AUTHOR
26+
27+
Written by Edwin Kofler &lt;<[email protected]>&gt;
28+
29+
## REPORTING BUGS
30+
31+
&lt;<https://github.com/tj/git-extras/issues>&gt;
32+
33+
## SEE ALSO
34+
35+
&lt;<https://github.com/tj/git-extras>&gt;

0 commit comments

Comments
 (0)