Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions _tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

clear

Expand All @@ -9,8 +9,8 @@ set -euo pipefail
}
PATH=$(pwd):$PATH

which git
git --version
source "$(dirname "$0")/git-artifact"
check_environment

cd .test
root_folder=$(pwd)
Expand All @@ -22,7 +22,6 @@ remote_tester_repo=.remote
clone_tester_repo=.clone
global_exit_code=0


function testcase_header() {
[[ ${verbose:-} == true ]] || return 0
echo
Expand Down
92 changes: 70 additions & 22 deletions git-artifact
Original file line number Diff line number Diff line change
@@ -1,30 +1,70 @@
#!/bin/bash
#!/usr/bin/env bash
#
# git-artifact: use a git repository as artifact management storage
#

if test -z "$GIT_EXEC_PATH" || ! test -f "$GIT_EXEC_PATH/git-sh-setup" || {
test "${PATH#"${GIT_EXEC_PATH}:"}" = "$PATH" &&
test ! "$GIT_EXEC_PATH" -ef "${PATH%%:*}" 2>/dev/null
function check_environment() {
if [[ "${BASH_VERSINFO:-}" == "" ]] ; then
echo "ERROR: git-artifact only runs in bash - please check that the variable BASH_VERSINFO is set"
echo "BASH_VERSINFO: ${BASH_VERSINFO:-unknown}"
echo "BASH_VERSION: ${BASH_VERSION:-unknown}"
echo "SHELL: ${SHELL:-unknown}"
exit 1
fi

if [[ "${BASH_VERSINFO[0]}" -lt 4 ]]; then
echo "ERROR: git-artifact requires Bash version 4.3 or higher."
echo "BASH_VERSINFO: ${BASH_VERSINFO:-unknown}"
echo "BASH_VERSION: ${BASH_VERSION:-unknown}"
exit 1
elif [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -lt 3 ]]; then
echo "ERROR: git-artifact requires Bash version 4.3 or higher."
echo "BASH_VERSINFO: ${BASH_VERSINFO:-unknown}"
echo "BASH_VERSION: ${BASH_VERSION:-unknown}"
exit 1
fi

}

function check_git_environment() {
if test -z "$GIT_EXEC_PATH" || ! test -f "$GIT_EXEC_PATH/git-sh-setup" || {
test "${PATH#"${GIT_EXEC_PATH}:"}" = "$PATH" &&
test ! "$GIT_EXEC_PATH" -ef "${PATH%%:*}" 2>/dev/null
}
then
basename=${0##*[/\\]}
echo >&2 'It looks like your git installation broken'
echo >&2
echo >&2 "Tips:"
echo >&2 " - If \`git --exec-path\` does not print the correct path to"
echo >&2 " your git install directory, then set the GIT_EXEC_PATH"
echo >&2 " environment variable to the correct directory."
echo >&2 " - Make sure that your \`$basename\` file is either in your"
echo >&2 " PATH or in your git exec path (\`$(git --exec-path)\`)."
echo >&2 " - You should run git-subtree as \`git ${basename#git-}\`,"
echo >&2 " not as \`$basename\`." >&2
exit 126
fi

}

function show_info() {
echo "git-artifact: use a git repository as artifact management storage"
echo "Version: $(git --version | cut -d ' ' -f 3)"
echo "Bash version: ${BASH_VERSION:-unknown}"
echo "Bash version info: ${BASH_VERSINFO[*]:-unknown}"
echo "Git exec path: ${GIT_EXEC_PATH:-unknown}"
echo "Git version: $(git --version)"
}
then
basename=${0##*[/\\]}
echo >&2 'It looks like either your git installation or your'
echo >&2 'git-subtree installation is broken.'
echo >&2
echo >&2 "Tips:"
echo >&2 " - If \`git --exec-path\` does not print the correct path to"
echo >&2 " your git install directory, then set the GIT_EXEC_PATH"
echo >&2 " environment variable to the correct directory."
echo >&2 " - Make sure that your \`$basename\` file is either in your"
echo >&2 " PATH or in your git exec path (\`$(git --exec-path)\`)."
echo >&2 " - You should run git-subtree as \`git ${basename#git-}\`,"
echo >&2 " not as \`$basename\`." >&2
exit 126
fi

function set_opts_spec() {
# Set the options specification for git rev-parse --parseopt
# This is used to parse command line arguments
# It is used in the main function to set the arguments
# It is also used in the cmd_* functions to parse the arguments
# It is also used in the git artifact help command to show the options
#inspiration: https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh
OPTS_SPEC="\
OPTS_SPEC="\
git artifact commmand <options>

commands:
Expand Down Expand Up @@ -61,6 +101,7 @@ r,regex= the reg-ex pattern to latest of
options for 'fetch-tags'
s,sha1= The sha1 of which to get tags from from
"
}

debug () {
if test -n "$arg_debug"
Expand Down Expand Up @@ -395,6 +436,7 @@ main () {
done
arg_command=$1
shift

which git-sh-setup
case "$arg_command" in
init) if test -z "${arg_remoteurl:-}" ; then
Expand Down Expand Up @@ -485,5 +527,11 @@ main () {
"cmd_$arg_command" "$@"
}


main "$@"
# Only run main if not being sourced
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
check_environment
check_git_environment
[[ ${arg_debug:-} == true ]] && show_info
set_opts_spec
main "$@"
fi