[英]How to correctly call a git submodule symlinked?
On the Sublime Text Package Control issue: 关于Sublime Text Package Control问题:
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文件位于:
gitdir: ../.git/modules/All Autocomplete
Now you can reproduce it, but you need: 现在您可以复制它,但是您需要:
All Autocomplete
as a submodule. All Autocomplete
作为子模块。 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文件夹中:
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)
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上为此打开了一个问题:
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.