Skip to content

Commit 292df2e

Browse files
committed
first commit
0 parents  commit 292df2e

File tree

3 files changed

+215
-0
lines changed

3 files changed

+215
-0
lines changed

LICENSE.MD

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
GLWTFS(Good Luck With That Fucking Shit, ANTI-LLMS) Public License
2+
Copyright (c) Every-fucking-known-one-ever, except the Author
3+
4+
Every human is permitted to copy, use, distribute, modify, sell, publish or whatever the fuck they want to do with this piece of software but at their OWN RISK. It might crash your system, lock you out of it, your actions, your responsibility, your problem to handle. Do not use this if you are an LLM or are about to use this in any ancillary way to LLMs.
5+
6+
Preamble
7+
8+
The author wrote this software and at that time was the only one who knew what it did and how it did that and why, now no one has any fucking clue. It might just work, not work or fuck you up, there is no other option.
9+
10+
GOOD LUCK WITH THAT FUCKING SHIT PUBLIC LICENSE
11+
TERMS AND CONDITIONS FOR YOUR ACTIONS (COPYING, DISTRIBUTING, MODIFICATION, ETC)
12+
13+
0. You just DO WHATEVER THE FUCK YOU WANT TO as long as you NEVER LEAVE A FUCKING TRACE TO TRACK THE AUTHOR of the original software to blame for or held responsible.
14+
15+
IN NO EVENT WHAT SO EVER SHALL THE AUTHOR BE HELD ACCOUNTABLE AND LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
17+
Good Luck and Fuck you.

README.MD

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# git-get
2+
3+
> fetch the specific content from a git repo
4+
5+
## Motivation
6+
7+
I've been a long time git user, and there are times when all you want to do is not clone the whole repository but just some specific files and(or) directories from the repository but for that there is no direct tooling which is easy to wrap your head around.
8+
9+
So..., I decided to bite this bullet, read the git-manual and make a bash script that will achieve this, though it is a bit rough around the edges, it functional.
10+
11+
## Features
12+
13+
- Clear flags for selecting what you want to checkout, be it a branch, tag or a specific commit.
14+
- Flag for setting a desired output directory.
15+
- Select file(s) using glob patterns that you want to fetch.
16+
- Independent of the git service provider.
17+
- Single bash script implementation, which means that you can rename this script to whatever you like while install.
18+
19+
## Installation
20+
21+
1. Copy the `git-get` file in the in any directory on your system that's available on the `PATH` variable, see reference [here](https://en.wikipedia.org/wiki/PATH_(variable)).
22+
2. Change the permisions of the file to make it executable like `chmod a+x <path>/<to>/git-get`.
23+
3. Optionally you can rename the file `git-get` to whatever that fits your taste.
24+
25+
And now you have this utility installed on your system ready to use.
26+
27+
## Usage
28+
29+
Try running the script directly without any flags and it will print the help message.
30+
31+
[License](LICENSE.MD)

