开发者

Restore read-only status when switching branches in msysgit

开发者 https://www.devze.com 2023-04-02 13:10 出处:网络
I\'d like to use git branches to separate my local changes from the team\'s head code, w开发者_JS百科hich is stored in a Perforce repository.

I'd like to use git branches to separate my local changes from the team's head code, w开发者_JS百科hich is stored in a Perforce repository.

Perforce uses the read-only flag on unchanged files, and won't update modified files if the read-only flag is not set, thinking that I might have changed them without putting them into a changelist.

I'd like to keep everything read-only on the master branch and modify files on other branches. Is it possible to make msysgit restore the read-only flag on the reverted files when checking out the master branch, so that p4 can sync everything?


You could write a git post-checkout hook with a bash script that sets the read-only flag...

Something along the lines of:

# (flag==1?) && (HEAD == master) ?
if [ $3 == 1 ] && [ `git symbolic-ref -q HEAD` == "refs/heads/master" ]
then
    # make everything in the given directory (recursively) read-only:
    chmod -w [ path_to_repo | . ]/* -R
fi

It looks like ./* skips the .git folder (hidden files/folders in general?), but you should check that out to be sure. You probably also want to use the full path to your git repo instead of just ./* so that it doesn't matter which dir/subdir you're in...

0

精彩评论

暂无评论...
验证码 换一张
取 消