Small hick-up: the script works under OS X (and I'll assume under Linux) but not in the git shell under Windows. I should be able to use a separate batch script for Windows but it would be easiest if a single script was cross platform.
Hmph.
Cheers,
E. ————— Eliot Kimber, Owner Contrext, LLC http://contrext.com
On 3/22/15, 3:44 PM, "Eliot Kimber" ekimber@contrext.com wrote:
Cool,
Thanks for all the info. I knew it was due to my very weak understanding of bash scripting.
The improved script you suggested worked. I'll do the reading necessary to understand *why* it works, but that gets me over the immediate hurdle.
Cheers,
E. ————— Eliot Kimber, Owner Contrext, LLC http://contrext.com
On 3/22/15, 11:51 AM, "Charles Duffy" charles@dyfis.net wrote:
[Eliot, apologies for the duplicate mail -- I just realized that my initial replies weren't CC'd to the list. Note that this fixes a bug in the last version I sent you privately; please use it in preference].
Please see BashFAQ #50: http://mywiki.wooledge.org/BashFAQ/050; argument lists should be handled as arrays, not strings.
...also, see BashFAQ #1, http://mywiki.wooledge.org/BashFAQ/001, and (for the same reason) http://mywiki.wooledge.org/DontReadLinesWithFor
A better version of this script might look like:
#!/bin/bash # ^-- MUST NOT BE /bin/sh
addOrUpdate() { git diff HEAD^ HEAD --name-only --diff-filter=AM; } basexOptions=( -U admin -P admin -p 1984 -n localhost )
while read -r line; do cmd=( basexclient -c "OPEN $basexDatabase; REPLACE $line $topDir/$line; EXIT" "${basexOptions[@]}" ) printf 'Running: '; printf '%q ' "${cmd[@]}"; printf '\n' "${cmd[@]}" done < <(addOrUpdate)
On Sun, Mar 22, 2015 at 11:31 AM, Eliot Kimber ekimber@contrext.com wrote:
I'm trying to implement agit commit hook that updates a BaseX database with updates committed to the git repo (the BaseX database is being used for search and link management).
My script is here:
https://github.com/dita-for-small-teams/dfst-git-commit-hooks/blob/devel o p/ post-commit
The important code is:
addOrUpdate="git diff HEAD^ HEAD --name-only --diff-filter=AM"
# echo "Adding/Updating files:" for line in `${addOrUpdate}`; do cmd="basexclient -c "OPEN ${basexDatabase};REPLACE ${line} ${topDir}/${line};EXIT" ${basexOptions}" echo "Running cmd: ${cmd}" $($cmd) done
When I run the script I'm getting this response:
Contrext01:docs ekimber$ ../../dita-for-small-teams/commit-hooks/git/post-commit Running cmd: basexclient -c "OPEN sample-project;REPLACE docs/topic-01.dita
/Users/ekimber/workspace-dfst/dfst-sample-project/docs/docs/topic-01.dit a ;E XIT" -U admin -P admin -p 1984 -n localhost Stopped at , 1/6: Unknown command: "OPEN. Did you mean 'OPEN'? Contrext01:docs ekimber$
If I copy the command from the message and run it directly from the command line it works as expected.
There must be some subtlety of using base in this context but my bash fu is weak and I have no idea what I'm doing wrong--I can't see any obvious user error but there must be one.
Can anyone tell me what my bash scripting mistake is?
Is there a better way to do this sort of scripted interaction with basex? It didn't appear that BaseX scripts provided a way to take parameters--if they could then I'd just call a .bxs script with the relevant parameters. Short of generating the script and then running it, I couldn't think of a simpler way to do what I want that just using the -c option on the basexclient command.
Thanks,
Eliot
————— Eliot Kimber, Owner Contrext, LLC http://contrext.com