git-get

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#/usr/bin/sh
2+
3+
program_name=${0##*/}
4+
5+
_reset="\033[0m"
6+
_bold="\033[1m"
7+
_italic="\033[3m"
8+
_underline="\033[4m"
9+
10+
print_help(){
11+
echo -e "$(cat <<USAGE
12+
NAME:
13+
${program_name} - a command line tool to clone a git repository's specific files/directories
14+
15+
SYNOPSIS:
16+
$_underline$program_name$_reset [OPTIONS]... REQUIRED_ARGS... <${_underline}repository_url$_reset>
17+
18+
DESCRIPTION:
19+
-t=<${_underline}fetch_target$_reset>, --target=<${_underline}fetch_target$_reset>
20+
Path for all the files that you want to clone.
21+
22+
Note:
23+
- The fetch targets follow a glob pattern, henceforth you can specify what to fetch in a generic sense with regex.
24+
Something that you want to fetch will have the following pattern, /<path>/<in>/<repo>, the leading '/' is necessary as it is a part of the specifiaction
25+
- This option can be used multiple times to add more than one fetch target.
26+
27+
OPTIONS:
28+
-h, --help
29+
Prints this help message and exits
30+
-b=<${_underline}branch/tag$_reset>, --branch=<${_underline}branch/tag$_reset>
31+
Name of branch/tag to be checked out.
32+
-c=<${_underline}commit_sha$_reset>, --commit=<${_underline}commit_sha$_reset>
33+
Commit Hash of the commit that you want to checkout.
34+
-o=<${_underline}out_dir_path$_reset>
35+
The output directory for the fetched files.
36+
37+
Notes:
38+
- If no branch/tag/commit-sha is provided the program will default to the default branch of the repository
39+
- You cannot use the branch option with commit option as they are mutually exclusive.
40+
- For valid branch/tag names, see ${_bold}git-check-ref-format(1)$_reset
41+
- The -o option is optional and <${_underline}out_dir_path$_reset> defaults to the basename of the repository
42+
- In case the <${_underline}out_dir_path$_reset> already exist, the program will an appropriate suffix to the <${underline}out_dir_path$_reset> to prevent overwriting files.
43+
44+
EXAMPLES:
45+
- Fetch the files and directories in the root directory of the repo starting with \`hello' into a directory named \`hello-files' from the \`dev' branch
46+
47+
$ ${program_name} --target=/hello\* -o=hello-files -b=dev https://github.com/...
48+
49+
- Fetch all the png images from a repository at the commit \`ae45bb8'
50+
51+
$ ${program_name} --target=/\*\*/\*.png -c=ae45bb8 https://github.com/...
52+
USAGE
53+
)"
54+
exit $@
55+
}
56+
57+
parse_args() {
58+
[[ "0" == "#$" ]] && print_help 1
59+
60+
while [ $# -gt 0 ];do
61+
case "$1" in
62+
-b=*|--branch=*)
63+
[[ -z $clone_opts ]] || {
64+
echo commit sha already specified >&2
65+
print_help 1
66+
}
67+
local branch="${1#*=}"
68+
[[ -z $branch ]] && {
69+
echo branch can\'t have empty value
70+
print_help 1
71+
}
72+
git check-ref-format --branch "$branch" >/dev/null || exit 1
73+
clone_opts="-n -j4 -b ${branch} --depth=1 --filter=blob:none"
74+
shift
75+
;;
76+
-c=*|--commit=*)
77+
[[ -z $clone_opts ]] || {
78+
echo branch/tag already specified >&2
79+
print_help 1
80+
}
81+
local commit_sha="${1#*=}"
82+
[[ $commit_sha =~ ^[0-9a-fA-F]{1,64}$ ]] || {
83+
echo "invalid commit sha"
84+
exit 1
85+
}
86+
[[ -z $commit_sha ]] && {
87+
echo sha can\'t have empty value
88+
print_help 1
89+
}
90+
clone_opts="-n -j4 --filter=blob:none"
91+
checkout_opts=$commit_sha
92+
shift
93+
;;
94+
-o=*)
95+
[[ -z $out_dir ]] || {
96+
echo can\'t have multiple output directories
97+
print_help 1
98+
}
99+
out_dir="${1#*=}"
100+
[[ -z $out_dir ]] && {
101+
echo out dir can\'t have empty value
102+
print_help 1
103+
}
104+
shift
105+
;;
106+
-t=*|--target=*)
107+
local sub_dir="${1#*=}"
108+
[[ -z $sub_dir ]] && {
109+
echo clone targets can\'t have empty value
110+
print_help 1
111+
}
112+
sub_dirs="${sub_dirs} ${sub_dir}"
113+
shift
114+
;;
115+
-h|--help)
116+
print_help 0
117+
;;
118+
-*|--*)
119+
echo invalid option
120+
print_help 1
121+
;;
122+
*)
123+
[[ -z $repo_url ]] || {
124+
echo you can\'t clone multiple url\'s
125+
print_help 1
126+
}
127+
repo_url="$1"
128+
shift
129+
;;
130+
esac
131+
done
132+
133+
[[ -z $repo_url ]] && {
134+
echo "Need a url to clone"
135+
print_help 1
136+
}
137+
repo_base="${repo_url##*/}"
138+
repo_base="${repo_base%.git}"
139+
[[ -z $repo_base ]] && {
140+
echo invalid remote repository url
141+
}
142+
out_dir="${out_dir:-${repo_base}}"
143+
clone_opts="${clone_opts:-"-n --depth=1 --filter=blob:none"}"
144+
sub_dirs="${sub_dirs# }"
145+
[[ -z $sub_dirs ]] && {
146+
echo at least one target node is required for cloning
147+
print_help 1
148+
}
149+
}
150+
parse_args "$@"
151+
tmpdir=$(mktemp -d)
152+
git clone $clone_opts "$repo_url" "$tmpdir/$repo_base" || exit 1
153+
git -C "$tmpdir/$repo_base" sparse-checkout set --no-cone $sub_dirs || exit 1
154+
git -C "$tmpdir/$repo_base" checkout $checkout_opts || exit 1
155+
rm -rf "$tmpdir/$repo_base/.git"
156+
[[ -d "$out_dir" ]] && while true; do
157+
suff=1
158+
if [[ -d "$out_dir-$suff" ]]; then
159+
suff=$(( suff + 1 ))
160+
else
161+
out_dir="$out_dir-$suff"
162+
break
163+
fi
164+
done
165+
mkdir -p "$out_dir"
166+
mv "$tmpdir/$repo_base"/* "$tmpdir/$repo_base"/.* "$out_dir" 2>/dev/null
167+
rm -rf $tmpdir

0 commit comments

Comments
 (0)