How to correctly call a git submodule symlinked?

2024/10/11 22:19:39

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

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
>>>
https://en.xdnf.cn/q/118274.html

Related Q&A

Python and MySQL query with quotes

With a script in Python3, after extracting some strings from a file, they should be used as data to be inserted into a MySQL database as follows:query1 = """INSERT INTO {:s} VALUES ({:s}…

Using scipy kmeans for cluster analysis

I want to understand scipy.cluster.vq.kmeans. Having a number of points distributed in 2D space, the problem is to group them into clusters. This problem came to my attention reading this question and …

Scrapy and celery `update_state`

I have the following setup (Docker):Celery linked to Flask setup which runs the Scrapy spider Flask setup (obviously) Flask setup gets request for Scrapy -> fire up worker to do some workNow I wish …

SPIDEV on raspberry pi for TI DAC8568 not behaving as expected

I have a Texas Instruments DAC8568 in their BOOST breakout board package. The DAC8568 is an 8 channel, 16bit DAC with SPI interface. The BOOST package has headers to connect it to my raspberry pi, an…

Tensorflow: Simple Linear Regression using CSV data

I am an extreme beginner at tensorflow, and i was tasked to do a simple linear regression using my csv data which contains 2 columns, Height & State of Charge(SoC), where both values are float. In …

How to resolve positional index error in python while solving a condition in python?

I have the following data and I am trying the following code: Name Sensex_index Start_Date End_Date AAA 0.5 20/08/2016 25/09/2016 AAA 0.8 26/08/2016 …

Google Calendar API: Insert multiple events (in Python)

I am using the Google Calendar API, and have successfully managed to insert a single event into an authorized primary calendar, but I would like to hard code multiple events that, when executed, would …

Remove special characters from column headers

I have a dictionary (data_final) of dataframes (health, education, economy,...). The dataframes contain data from one xlsx file. In one of the dataframes (economy), the column names have brackets and s…

Python Flask application getting OPTIONS instead of POST

I have a python Flask listener waiting on port 8080. I expect another process to make a series of POSTs to this port.The code for listener is as follows.#!/usr/bin/env python2 from __future__ import pr…

Raspberry pi:convert fisheye image to normal image using python

I have attached the USB webcam with raspberry pi to capture image and write code to send it using mail. It captures image using fswebcam commamnd so code for capture image in python script is :subproce…