简体   繁体   English

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

[英]How to correctly call a git submodule symlinked?

On the Sublime Text Package Control issue: 关于Sublime Text Package Control问题:

  1. Why ignore VCS-based packages accordingly to this message? 为什么要根据此消息忽略基于VCS的软件包?

I find out what causes this error. 我找出导致此错误的原因。 I had the package All Autocomplete triggering it. 我已经触发了All Autocomplete软件包。 Then I gone to the folder Packages/All Autocomplete and noticed it is a git repo synlinked. 然后我去了Packages/All Autocomplete文件夹,发现它是一个git repo synlink。 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. 然后,我删除了指向gitdir: ../.git/modules/All Autocomplete.git文件gitdir: ../.git/modules/All Autocomplete .git gitdir: ../.git/modules/All Autocomplete并重新克隆了存储库,因此其文件位于存储库中。 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抛出错误,并开始对下一个程序包(也是git子模块,并将.git同步链接到父git文件夹)执行相同的错误。

It is because the All Autocomplete is a submodule, therefore its gits files are in: 这是因为“ All Autocomplete是一个子模块,因此其gits文件位于:

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

Now you can reproduce it, but you need: 现在您可以复制它,但是您需要:

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

This will create the All Autocomplete as a git submodule and store its files on the parent git folder at: 这将创建All Autocomplete作为git子模块,并将其文件存储在父git文件夹中:

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

I am calling this subprocess on a git submodule symliked: 我在一个类似的git子模块上调用此子进程:

I did some testing using the python interpreter, and it is a problem with the proc = subprocess.Popen() : 我使用python解释器进行了一些测试,而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)
>>>

On the first command, I do with the package amxmodx which has the .git file symlinking to gitdir: ../.git/modules/amxmodx . 在第一个命令中,我使用包amxmodx ,该包具有链接到gitdir: ../.git/modules/amxmodx.git文件gitdir: ../.git/modules/amxmodx . .git gitdir: ../.git/modules/amxmodx And we got the output (b'', None) . 然后我们得到了输出(b'', None)

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. 在第二个命令中,我使用其中包含.git文件夹的软件包All Autocomplete ,因为我只是将其克隆为git子模块。 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. 因此,由于其安装不是通过git clone --recursive.git是一个文件夹,并且不是与gitdir: ../.git/modules/链接的gitdir: ../.git/modules/ .git gitdir: ../.git/modules/ ,因此它具有实际的git文件内容。

Hence we got the output (b'refs/heads/master\\n', None) , which works correctly and make the package control not throw the error. 因此,我们得到了输出(b'refs/heads/master\\n', 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? 如何使用subprocess.Popen()来调用gitdir: ../.git/modules/链接的git子模块,使其作为未gitdir: ../.git/modules/链接到gitdir: ../.git/modules/的git子模块的调用而正常工作gitdir: ../.git/modules/ git (b'refs/heads/master\\n', None)会产生输出(b'refs/heads/master\\n', None)而不是符号链接子模块的(b'', None)


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)

Update 更新

I also tried using os.system : 我也尝试使用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
>>>

I also opened a issue for this on the git for windows: 我也在Windows的git上为此打开了一个问题:

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

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 clone --recursive ,子模块不在其默认分支上签出,因此命令git.exe symbolic-ref -q HEAD返回始终为空。

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

>>> 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
>>>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM