Skip to content

Commit f4a338f

Browse files
committed
feat: Add git-get command
1 parent f5bcbe5 commit f4a338f

File tree

9 files changed

+228
-0
lines changed

9 files changed

+228
-0
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 `name`:
889890
$ git fresh-branch docs
890891
```
891892
893+
## git get
894+
895+
Clone repository into `"$GIT_EXTRA_DEFAULT_CLONE_PATH/<repository_name>"`:
896+
897+
```bash
898+
$ export GIT_EXTRA_DEFAULT_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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
url=$1
11+
12+
if (( $# == 0)); then
13+
_usage
14+
exit 0
15+
fi
16+
17+
for arg; do
18+
if [ "$arg" = '-h' ] || [ "$arg" = '--help' ]; then
19+
_usage
20+
exit 0
21+
fi
22+
done
23+
24+
25+
if [ -z "$GIT_EXTRA_DEFAULT_CLONE_PATH" ]; then
26+
printf 'ERROR: %s\n' "Environment variable 'GIT_EXTRA_DEFAULT_CLONE_PATH' must be set to a directory to clone under" >&2
27+
exit 1
28+
fi
29+
30+
dirname=${url%/}
31+
dirname=${url%.git}
32+
dirname=${dirname##*/}
33+
34+
mkdir -p "$GIT_EXTRA_DEFAULT_CLONE_PATH"
35+
git clone "$url" "$GIT_EXTRA_DEFAULT_CLONE_PATH/$dirname"

etc/git-extras-completion.zsh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
372372
force-clone:'overwrite local repositories with clone' \
373373
fork:'fork a repo on github' \
374374
fresh-branch:'create fresh branches' \
375+
get:'clone a repository in a directory' \
375376
gh-pages:'create the github pages branch' \
376377
graft:'merge and destroy a given branch' \
377378
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.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 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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 environment variable \fBGIT_EXTRA_DEFAULT_CLONE_PATH\fR
10+
.SH "EXAMPLES"
11+
.nf
12+
$ GIT_EXTRA_DEFAULT_CLONE_PATH="$HOME/some\-dir" git\-get 'https://github\.com/hyperupcall/bake'
13+
Cloning into '/home/<user>/some\-dir/bake'\|\.\|\.\|\.
14+
remote: Enumerating objects: 1199, done\.
15+
remote: Counting objects: 100% (378/378), done\.
16+
remote: Compressing objects: 100% (174/174), done\.
17+
remote: Total 1199 (delta 163), reused 357 (delta 146), pack\-reused 821
18+
Receiving objects: 100% (1199/1199), 3\.05 MiB | 9\.85 MiB/s, done\.
19+
Resolving deltas: 100% (515/515), done\.
20+
$
21+
.fi
22+
.SH "AUTHOR"
23+
Written by Edwin Kofler <\fIedwin@kofler\.dev\fR>
24+
.SH "REPORTING BUGS"
25+
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
26+
.SH "SEE ALSO"
27+
<\fIhttps://github\.com/tj/git\-extras\fR>

man/git-get.html

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

man/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ git-feature(1) git-feature
2828
git-force-clone(1) git-force-clone
2929
git-fork(1) git-fork
3030
git-fresh-branch(1) git-fresh-branch
31+
git-get(1) git-get
3132
git-gh-pages(1) git-gh-pages
3233
git-graft(1) git-graft
3334
git-guilt(1) git-guilt

0 commit comments

Comments
 (0)