【问题标题】:Post-commit script wont export files starting with "@"提交后脚本不会导出以“@”开头的文件
【发布时间】:2013-03-12 20:02:17
【问题描述】:

我正在使用这个提交后脚本(这不是我的工作,我从这里获得)。

#!/bin/bash

REPOS="$1"
REV="$2"

# A - Item added to repository
# D - Item deleted from repository
# U - File contents changed
# _U - Properties of item changed; note the leading underscore
# UU - File contents and properties changed

# Files and directories can be distinguished, as directory paths are displayed with a trailing "/" character.

LOOK=/usr/bin/svnlook
SVN=/usr/bin/svn 
DEV=/var/www/my_web

cd /var/tmp/svn
  for changes in `$LOOK changed $REPOS | awk '{print $1 "=" $2;}'`;
  do
        len=${#changes}
        idx=`expr index "$changes" =`;
        directory=${changes:$idx};
        action=${changes:0:$idx-1};
        if [ ${changes:len-1} = '/' ]
        then
            case "$action" in
                "A" ) \
                    mkdir --mode=775 -p $DEV/$directory;
                    chown www-data:www-data $DEV/$directory;
                    chmod 775 $DEV/$directory;
                    ;;
                "D" ) \
                    rmdir $DEV/$directory;
                    ;;
            esac
        else
            case "$action" in
                "A"|"U"|"UU" ) \
                    $SVN export --force --non-interactive -r HEAD -q file://$REPOS/$directory;
                    BASE=`basename $directory`;
                    DIR=`dirname $directory`;
                    chown www-data:www-data $BASE;
                    chmod 775 $BASE;
                    mkdir --mode=775 -p $DEV/$DIR;
                    cp -f --preserve=ownership $BASE $DEV/$DIR;
                    unlink $BASE;
                    ;;
                "D" ) \
                    rm -f $DEV/$directory;
                    ;;
            esac
        fi
  done

exit 0

脚本完美运行 - 添加/删除文件、文件夹、设置权限,但如果我提交名称为“@layout.latte”的文件,我可以在我的服务器上的 SVN 树中看到这个文件(所以提交工作正常)但发布-commit 脚本不会将此文件复制到我的 /var/www/my_web 文件夹中。

有人知道为什么吗?非常感谢你!我四处寻找,但我没有运气。

编辑:它也不适用于像“test@test.txt”这样的文件。这是因为“@”,但我不知道如何解决它。我认为像逃避这样的事情会有所帮助,但我真的不是一个“bash guy”:)

【问题讨论】:

    标签: bash svn post-commit


    【解决方案1】:

    Subversion URLs 中的@ 有一个特殊的含义——但仅适用于最终的@。您需要在 URL 中将 @ 编码为 %40,或者在 URL 中附加一个结尾的 @

    【讨论】:

    • 你能给我一些代码示例吗?我正在使用 TortoiseSVN 将文件从我的 PC 提交到我使用 Debian 的服务器上的 SVN 存储库,然后 SVN 运行提交后脚本。我不知道此过程中的某个 URL 位于何处。谢谢!
    • 不,您必须在上面发布的挂钩脚本中执行此操作。 file://$REPOS/$directory 是您的网址。
    • 好吧,我在file://$REPOS/$directory; 之后添加了一个@ 就像file://$REPOS/$directory@; 一样,它可以工作'非常感谢! :)
    猜你喜欢
    • 2012-10-23
    • 2019-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-21
    • 2013-09-23
    • 1970-01-01
    相关资源
    最近更新 更多