close

windows 不支援 linux file permission 

所以是看不出來 permission 有沒有設對

必須使用 git command

git ls-file 看目前 permission

git ls-files -s -- *.sh

git update-index 修改 script permission

git update-index --chmod=+x script.sh

除了手動還有一個自動方式可以修改 就是使用 git commit hooks

在 <repository root>/.git/hooks/pre-commit 寫程式改

#!/usr/bin/env python
import subprocess

if __name__ == '__main__':
  output = subprocess.check_output(["git", "ls-files", "-s", "--", "*.sh"], shell=True).decode("utf-8") # type: str
  files_to_fix = []
  for line in output.splitlines():
    # Example for "line": '100644 82f6a7d558e1b38c8b47ec5084fe20f970f09981 0 test-update.sh'
    entry = line.replace('\t', ' ').split(" ", maxsplit=3)
    mode = entry[0][3:] # strips the first 3 chars ("100") which we don't care about
    filename = entry[3]
    if mode == "644":
      files_to_fix.append(filename)
  for file_path in files_to_fix:
    # git update-index --chmod=+x script.sh
    subprocess.check_call(["git", "update-index", "--chmod=+x", file_path], shell=True)

https://www.augmentedmind.de/2020/05/10/commit-executable-shell-scripts-with-git/

arrow
arrow
    全站熱搜

    JohnDX 發表在 痞客邦 留言(0) 人氣()