[英]How to properly git clone with Windows symlinks pointing to folder in submodule
[英]How to use symlinks created by Windows git with Cygwin
我在Windows機器上使用Jenkins構建Cygwin程序。 最近開始失敗。
我發現這是因為Windows的git
似乎將回購中的符號鏈接表示為純文本文件。
有兩種方法可以解決此問題:
git
進行結帳。 最初的結果並非如我所願那樣簡單,指向Cygwin的git.exe
還不夠,因為我們在路徑中需要cygwin1.dll
。 這個問題和其他一些問題使我放棄了這種方法。 我對有關如何執行此操作的建議很感興趣,實質上是將Windows Jenkins轉換為Cygwin Jenkins。
但是,將Windows git
“鏈接”轉換為Cygwin鏈接似乎是可行的。 有什么簡單的方法可以做到並可以在Jenkins構建的第一步中運行?
我編寫了一個簡單的bash腳本來查找所有“鏈接”,這很容易,因為根據此答案將它們標記為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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.