我正在尝试使用我的 OS X 桌面设置一个内部 git 服务器(主要作为测试用例)。当涉及 SSH key 时一切正常,但我目前正在尝试使用 git-daemon 进行只读克隆。如果我在终端中启动 git-daemon:
sudo -u git git-daemon --basepath=/Users/git/repos/ --export-all
然后一切正常,例如
git clone git://localhost/My_Project.git
但是当我尝试使用 launchd 进行设置时,它拒绝所有请求。我正在使用这个 plist 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>git</string>
<key>UserName</key>
<string>git</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/path/to/git-daemon</string>
<string>--base-path=/Users/git/repos/</string>
<string>--export-all</string>
</array>
</dict>
</plist>
如果我尝试克隆 My_Project,则会收到以下错误:
Cloning into My_Project...
fatal: The remote end hung up unexpectedly
令人沮丧的是,我相信这曾经有效,所以问题可能与我的 plist 文件或使用 launchd 的关系不大,而与任何可能已更改的网络设置有关。任何建议将不胜感激。
如果这更像是一个系统管理员问题,我深表歉意,但我认为开发人员可能在这方面有一些经验。
更新:如果存储库存在,控制台会报告以下错误:
git[431]
error: cannot run upload-pack: No such file or directory
最佳答案
问题是 git-daemon 在它从 launchd 继承的 PATH 中的任何目录中找不到 git 可执行文件过程。当您从 shell 启动它时它会起作用,因为从 shell 继承的 PATH 包含适当的目录。
通常,Git 命令是通过主 git 命令调用的(例如 git commit
,而不是(不再)git-commit
)。除此之外,主要的 git 命令将内置的“exec 路径”添加到“子命令”将继承的 PATH 环境变量。
你的 launchd 配置直接调用一个“内部”程序——git-daemon——而不是让普通的顶级程序调用它(在扩展 PATH 之后它将继承)。
使用以下ProgramArguments:
<array>
<string>/path/to/git</string>
<string>daemon</string>
<string>--base-path=/Users/git/repos/</string>
<string>--export-all</string>
</array>
/path/to/git
是 which git
在您的正常 shell session 中报告的内容。
关于git - 使用 launchd 在 OS X 上启动 git-daemon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5388390/