2012-04-07 57 views
1

我的一些(Mac OS)文件需要具有文本类型的文本。我不是在谈论扩展,而是扩展属性。该功能被git遗失。如何在Git工作树中的某些文件上更改(旧式Mac OS)文件类型?

所以我需要对具有特定扩展名的文件运行SetFile命令,但我还没有想出如何去做。我只需要在结帐方向上执行此操作 - 在提交期间不需要保存任何内容。

我看过Ruby脚本作为涂抹过滤器,但不知道如何获取文件名。这是正确的方法还是会更好?

(我有超过需要的文件没有控制权类型 - 这是一个遗留系统,我无法改变它的工作方式。)

回答

0

git hooks --help

post-checkout 
    This hook is invoked when a git checkout is run after having updated 
    the worktree. The hook is given three parameters: the ref of the 
    previous HEAD, the ref of the new HEAD (which may or may not have 
    changed), and a flag indicating whether the checkout was a branch 
    checkout (changing branches, flag=1) or a file checkout (retrieving a 
    file from the index, flag=0). This hook cannot affect the outcome of 
    git checkout. 

所以你可以有一个后结账挂钩,可以在工作树中所有具有特定扩展名的文件上运行,并在其上调用SetFile。这并不完美,因为它会重新对未更改的文件执行操作,并且在git reset --hard之后完全不会运行,但可能满足您的需要。

一结账后挂机,将名为*.txt的所有文件(但没有其他人)这样做是很简单的:

#! /bin/sh 
git ls-files -z -- '*.txt' | xargs -0 SetFile -t TEXT 

-z-0做这项工作的硬壳路径名(包含嵌入式的人例如空间)。

+0

torek,非常感谢。我将您的代码完全粘贴到您提交的结账后,并且第一次运行! – wscole 2012-04-09 20:18:44