#!/bin/bash

add-git-folder() {
    if [[ -z "$1" ]]; then
        echo '$1/url is empty.'
        exit
    fi
    if [[ -z "$2" ]]; then
        echo '$2/branch is empty.'
        exit
    fi
    if [[ -z "$3" ]]; then
        echo '$3/path is empty.'
        exit
    fi
    local url="$1"
    local branch="$2"
    local path="$3"
    
    # Add entry to .gitmodules
    git config -f .gitmodules submodule."$path".path "$path"
    git config -f .gitmodules submodule."$path".url "$url"
    git config -f .gitmodules submodule."$path".branch "$branch"

    # Clone
    clone-git-folder "$path"

    # Save commit ref
    save-git-folder
}
agf() {
    add-git-folder "$@"
}
