已发布这里所以请随意回答。
每次我向 git 服务器提交/推送某些内容时,文件权限都会发生变化(存储库中的所有添加/编辑文件都无该组的读取和执行访问权限)。因此 trac 无法访问存储库。
我是否需要以不同的方式更改文件夹的权限?
chmod u=rwx,g=rx,o= -R /home/git/repositories
或者我是否需要以某种方式设置 gitolite 来写入具有不同权限的文件???
问候,klemens
答案1
设置 umask/default umask 无效,因为 gitolite 有自己的设置。
在 ~/.gitolite.rc
$REPO_UMASK = 0027;
按你喜欢的方式设置:)
答案2
Git 仅跟踪文件名和这些文件的数据。它不跟踪文件系统元数据(所有权、权限等)。
如果您希望所有文件具有相同的权限,则 umask 可能是一种有效的解决方案。
我已经使用 Git 跟踪多台服务器上的系统文件 3 年了。我需要一种方法来跟踪权限和数据的更改。我编写了一个 Ruby 脚本来捕获文件权限/所有权并将其放入文件中。现在可以通过 git 跟踪此文件。每当需要恢复该元数据时,我都会使用另一个 Ruby 脚本来读取文件并恢复权限。
三年来我经常使用这些脚本,它们从来没有让我失望过。
他们来了:
脚本:save-fs-permissions
#!/usr/bin/ruby
RM = "/bin/rm"
SORT = "/usr/bin/sort"
TMP = "/tmp/save_fs_permissions_#{Time.now.to_i}_#{rand * 899 + 100}"
require 'find'
IGNORE = [".git"]
def numeric2human(m)
return sprintf("%c%c%c%c%c%c%c%c%c",
(m & 0400 == 0 ? ?- : ?r),
(m & 0200 == 0 ? ?- : ?w),
(m & 0100 == 0 ? (m & 04000 == 0 ? ?- : ?S) :
(m & 04000 == 0 ? ?x : ?s)),
(m & 0040 == 0 ? ?- : ?r),
(m & 0020 == 0 ? ?- : ?w),
(m & 0010 == 0 ? (m & 02000 == 0 ? ?- : ?S) :
(m & 02000 == 0 ? ?x : ?s)),
(m & 0004 == 0 ? ?- : ?r),
(m & 0002 == 0 ? ?- : ?w),
(m & 0001 == 0 ? (m & 01000 == 0 ? ?- : ?T) :
(m & 01000 == 0 ? ?x : ?t)))
end
File.open(TMP, "w") do |permissions_file|
# TODO: Instead of the current dir, find the .git dir, which could be
# the same or outside of the current dir
Find.find(".") do |path|
next if IGNORE.collect {|ig| !!(path[2..-1] =~ /\A#{ig}/)}.include? true
next if File.symlink?(path)
stat = File.lstat(path)
type = stat.ftype[0..0].sub('f', '-') # Single character for the file type
# But a "-" istead of "f"
owner_id = stat.uid
group_id = stat.gid
rules = "#{type}#{numeric2human(stat.mode)}"
permissions_file.puts "#{path} #{rules} #{owner_id} #{group_id}"
end
end
`#{SORT} #{TMP} > ./fs-permissions`
`#{RM} #{TMP}`
- 上述脚本应在 Git 工作目录 (GIT_WORK_TREE) 的根目录下执行。fs 权限、所有者和组 ID 将存储在
fs-permissions
GIT_WORK_TREE 目录根目录中的文件中。
脚本:restore-fs-permissions
#!/usr/bin/ruby
# Restore from...
FROM = "./fs-permissions"
MKDIR = "/bin/mkdir"
CHMOD = "/bin/chmod"
CHOWN = "/bin/chown"
known_content_missing = false
def numeric2human(m)
return sprintf("%c%c%c%c%c%c%c%c%c",
(m & 0400 == 0 ? ?- : ?r),
(m & 0200 == 0 ? ?- : ?w),
(m & 0100 == 0 ? (m & 04000 == 0 ? ?- : ?S) :
(m & 04000 == 0 ? ?x : ?s)),
(m & 0040 == 0 ? ?- : ?r),
(m & 0020 == 0 ? ?- : ?w),
(m & 0010 == 0 ? (m & 02000 == 0 ? ?- : ?S) :
(m & 02000 == 0 ? ?x : ?s)),
(m & 0004 == 0 ? ?- : ?r),
(m & 0002 == 0 ? ?- : ?w),
(m & 0001 == 0 ? (m & 01000 == 0 ? ?- : ?T) :
(m & 01000 == 0 ? ?x : ?t)))
end
def human2chmod(mode)
raise unless mode =~ /([r-][w-][xtsTS-])([r-][w-][xtsTS-])([r-][w-][xtsTS-])/
triple = [$1, $2, $3]
u,g,o = triple.collect do |i|
i.sub('s', 'sx').sub('t', 'tx').downcase.gsub('-', '')
end
return "u=#{u},g=#{g},o=#{o}"
end
File.open(FROM).each do |permissions|
raise unless permissions =~ /\A(([^ ]*? )+)([^ ]+) ([^ ]+) ([^ ]+)\Z/
path, rules, owner_id, group_id = $1, $3, $4, $5
path = path.strip
owner_id = owner_id.to_i
group_id = group_id.to_i
if !File.exists?(path) and !File.symlink?(path)
if rules =~ /\Ad/
STDERR.puts "Restoring a missing directory: #{path}"
STDERR.puts "Probably it was an empty directory. Git goes not track them."
`#{MKDIR} -p '#{path}'` # Creating the any parents
else
known_content_missing = true
STDERR.puts "ERROR: Permission is listed but the file is missing: #{path}"
next
end
end
s = File.lstat(path)
t = s.ftype[0..0].sub('f', '-') # Single character for the file type
# But a "-" istead of "f"
# Actual, but not neccesarely Desired
actual_rules = "#{t}#{numeric2human(s.mode)}"
actual_owner_id = s.uid
actual_group_id = s.gid
unless [actual_rules, actual_owner_id, actual_group_id] ==
[rules, owner_id, group_id]
chmod_argument = human2chmod(rules)
# Debug
#p chmod_argument
#p s.mode
## Verbose
puts path
puts "Wrong: #{[actual_rules, actual_owner_id, actual_group_id].inspect}"
puts "Fixed: #{[rules, owner_id, group_id].inspect}"
puts
`#{CHOWN} #{owner_id}:#{group_id} '#{path}'`
`#{CHMOD} #{chmod_argument} '#{path}'`
#puts
end
end
if known_content_missing
STDERR.puts "-" * 80
STDERR.puts "Some files that are listed in #{FROM.inspect} are missing in " +
"the current directory."
STDERR.puts
STDERR.puts "Is #{FROM.inspect} outdated?"
STDERR.puts "(Try retrograding the current directory to an earlier version)"
STDERR.puts
STDERR.puts "Or is the current directory incomplete?"
STDERR.puts "(Try to recover the current directory)"
STDERR.puts "-" * 80
end