如何在 Cygwin 中使用 Windows git 创建的符号链接
How to use symlinks created by Windows git with Cygwin
我在 Windows 机器上使用 Jenkins 构建 Cygwin 程序。最近开始失败了。
我原来是因为 Windows' git
似乎将存储库中的符号链接表示为纯文本文件。
有两种可能的方法可以解决这个问题:
- 使用 Cygwin 的
git
进行结帐。
- 将链接(a.k.a. 纯文本文件)转换为 Cygwin 链接
第一个结果并不像我希望的那么简单,指向Cygwin的git.exe
是不够的,因为我们需要路径中的cygwin1.dll
。这个问题和其他一些问题让我放弃了这个方法。我对如何做到这一点的建议很感兴趣,本质上是将 Windows Jenkins 变成 Cygwin Jenkins。
但是,将 Windows git
"links" 转换为 Cygwin 链接似乎是可行的。什么是一种简单的方法来做到这一点并且可以 运行 作为 Jenkins 构建的初始步骤?
我写了一个简单的 bash 脚本来查找所有 "links",这很容易,因为根据 this answer,它们标有标志 120000。然后只需选择目标文件名(文本文件的内容)然后用符号 link.
替换文件就很简单了
由于它是一个 bash 脚本,因此可以很容易地从 Cygwin 和 MSys 使用。
#!/bin/bash
#
#
#
# Script to convert symbolic links created by a windows git
# clone/checkout to cygwin links. When a typical Windows git checks
# out a symbolic link from the repo it (MsysGit, at least) tend to
# produce text files with flag 120000 and the link target file name as
# the content. Strategy would simply be to find all those and replace
# by cygwin links.
#
# This will work if you are not planning on commiting anything, e.g.
# in a Jenkins, or other CI, build environment
for f in `git ls-files -s | awk ' == "120000" {print }'`
do
# echo $f is a symlink pointing to $dir/$target
dir=$(dirname "${f}")
pushd "$dir" 2>&1 > /dev/null
file=$(basename "$f")
target=`cat "$file"`
rm "$file"
ln -s "$target" "$file"
popd 2>&1 > /dev/null
done
我在 Windows 机器上使用 Jenkins 构建 Cygwin 程序。最近开始失败了。
我原来是因为 Windows' git
似乎将存储库中的符号链接表示为纯文本文件。
有两种可能的方法可以解决这个问题:
- 使用 Cygwin 的
git
进行结帐。 - 将链接(a.k.a. 纯文本文件)转换为 Cygwin 链接
第一个结果并不像我希望的那么简单,指向Cygwin的git.exe
是不够的,因为我们需要路径中的cygwin1.dll
。这个问题和其他一些问题让我放弃了这个方法。我对如何做到这一点的建议很感兴趣,本质上是将 Windows Jenkins 变成 Cygwin Jenkins。
但是,将 Windows git
"links" 转换为 Cygwin 链接似乎是可行的。什么是一种简单的方法来做到这一点并且可以 运行 作为 Jenkins 构建的初始步骤?
我写了一个简单的 bash 脚本来查找所有 "links",这很容易,因为根据 this answer,它们标有标志 120000。然后只需选择目标文件名(文本文件的内容)然后用符号 link.
替换文件就很简单了由于它是一个 bash 脚本,因此可以很容易地从 Cygwin 和 MSys 使用。
#!/bin/bash
#
#
#
# Script to convert symbolic links created by a windows git
# clone/checkout to cygwin links. When a typical Windows git checks
# out a symbolic link from the repo it (MsysGit, at least) tend to
# produce text files with flag 120000 and the link target file name as
# the content. Strategy would simply be to find all those and replace
# by cygwin links.
#
# This will work if you are not planning on commiting anything, e.g.
# in a Jenkins, or other CI, build environment
for f in `git ls-files -s | awk ' == "120000" {print }'`
do
# echo $f is a symlink pointing to $dir/$target
dir=$(dirname "${f}")
pushd "$dir" 2>&1 > /dev/null
file=$(basename "$f")
target=`cat "$file"`
rm "$file"
ln -s "$target" "$file"
popd 2>&1 > /dev/null
done