简体   繁体   中英

How to correctly call a git submodule symlinked?

On the Sublime Text Package Control issue:

  1. Why ignore VCS-based packages accordingly to this message?

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.

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

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

I am calling this subprocess on a git submodule symliked:

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

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

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.

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

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)

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

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

  1. How to correctly call a git submodule symlinked?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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