如何使用Windows git与Cygwin创建的符号链接

时间:2016-07-01 08:15:35

标签: windows git jenkins cygwin symlink

我在Windows机器上使用Jenkins来构建Cygwin程序。最近开始失败。

我发现这是因为Windows“git似乎将repo中的符号链接表示为纯文本文件。

有两种方法可以解决这个问题:

  1. 使用Cygwin的git进行结帐。
  2. 将链接(a.k.a。纯文本文件)转换为Cygwin链接
  3. 第一个结果并不像我希望的那么简单,指向Cygwin的git.exe是不够的,因为我们需要路径中的cygwin1.dll。这个和其他一些问题让我放弃了这个问题。我对如何做到这一点的建议感兴趣,实质上是将Windows Jenkins变成Cygwin Jenkins。

    然而,将Windows git“链接”转换为Cygwin链接似乎是可行的。什么是一个简单的方法,可以作为Jenkins构建的初始步骤运行?

1 个答案:

答案 0 :(得分:2)

我编写了一个简单的bash脚本来查找所有“链接”,因为它们根据this answer标记了120000标记。然后,只需获取目标文件名(文本文件的内容),然后用符号链接替换该文件,这是一件简单的事情。

由于它是一个bash脚本,因此可以很容易地从Cygwin和MSys中使用。

#!/bin/bash
#
# https://stackoverflow.com/a/38140374/204658
#
# 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 '$1 == "120000" {print $4}'`
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
相关问题