#!/bin/bash
-# Copyright (C) 2016 Ian Kelling
+# I, Ian Kelling, follow the GNU license recommendations at
+# https://www.gnu.org/licenses/license-recommendations.en.html. They
+# recommend that small programs, < 300 lines, be licensed under the
+# Apache License 2.0. This file contains or is part of one or more small
+# programs. If a small program grows beyond 300 lines, I plan to switch
+# its license to GPL.
+
+# Copyright 2024 Ian Kelling
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# See the License for the specific language governing permissions and
# limitations under the License.
+
gitget() {
local help="Usage: gitget [--help] [REPO_URL] [REPO_DIR]
Idempotent git clone/pull
local workingdir
local orig_dir="$PWD"
local ret
- if [[ $1 == *[^/].git ]]; then
- if [[ $2 ]]; then
- workingdir="$2"
- else
- workingdir="${1##*/}"
- workingdir="${workingdir%.git}"
- fi
- elif (( $# == 2 )); then
- echo error: 2 arguments given but the first does not end in .git
- echo "$help"
- return 1
+ if [[ $2 ]]; then
+ workingdir="$2"
else
- workingdir="$1"
- if [[ ! -d $workingdir/.git ]]; then
- echo "error: expected $workingdir/.git to exist"
- return 1
- fi
+ workingdir="${1##*/}"
+ workingdir="${workingdir%.git}"
fi
[[ -d $workingdir ]] || mkdir -p "$workingdir"
cd "$workingdir"