【问题标题】:Tracking file permissions in Git. Error running git-cache-meta: "find: you have too many ')'"在 Git 中跟踪文件权限。运行 git-cache-meta 时出错:“发现:你有太多 ')'”
【发布时间】:2015-03-15 10:38:47
【问题描述】:

我目前正在尝试实现this recommendation,以便在进行 Git 克隆时能够保留文件权限。但是,当我运行命令时,我收到此错误。

$ git-cache-meta.sh --store
find: you have too many ')'

之前的一个错误是关于 Git 列出的文件过多(我正在跟踪大约 2.5GB 的文件,据我所知这已经突破了单个 Git 项目的限制)。

是不是我在初始化shell脚本时做错了什么(我用了here列出的主代码:

1.  #!/bin/sh -e
2.  
3.  #git-cache-meta -- simple file meta data caching and applying.
4.  #Simpler than etckeeper, metastore, setgitperms, etc.
5.  #from http://www.kerneltrap.org/mailarchive/git/2009/1/9/4654694
6.  #modified by n1k
7.  # - save all files metadata not only from other users
8.  # - save numeric uid and gid
9.
10. # 2012-03-05 - added filetime, andris9
11.
12. : ${GIT_CACHE_META_FILE=.git_cache_meta}
13. case $@ in
14. --store|--stdout)
15. case $1 in --store) exec > $GIT_CACHE_META_FILE; esac
16. find $(git ls-files)\
17.     \( -printf 'chown %U %p\n' \) \
18.     \( -printf 'chgrp %G %p\n' \) \
19.     \( -printf 'touch -c -d "%AY-%Am-%Ad %AH:%AM:%AS" %p\n' \) \
20.     \( -printf 'chmod %#m %p\n' \) ;;
21. --apply) sh -e $GIT_CACHE_META_FILE;;
22. *) 1>&2 echo "Usage: $0 --store|--stdout|--apply"; exit 1;;
23. esac

但我没有使用任何修订版,这似乎解决了不同的问题)。该页面上报告的几个错误似乎与文件名中的特定字符有关,但通过查看,我找不到任何可能引发我遇到的错误的“(”或“)”。

如果它与尝试跟踪太多文件有关,那么在将文件部署到 Git 时是否有任何建议来维护文件权限和所有者元数据?

【问题讨论】:

  • 如果您将set -x 添加到该脚本,您会看到什么查找命令?
  • 对不起,我对shell命令不是很熟悉,但是我应该在哪一行添加呢?
  • find 命令之前的任何地方都可以。制作 shebang 线 -ex 也适用于这种情况。

标签: git shell


【解决方案1】:

试试这个:

function get_metadata {
    git ls-files | 
    xargs stat -c $'%a\t%U\t%G\t%x\t%n' | 
    while IFS=$'\t' read -r perm user grp date name; do 
        echo chown "$user" "$name"
        echo chgrp "$grp" "$name"
        echo chmod "$perm" "$name"
        echo touch -c -d "'$date'" "$name"
    done
}

case $1 in
    --stdout) get_metadata ;;
    --store)  get_metadata > "$GIT_CACHE_META_FILE" ;;
    --apply)
        [[ -f "$GIT_CACHE_META_FILE" ]] &&
        sh "$GIT_CACHE_META_FILE"
        ;;
    *) echo "usage: ..." ;;
esac

这假定您的文件名都不包含换行符。

【讨论】:

    猜你喜欢
    • 2012-10-27
    • 2015-10-09
    • 1970-01-01
    • 2019-10-23
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 2015-12-25
    相关资源
    最近更新 更多