File size: 2,336 Bytes
e416fd9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# This function is a wrapper for the 'git' command, providing additional functionality for the 'clone' and 'add' operations.
# 
# Usage:
#   git <command> [<args>...]
#
# Parameters:
#   <command> - The git command to execute (e.g., clone, pull, push, add, etc.).
#   [<args>...] - The arguments to pass to the git command.
#
# Functionality:
#   - If the first argument is 'clone', the function executes 'git clone' with the '--recurse-submodules' option.
#     This ensures that all submodules are cloned along with the main repository.
#   - If the first argument is 'add', the function checks if the current directory is inside '~/datasets'.
#     If it is, it checks for the existence of a '.gitattributes' file and runs 'git lfs track "*.jxl"' before executing 'git add'.
#   - For any other git command, the function simply passes all arguments to the 'git' command as-is.
#
# Examples:
#   git clone https://github.com/user/repo.git
#     This will execute 'git clone --recurse-submodules https://github.com/user/repo.git', cloning the repository along with its submodules.
#
#   git add .
#     This will check if the current directory is inside '~/datasets', check for a '.gitattributes' file, and run 'git lfs track "*.jxl"' if the file exists, then execute 'git add .'.
#
#   git pull origin main
#     This will execute 'git pull origin main', pulling the latest changes from the 'main' branch.
#
# Notes:
#   - This function uses 'command' to bypass any other shell functions or aliases named 'git', ensuring that the actual git command is executed.
#   - The use of "${@:2}" in the 'clone' case ensures that all arguments after 'clone' are passed to the 'git clone' command.
#   - The use of "${@:2}" in the 'add' case ensures that all arguments after 'add' are passed to the 'git add' command.
#   - The function checks if the current directory is inside '~/datasets' by comparing the current directory path with the '~/datasets' path.
function git() {
    if [[ "$1" == "clone" ]]; then
        command git clone --recurse-submodules "${@:2}"
    elif [[ "$1" == "add" ]]; then
        if [[ "$(pwd)" == ~/datasets* ]]; then
            if [[ -f .gitattributes ]]; then
                command git lfs track "*.jxl"
            fi
        fi
        command git add "${@:2}"
    else
        command git "$@"
    fi
}