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

feat: Implement git-get command #1045

Merged
merged 9 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [`git force-clone`](#git-force-clone)
- [`git fork`](#git-fork)
- [`git fresh-branch`](#git-fresh-branch)
- [`git get`](#git-get)
- [`git gh-pages`](#git-gh-pages)
- [`git graft`](#git-graft)
- [`git guilt`](#git-guilt)
Expand Down Expand Up @@ -889,6 +890,15 @@ Create empty local branch `name`:
$ git fresh-branch docs
```

## git get

Clone repository into `"$GIT_EXTRA_DEFAULT_CLONE_PATH/<repository_name>"`:

```bash
$ export GIT_EXTRA_DEFAULT_CLONE_PATH="$HOME/some-dir"
$ git get 'https://github.com/hyperupcall/bake'
```

## git guilt

Calculate the change in blame between two revisions
Expand Down
35 changes: 35 additions & 0 deletions bin/git-get
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


_usage() {
printf '%s\n' "usage: ${0##*/} <url>
usage: ${0##*/} --help
Clone a repository in a particular directory."
}

url=$1

if (( $# == 0)); then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to check num of args before assigning to $url

Copy link
Collaborator Author

@hyperupcall hyperupcall Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake - it has been fixed now.

_usage
exit 0
fi

for arg; do
if [ "$arg" = '-h' ] || [ "$arg" = '--help' ]; then
_usage
exit 0
fi
done


if [ -z "$GIT_EXTRA_DEFAULT_CLONE_PATH" ]; then
printf 'ERROR: %s\n' "Environment variable 'GIT_EXTRA_DEFAULT_CLONE_PATH' must be set to a directory to clone under" >&2
exit 1
fi

dirname=${url%/}
dirname=${url%.git}
dirname=${dirname##*/}

mkdir -p "$GIT_EXTRA_DEFAULT_CLONE_PATH"
git clone "$url" "$GIT_EXTRA_DEFAULT_CLONE_PATH/$dirname"
1 change: 1 addition & 0 deletions etc/git-extras-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
force-clone:'overwrite local repositories with clone' \
fork:'fork a repo on github' \
fresh-branch:'create fresh branches' \
get:'clone a repository in a directory' \
gh-pages:'create the github pages branch' \
graft:'merge and destroy a given branch' \
guilt:'calculate change between two revisions' \
Expand Down
1 change: 1 addition & 0 deletions etc/git-extras.fish
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set __fish_git_extras_commands \
"force-clone:overwrite local repositories with clone" \
"fork:Fork a repo on github" \
"fresh-branch:Create fresh branches" \
"get:Clone a repository in a directory" \
"gh-pages:Create the GitHub Pages branch" \
"graft:Merge and destroy a given branch" \
"guilt:calculate change between two revisions" \
Expand Down
1 change: 1 addition & 0 deletions man/git-extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ git-extras(1) -- Awesome GIT utilities
- **git-force-clone(1)** overwrite local repositories with clone
- **git-fork(1)** Fork a repo on github
- **git-fresh-branch(1)** Create fresh branches
- **git-get(1)** Clone a Git repository under a directory
- **git-gh-pages(1)** Create the GitHub Pages branch
- **git-graft(1)** Merge and destroy a given branch
- **git-guilt(1)** calculate change between two revisions
Expand Down
27 changes: 27 additions & 0 deletions man/git-get.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.\" generated with Ronn-NG/v0.9.1
.\" http://github.com/apjanke/ronn-ng/tree/0.9.1
.TH "GIT\-GET" "1" "May 2023" "" "Git Extras"
.SH "NAME"
\fBgit\-get\fR \- Clone a Git repository under a directory
.SH "SYNOPSIS"
\fBgit\-get\fR
.SH "DESCRIPTION"
Clones a Git repository under the directory specified by the environment variable \fBGIT_EXTRA_DEFAULT_CLONE_PATH\fR
.SH "EXAMPLES"
.nf
$ GIT_EXTRA_DEFAULT_CLONE_PATH="$HOME/some\-dir" git\-get 'https://github\.com/hyperupcall/bake'
Cloning into '/home/<user>/some\-dir/bake'\|\.\|\.\|\.
remote: Enumerating objects: 1199, done\.
remote: Counting objects: 100% (378/378), done\.
remote: Compressing objects: 100% (174/174), done\.
remote: Total 1199 (delta 163), reused 357 (delta 146), pack\-reused 821
Receiving objects: 100% (1199/1199), 3\.05 MiB | 9\.85 MiB/s, done\.
Resolving deltas: 100% (515/515), done\.
$
.fi
.SH "AUTHOR"
Written by Edwin Kofler <\fIedwin@kofler\.dev\fR>
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR>
118 changes: 118 additions & 0 deletions man/git-get.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions man/git-get.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
git-get(1) -- Clone a Git repository under a directory
=================================================

## SYNOPSIS

`git-get`

## DESCRIPTION

Clones a Git repository under the directory specified by the environment variable `GIT_EXTRA_DEFAULT_CLONE_PATH`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using a git config like the other scripts?
For example,

remote_pref=${2:-$(git config --get git-extras.pr.remote)}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's probably better


## EXAMPLES

$ GIT_EXTRA_DEFAULT_CLONE_PATH="$HOME/some-dir" git-get 'https://github.com/hyperupcall/bake'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this feature is not much convenient than git clone 'https://github.com/hyperupcall/bake' $GIT_EXTRA_DEFAULT_CLONE_PATH/bake. Could you provide some real-world use cases for this tool?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linked issue did suggest making a PR, but this change additionally significantly reduces typing.

On some keyboards (like mine), the ~ is either touch to reach, or requires an extra button (Fn+Shift for some 80%s). $HOME is also quite long to type. Besides that, this is a good solution when cloning frequently. It's common to clone repositories (maybe for just sifting through or quickly reading code) to a certain directory, such as ~/Programming/git. I myself have about 50 Git repositories cloned there. Having an actual variable like $GIT_CLONE_DIR is hard to remember and again is on the longer side.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see

Cloning into '/home/<user>/some-dir/bake'...
remote: Enumerating objects: 1199, done.
remote: Counting objects: 100% (378/378), done.
remote: Compressing objects: 100% (174/174), done.
remote: Total 1199 (delta 163), reused 357 (delta 146), pack-reused 821
Receiving objects: 100% (1199/1199), 3.05 MiB | 9.85 MiB/s, done.
Resolving deltas: 100% (515/515), done.
$

## AUTHOR

Written by Edwin Kofler &lt;<[email protected]>&gt;

## REPORTING BUGS

&lt;<https://github.com/tj/git-extras/issues>&gt;

## SEE ALSO

&lt;<https://github.com/tj/git-extras>&gt;
1 change: 1 addition & 0 deletions man/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ git-feature(1) git-feature
git-force-clone(1) git-force-clone
git-fork(1) git-fork
git-fresh-branch(1) git-fresh-branch
git-get(1) git-get
git-gh-pages(1) git-gh-pages
git-graft(1) git-graft
git-guilt(1) git-guilt
Expand Down