From 45d1703a6b6f1172bafe87f9265d8b1e0800ee58 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 25 Mar 2016 16:40:57 +1100 Subject: [PATCH] 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. --- git-ftp | 20 +++++++++----------- man/git-ftp.1.md | 6 ++++++ tests/git-ftp-test.sh | 19 +++++++++++++++++-- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/git-ftp b/git-ftp index 49a2560..fe85c94 100755 --- a/git-ftp +++ b/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 diff --git a/man/git-ftp.1.md b/man/git-ftp.1.md index 5316e6b..979e11b 100644 --- a/man/git-ftp.1.md +++ b/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: diff --git a/tests/git-ftp-test.sh b/tests/git-ftp-test.sh index 7af2848..aec7cf7 100755 --- a/tests/git-ftp-test.sh +++ b/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