我正在编写一个git钩子来检查裸存储库的主分支并将其放在一个文件夹中。然后我需要它是只读的,这样人们就不会意外地改变它并打破它。
我正在测试它作为.sh文件,因为它更容易触发。
这一切都运作良好:
#!/bin/sh
# after receiving, populates a folder called "LatestMaster" in the *.git directory.
# Folder contains the working copy of the master branch.
# All working tree items are made to be read-only so they cannot be modified accidentally
# 4 March 2016 Matt Tarabulski
# relative path of shell script
MY_PATH="`dirname \"$0\"`"
# absolutized and normalized path
MY_PATH="`( cd \"$MY_PATH\" && pwd )`"
# move one above the hooks folder
MY_PATH="$MY_PATH""/../LatestMaster"
# make the directory one above the hooks directory
mkdir -p "$MY_PATH"
if [ -z "$MY_PATH" ] ; then
# error; for some reason, the path is not accessible
# to the script (e.g. permissions re-evaled after suid)
echo "post-receive hook could not write to LatestMaster folder"
exit 1 # fail
fi
# set the work tree env var to $MY_PATH and export to be usable later in this script
export GIT_WORK_TREE="$MY_PATH"
# Make the head writeable for checkout
attrib -r "$MY_PATH/../HEAD"
git checkout master -f -q
在这里打破
# Make the working copy read only so people don't lose work
attrib +r "$MY_PATH" /s /d
输出:参数格式不正确 -
我觉得我已尝试过各种引号,搜索路径等组合,无论我得到什么参数格式都不正确或
例如使用此代码:
attrib +r "$MY_PATH/*.*"" /s"
我找不到路径,即使它确实存在。感谢对此的任何帮助。
我正在使用Windows 7,如果这会产生任何差异,则路径是映射的网络驱动器
当我这样做的时候 attrib + r / s
在文件夹中的cmd中它完美运行,所以我认为它可能与我使用变量有关
如果我在我的脚本中: cd" $ MY_PATH" attrib + r / s 我得到S:没找到
好的我明白了:
cd "$MY_PATH"
attrib +r '//s'
完美无缺。谁知道为什么?