summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgit-shell-commands/change-description13
-rwxr-xr-xgit-shell-commands/change-owner14
-rwxr-xr-xgit-shell-commands/create-bare-repo17
-rwxr-xr-xgit-shell-commands/delete-repo13
-rwxr-xr-xgit-shell-commands/fetch-mirrors11
-rwxr-xr-xgit-shell-commands/help6
-rwxr-xr-xgit-shell-commands/hook-install17
-rwxr-xr-xgit-shell-commands/mirror6
-rwxr-xr-xgit-shell-commands/mirrors4
9 files changed, 55 insertions, 46 deletions
diff --git a/git-shell-commands/change-description b/git-shell-commands/change-description
index 730777c..60db0ac 100755
--- a/git-shell-commands/change-description
+++ b/git-shell-commands/change-description
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# * change-description
# Cambia la descripcion del projecto, necesita archivo description en el proyecto
# ssh git@host change-description repo "description"
@@ -7,6 +7,13 @@ set -e
repo=$1; shift
-test -d ${repo}.git && echo "${@}" > ${repo}.git/description
+repo="$(sed -r 's,^/*,,' <<<"$repo")"
+_repo="$(sed -r -e '/(^|\/)\.\.($|\/)/d' -e "s,[^A-Za-z0-9\./_~-],,g" <<<"$repo")"
+test "$repo" = "$_repo" || { printf 'Illegal name: %s\n' "${repo}"; exit 1; }
-exit $?
+if test -d "$repo".git; then
+ echo "${*}" > "${repo}".git/description
+else
+ printf 'Does not exist: %s\n' "${repo}"
+ exit 1
+fi
diff --git a/git-shell-commands/change-owner b/git-shell-commands/change-owner
index 4cf90c7..6b6f353 100755
--- a/git-shell-commands/change-owner
+++ b/git-shell-commands/change-owner
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# * change-owner
# Define quiƩn manda
# ssh git@host change-owner repo "Hacklab"
@@ -7,7 +7,13 @@ set -e
repo=$1; shift
-test -d "${repo}".git && \
-git config -f "${repo}.git/config" "gitweb.owner" "${@}"
+repo="$(sed -r 's,^/*,,' <<<"$repo")"
+_repo="$(sed -r -e '/(^|\/)\.\.($|\/)/d' -e "s,[^A-Za-z0-9\./_~-],,g" <<<"$repo")"
+test "$repo" = "$_repo" || { printf 'Illegal name: %s\n' "${repo}"; exit 1; }
-exit $?
+if test -d "${repo}".git; then
+ git config -f "${repo}.git/config" "gitweb.owner" "${*}"
+else
+ printf 'Does not exist: %s\n' "${repo}"
+ exit 1
+fi
diff --git a/git-shell-commands/create-bare-repo b/git-shell-commands/create-bare-repo
index 3051c9d..b4d2d5f 100755
--- a/git-shell-commands/create-bare-repo
+++ b/git-shell-commands/create-bare-repo
@@ -1,17 +1,18 @@
-#!/bin/sh
+#!/bin/bash
# * create-bare-repo
# Allows users to create repo.git
# ssh git@host create-bare-repo repo1 repo2 ...
set -e
-for repo in $@; do
-# Cleanup names, allow hidden repos
- repo="`echo "$repo" | sed -e "s/\.\.//g" -e "s,^/\+,,g" -e "s,[^a-z0-9\./_-],,gi"`"
- test -d "$repo".git && continue
+for repo in "$@"; do
+ repo="$(sed -r 's,^/*,,' <<<"$repo")"
+ _repo="$(sed -r -e '/(^|\/)\.\.($|\/)/d' -e "s,[^A-Za-z0-9\./_~-],,g" <<<"$repo")"
+ test "$repo" != "$_repo" && { printf 'Illegal name: %s\n' "${repo}"; continue; }
+ test -d "$repo".git && { printf 'Already exists: %s\n' "${repo}"; continue; }
- mkdir -p "$repo".git
- pushd "$repo".git
+ mkdir -p -- "$repo".git
+ pushd "$repo".git >/dev/null
git init --bare
- popd
+ popd >/dev/null
done
diff --git a/git-shell-commands/delete-repo b/git-shell-commands/delete-repo
index 4ca644e..5ef94b1 100755
--- a/git-shell-commands/delete-repo
+++ b/git-shell-commands/delete-repo
@@ -1,16 +1,17 @@
-#!/bin/sh
+#!/bin/bash
# * delete-repo
# Allows users to delete repositories permanently
# ssh git@host delete-repo repo1 repo2 ...
set -e
-for repo in $@; do
-# Remove leading slashes and dots and perform cleanup
- repo="`echo "$repo" | sed -e "s/\.\.//g" -e "s,^/\+,,g" -e "s,[^a-z0-9\./_-],,gi"`"
- test ! -d "$repo".git && continue
+for repo in "$@"; do
+ repo="$(sed -r 's,^/*,,' <<<"$repo")"
+ _repo="$(sed -r -e '/(^|\/)\.\.($|\/)/d' -e "s,[^A-Za-z0-9\./_~-],,g" <<<"$repo")"
+ test "$repo" != "$_repo" && { printf 'Illegal name: %s\n' "${repo}"; continue; }
+ test ! -d "$repo".git && { printf 'Does not exist: %s\n' "${repo}"; continue; }
echo "Removing ${repo}.git"
# lo and behold absolute horror
- rm -rf "$repo".git
+ rm -rf -- "$repo".git
done
diff --git a/git-shell-commands/fetch-mirrors b/git-shell-commands/fetch-mirrors
index a9442ba..15bf9c4 100755
--- a/git-shell-commands/fetch-mirrors
+++ b/git-shell-commands/fetch-mirrors
@@ -6,15 +6,8 @@
set -e
# Find all mirrors
-~/git-shell-commands/mirrors | \
- while read _mirror; do
-
- pushd "$_mirror" >/dev/null
-
+"$(dirname "$0")"/mirrors | while read -r mirror; do
+ pushd "$mirror" >/dev/null
git remote update
-
popd >/dev/null
-
done
-
-exit $?
diff --git a/git-shell-commands/help b/git-shell-commands/help
index e707df8..f1d116b 100755
--- a/git-shell-commands/help
+++ b/git-shell-commands/help
@@ -5,8 +5,8 @@
set -e
-# Gets three lines from every git-shell-command
-for c in `dirname $0`/*; do
- head -q -n4 $c | tail -n3 | sed "s/^..//"
+# Gets the initial comment after the shebeng from every git-shell-command
+for c in "$(dirname "$0")"/*; do
+ sed -rn '2,/^[^#]/s/^# ?//p' "$c"
echo
done
diff --git a/git-shell-commands/hook-install b/git-shell-commands/hook-install
index 08a0340..b38836a 100755
--- a/git-shell-commands/hook-install
+++ b/git-shell-commands/hook-install
@@ -5,19 +5,24 @@
set -e
+exit 1 # I don't trust this script
+
hook="${1}"
script="${HOME}/.ssh/git-hooks/${2}"
-repo="${HOME}/${3}"
+repo="${3}"
clone="${4:-${repo}}"
+repo="$(sed -r 's,^/*,,' <<<"$repo")"
+_repo="$(sed -r -e '/(^|\/)\.\.($|\/)/d' -e "s,[^A-Za-z0-9\./_~-],,g" <<<"$repo")"
+test "$repo" = "$_repo" || { printf 'Illegal name: %s\n' "${repo}"; exit 1; }
+test -d "$repo".git || { printf 'Does not exist: %s\n' "${repo}"; exit 1; }
+
# Tests
-test -f "${repo}/HEAD"
+test -f "${repo}.git/HEAD"
test -f "${clone}/.git/HEAD"
# Installs the generic hook that runs scripts
-test -f "${repo}/hooks/${hook}" || ln -s "${HOME}/.ssh/git-hooks/generic" "${repo}/hooks/${hook}"
+test -f "${repo}.git/hooks/${hook}" || ln -s "${HOME}/.ssh/git-hooks/generic" "${repo}.git/hooks/${hook}"
# Install the hook on the repo
-git config -f "${repo}/config" --add "hacking.hooks.${hook}.${2}" "${clone}"
-
-exit $?
+git config -f "${repo}.git/config" --add "hacking.hooks.${hook}.${2}" "${clone}"
diff --git a/git-shell-commands/mirror b/git-shell-commands/mirror
index 212687e..8282e9b 100755
--- a/git-shell-commands/mirror
+++ b/git-shell-commands/mirror
@@ -5,8 +5,6 @@
set -E
-for _m in $@; do
- git clone --mirror $_m
+for _m in "$@"; do
+ git clone --mirror "$_m"
done
-
-exit $?
diff --git a/git-shell-commands/mirrors b/git-shell-commands/mirrors
index d1301a8..436564f 100755
--- a/git-shell-commands/mirrors
+++ b/git-shell-commands/mirrors
@@ -6,6 +6,4 @@
set -e
# Find all mirrors
-find *.git -maxdepth 1 -iname config -print0 | \
- xargs -0 grep -l 'mirror = true' | \
- sed 's,/config$,,'
+find $(find * -name '*.git' -type d) -maxdepth 1 -name config -exec grep -l 'mirror\s*=\s*true' {} + | sed 's,/config$,,'