X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=gitget;h=e177a30f730f22b559451ff0a00b6d9bd9d3347f;hb=HEAD;hp=a61c11479b850f9b2642e14a67ec38edf387f1e2;hpb=fa048d95038ff8cb5d53dd9b9e20c25215791134;p=small-misc-bash diff --git a/gitget b/gitget index a61c114..e177a30 100755 --- a/gitget +++ b/gitget @@ -1,5 +1,12 @@ #!/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. @@ -13,6 +20,7 @@ # 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 @@ -38,23 +46,11 @@ REPO_DIR is, or will become the root of the repo." 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"