2012-04-07 21 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

相關問題