Browse Source

Include files based on `git diff` instead of `grep`

When including untracked files, grep was used to find the tracked source
file in the list of changed files. Now, git-diff is used to detect the
change. It allows to use source files outside of $SYNCROOT.

Source file paths starting with / are seen relative to the Git working
tree, even if --syncroot is specified.
pull/251/head
Maikel Linke 9 years ago
parent
commit
45d1703a6b
  1. 20
      git-ftp
  2. 6
      man/git-ftp.1.md
  3. 19
      tests/git-ftp-test.sh

20
git-ftp

@ -618,18 +618,16 @@ add_include_files() {
grep '^!' "$TMP_GITFTP_INCLUDE" | sed 's/^!//' | while read TARGET; do
add_include_file "$TARGET"
done
# test if grep knows --null-data (GNU grep) or not (OSX grep)
if echo 'test' | grep -q --null-data 'test' 2> /dev/null; then
cat "$TMP_GITFTP_UPLOAD" "$TMP_GITFTP_DELETE" > "$tmp_include_sources"
grep_cmd='grep --null-data'
else
cat "$TMP_GITFTP_UPLOAD" "$TMP_GITFTP_DELETE" | tr "\0" "\n" > "$tmp_include_sources"
grep_cmd='grep'
fi
local AGAINST="${DEPLOYED_SHA1:-"$(git hash-object -t tree /dev/null)"}"
grep ':' "$TMP_GITFTP_INCLUDE" | while read LINE; do
local TARGET=${LINE%%:*}
local SOURCE=${LINE#*:}
if $grep_cmd -Fxq "$SOURCE" "$tmp_include_sources"; then
local TARGET="${LINE%%:*}"
local SOURCE="${LINE#*:}"
if echo "$SOURCE" | grep '^/'; then
SOURCE="${SOURCE%%/*}"
elif [ -n "$SYNCROOT" ]; then
SOURCE="$SYNCROOT/$SOURCE"
fi
if ! git diff --quiet "$AGAINST" -- "$SOURCE"; then
add_include_file "$TARGET"
fi
done

6
man/git-ftp.1.md

@ -246,6 +246,12 @@ Whenever one of the tracked files changes, the upload of the paired untracked fi
If a local untracked file is deleted, a paired tracked file will trigger the deletion of the remote file on the server.
When using the `--syncroot` option, all paths are relative to the set syncroot.
If your source file is outside the syncroot, add a / and define a path relative to the Git working directory.
# upload "dist/style.css" with syncroot "dist"
style.css:/style.scss
It is also possible to upload whole directories.
For example, if you use a package manager like composer, you can upload all vendor packages when the file composer.lock changes:

19
tests/git-ftp-test.sh

@ -440,11 +440,9 @@ test_ignore_wildcard_files() {
}
test_include_init() {
cd $GIT_PROJECT_PATH
echo 'unversioned' > unversioned.txt
echo 'unversioned.txt' >> .gitignore
echo 'unversioned.txt:test 1.txt' > .git-ftp-include
echo 'new content' >> 'test 1.txt'
git add .
git commit -m 'unversioned file unversioned.txt should be uploaded with test 1.txt' > /dev/null
init=$($GIT_FTP init)
@ -596,6 +594,23 @@ test_include_similar() {
assertTrue 'templates/foo.html was not uploaded' "remote_file_exists 'templates/foo.html'"
}
# resolves issue #245
test_include_syncroot() {
syncroot="dist"
targetfile="main.css"
target="$syncroot/$targetfile"
source="main.scss"
touch "$source"
mkdir "$syncroot"
touch "$target"
echo "$syncroot" > ".gitignore"
echo "$target:/$source" > ".git-ftp-include"
git add . > /dev/null
git commit -a -m "test uploading only dist files" -q
init=$($GIT_FTP init --syncroot "$syncroot")
assertTrue "remote file '$targetfile'" "remote_file_exists '$targetfile'"
}
test_hidden_file_only() {
cd $GIT_PROJECT_PATH
echo "test" > .htaccess

Loading…
Cancel
Save