From 635ee5cbe72443b9b9b7a1e38e4178193b832d98 Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Sat, 29 Sep 2018 13:01:14 +1000 Subject: [PATCH] add_repo: make into a /bin/sh script and general style clean up --- add_repo | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/add_repo b/add_repo index 98cf1ae..f97551e 100755 --- a/add_repo +++ b/add_repo @@ -1,20 +1,28 @@ -#!/bin/bash +#!/bin/sh -name=$1 -url=$2 -branch=$3 -[[ -z "$name" ]] && { - echo "Need a remote name" 1>&2 +if [ $# -lt 2 ] || [ $# -gt 3 ]; then + printf 'usage: %s []\n' "$0" 1>&2 exit 1 -} -[[ -z "$url" ]] && { - echo "Need a URL" 1>&2 - exit 1 -} -[[ -z "$branch" ]] && branch="master" +fi + +name="$1" +url="$2" +branch="$3" -git remote add --no-tags -t "$branch" "$name" "$url" +if [ -z "$name" ]; then + printf 'Need a remote name\n' 1>&2 + exit 1 +fi +if [ -z "$url" ]; then + printf 'Need a URL\n' 1>&2 + exit 1 +fi +if [ -z "$branch" ]; then + branch='master' +fi -cp .git/config ../etc/git-config +if git remote add --no-tags -t "$branch" "$name" "$url"; then + cp .git/config ../etc/git-config +fi exit 0 -- 2.39.5