如何正确调用git子模块符号链接? [英] How to correctly call a git submodule symlinked?

查看:107
本文介绍了如何正确调用git子模块符号链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于崇高文本包装控制问题:

  1. 为什么与此消息相对应地忽略基于VCS的软件包?

我找出导致此错误的原因.我有包All Autocomplete触发了它.然后我转到文件夹Packages/All Autocomplete,发现它是一个git repo同步链接.然后,我删除了指向gitdir: ../.git/modules/All Autocomplete.git文件并重新克隆了存储库,因此其文件位于存储库中.然后,程序包控件停止为程序包All Autocomplete引发错误,并开始对下一个程序包(也是git子模块,并且将.git链接到父git文件夹)执行相同的错误.

I find out what causes this error. I had the package All Autocomplete triggering it. Then I gone to the folder Packages/All Autocomplete and noticed it is a git repo synlinked. Then I deleted the .git file which points to gitdir: ../.git/modules/All Autocomplete and recloned the repository, so its files are within the repo. Then the package control stopped throwing the error for the package All Autocomplete and started doing the same error for the next package which also a git submodule and had the .git synlinking to the parent git folder.

这是因为All Autocomplete是子模块,因此其gits文件位于:

It is because the All Autocomplete is a submodule, therefore its gits files are in:

  1. gitdir: ../.git/modules/All Autocomplete

现在您可以复制它,但是您需要:

Now you can reproduce it, but you need:

  1. 要将您的Packages文件夹设置为git存储库,并将All Autocomplete添加为子模块.
  2. 删除它,然后使用git clone --recursive
  3. 安装克隆您的Package文件夹存储库.
  1. To make your Packages folder a git repository, and add the All Autocomplete as a submodule.
  2. Delete it, and install clone your Package folder repo with git clone --recursive

这将创建All Autocomplete作为git子模块,并将其文件存储在父git文件夹中:

This will create the All Autocomplete as a git submodule and store its files on the parent git folder at:

  1. gitdir: ../.git/modules/All Autocomplete

我在一个类似的git子模块上调用此子进程:

I am calling this subprocess on a git submodule symliked:

我使用python解释器进行了一些测试,这是proc = subprocess.Popen()的问题:

I did some testing using the python interpreter, and it is a problem with the proc = subprocess.Popen():

>>> import os
>>> import subprocess
>>> startupinfo = subprocess.STARTUPINFO();startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW;
>>> proc = subprocess.Popen( ['C:/Program Files (x86)/Git/bin/git.exe', 'symbolic-ref', '-q', 'HEAD'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=startupinfo, cwd='D:/SublimeText/Data/Packages/amxmodx', env=os.environ )
>>> proc.communicate()
(b'', None)
>>> proc = subprocess.Popen( ['C:/Program Files (x86)/Git/bin/git.exe', 'symbolic-ref', '-q', 'HEAD'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=startupinfo, cwd='D:/SublimeText/Data/Packages/All Autocomplete', env=os.environ )
>>> proc.communicate()
(b'refs/heads/master\n', None)
>>>

在第一个命令中,我使用软件包amxmodx,该软件包的.git文件符号链接到gitdir: ../.git/modules/amxmodx.然后我们得到了输出(b'', None).

On the first command, I do with the package amxmodx which has the .git file symlinking to gitdir: ../.git/modules/amxmodx. And we got the output (b'', None).

在第二个命令中,我使用其中包含.git文件夹的软件包All Autocomplete,因为我只是将其克隆为git子模块.因此,由于不是由git clone --recursive安装的,因此.git为 一个文件夹,并且不是与gitdir: ../.git/modules/的符号链接,它上面有实际的git文件内容.

On the second command, I do with the package All Autocomplete which has the .git folder inside it, because I just cloned it on as a git submodule. Therefore as its installation was not by git clone --recursive, the .git is a folder, and is not a symlinked to gitdir: ../.git/modules/, it has the actual git files contents on it.

因此,我们得到了输出(b'refs/heads/master\n', None),它可以正常工作,并且使程序包控件不会引发错误.

Hence we got the output (b'refs/heads/master\n', None), which works correctly and make the package control not throw the error.

如何使用subprocess.Popen()调用符号链接的git子模块,以正确调用未符号链接到gitdir: ../.git/modules/的git子模块,从而为符号链接的子模块生成输出(b'refs/heads/master\n', None)而不是(b'', None)?

How to make the call to a symlinked git submodule with subprocess.Popen() to work properly as a call to a git submodule not symlinked to gitdir: ../.git/modules/ which produces the output (b'refs/heads/master\n', None) instead of (b'', None) for a symlinked submodule?

我的系统信息/版本是:

My system info/versions are:

$ git --version
git version 2.13.0.windows.1

$ systeminfo | findstr /B /C:"OS Version"
OS Version:                10.0.15063 N/A Build 15063

$ python --version
Python 3.6.1 :: Anaconda 4.4.0 (32-bit)


更新

我也尝试使用os.system:


Update

I also tried using os.system:

>>> cur_dir = os.getcwd()
>>> os.chdir(r'D:/SublimeText/Data/Packages/All Autocomplete')
>>> os.getcwd()
'D:\\SublimeText\\Data\\Packages\\All Autocomplete'
>>> os.system( r'"C:/Program Files (x86)/Git/bin/git.exe" symbolic-ref -q HEAD' )
refs/heads/master
0
>>> os.chdir(r'D:/SublimeText/Data/Packages/amxmodx')
>>> os.system( r'"C:/Program Files (x86)/Git/bin/git.exe" symbolic-ref -q HEAD' )
1
>>>

我也在Windows的git上为此打开了一个问题:

I also opened a issue for this on the git for windows:

  1. 如何正确调用符号链接的git子模块?

推荐答案

我刚刚发现了问题所在.当我执行git clone --recursive时,子模块不在其默认分支上签出,因此命令git.exe symbolic-ref -q HEAD返回始终为空.

I just figured out the problem. When I do git clone --recursive the submodules are not checkout on their default branches, therefore the command git.exe symbolic-ref -q HEAD returns always empty.

解决方案是转到每个子模块并执行git checkout master或main默认分支,因此该命令将正常运行并返回所需的值:

The solution is just go to each submodule and do git checkout master or the main default branch, therefore the command will work properly and return the desired values:

>>> cur_dir = os.getcwd()
>>> os.chdir(r'D:/SublimeText/Data/Packages/All Autocomplete')
>>> os.getcwd()
'D:\\SublimeText\\Data\\Packages\\All Autocomplete'
>>> os.system( r'"C:/Program Files (x86)/Git/bin/git.exe" symbolic-ref -q HEAD' )
refs/heads/master
0
>>> os.chdir(r'D:/SublimeText/Data/Packages/amxmodx')
>>> os.system( r'"C:/Program Files (x86)/Git/bin/git.exe" symbolic-ref -q HEAD' )
refs/heads/master
0
>>>

这篇关于如何正确调用git子模块符号链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