diff --git a/git-fatlas.sh b/git-fatlas.sh index 619773d..61b349e 100644 --- a/git-fatlas.sh +++ b/git-fatlas.sh @@ -11,7 +11,7 @@ # the main athena repo and use release 21.2. # _git-fatlas-init_usage() { - echo "usage: $1 [-h] [-r release] [-u URL] [-s SHARED]" + echo "usage: $1 [-h] [-v] [-r release] [-u URL] [-s SHARED]" } function git-fatlas-init() ( @@ -22,10 +22,11 @@ function git-fatlas-init() ( local RELEASE=main local URL=${GIT_FATLAS_UPSTREAM} local SHARED="" + VLOG=/dev/null # parse options local opt - while getopts ":hr:u:s:" opt $@; do + while getopts ":hvr:u:s:" opt $@; do case $opt in h) _git-fatlas-init_usage $FUNCNAME; cat < $VLOG + git checkout ${RELEASE} + + echo caching package list > $VLOG + git-fatlas-remake-package-list > $VLOG ) @@ -136,19 +137,26 @@ function git-fatlas-remake-package-list() { # the working tree. There are also tab complete functions defined # below. # -function git-fatlas-add() ( - set -eu +function git-fatlas-add() { + + local LOG=${TABTEST-/dev/null} + + echo "--- trying to add a package ---" >> $LOG local pkg_list=$(git-fatlas-get-package-list) - local SP=.git/info/sparse-checkout - local STUB - local FULLPATH - for STUB in ${@:1} ; do - egrep "(^|/)${STUB%/}(/|$)" $pkg_list | while read FULLPATH; do - echo ${FULLPATH%/}/ | tee -a $SP - done - done - git checkout HEAD -) + echo "matching against $pkg_list" >> $LOG + echo "looking for: $1" >> $LOG + local reply=( $(fgrep ${1} $pkg_list | egrep "(/|^)$1$") ) + echo "matches ${reply[*]}" >> $LOG + + if (( ${#reply[*]} > 1 )); then + echo "ERROR: too many replies" | tee -a $LOG 2>&1 + return 1 + elif (( ${#reply[*]} == 0 )); then + echo "ERROR: no matches" | tee -a $LOG 2>&1 + return 1 + fi + git sparse-checkout add ${reply[*]} +} # ____________________________________________________________________ # Add a new package to the repo @@ -156,9 +164,8 @@ function git-fatlas-add() ( # If you already have something in the working tree and want to check # it in, you should call this function on it. # -function git-fatlas-new() { - local SP=.git/info/sparse-checkout - local STUB +function git-fatlas-new() ( + pkg_list=$(git-fatlas-get-package-list) for STUB in ${@:1} ; do if [[ ! -d ${STUB} ]]; then echo "${STUB} is not a directory" 2>&1 @@ -170,10 +177,11 @@ contain this EOF return 1 fi - echo ${STUB%/}/ | tee -a $SP + echo ${STUB%/} >> $pkg_list + git-fatlas-add ${STUB%/} git add ${STUB%/}/ done -} +) # ____________________________________________________________________ # Remove package @@ -181,20 +189,10 @@ EOF # This one is a bit tricky in that we have to make sure we don't # remove the last package. Git doesn't like that for some reason. # -function git-fatlas-remove() { - local SP=.git/info/sparse-checkout - local TMP=$(cat $SP | sort -u | egrep -v $1) - if [[ ${TMP} == '' ]]; then - echo "ERROR: can't remove last package" 1>&2 - return 1 - fi - local FILE - rm $SP - for FILE in $TMP; do - echo $FILE >> $SP - done - git checkout HEAD -} +function git-fatlas-remove() ( + local NEW=$(git sparse-checkout list | egrep -v $1 | tr '\n' ' ') + git sparse-checkout set $NEW +) # ____________________________________________________________________ # Update copyright statements @@ -214,27 +212,43 @@ function git-fatlas-copyright-update() { # ____________________________________________________________________ # Tab complete function for the add utility # +# if you set TABTEST and then read it with `tail -f` you will see some +# logging info function _git-fatlas-add() { + local LOG=${TABTEST-/dev/null} + # build or get package list + echo "--- getting package list ---" >> $LOG + echo "looking for: $2" >> $LOG local pkg_list=$(git-fatlas-get-package-list) + echo "got $pkg_list" >> $LOG # first check for completion from the root up + echo "checking matches in package list" >> $LOG COMPREPLY=( $(compgen -W "$(cat $pkg_list)" -- $2 ) ) if [[ ${#COMPREPLY[*]} != 0 ]]; then + echo "returning ${#COMPREPLY[*]} matches" >> $LOG return 0 fi # then check for a unique fgrep match + echo "checking with fgrep" >> $LOG COMPREPLY=( $(fgrep ${2} $pkg_list ) ) if [[ ${#COMPREPLY[*]} == 1 ]]; then + echo "returning ${#COMPREPLY[*]} matches" >> $LOG return 0 fi - - # then check to see if any part of the package name matches note - # that we can't include the full path because that will trigger a - # completion to any stub that is shared among all matches. + echo "got ${#COMPREPLY[*]} replies, moving on" >> $LOG + + # then check to see if any part of the package name matches + # + # note that we can't include the full path because that will + # trigger a completion to any stub that is shared among all + # matches. + echo "checking with fgrep, excluding some patterns" >> $LOG COMPREPLY=( $(fgrep ${2} $pkg_list | egrep -o "[^/]*$2.*") ) + echo "returning ${#COMPREPLY[*]} matches" >> $LOG return 0 } complete -F _git-fatlas-add git-fatlas-add