Xcode 13 ignores GIT proxy settings when resolving SwiftPM packages (and probably for other SCM operations as well).

Originator:serieuxchat
Number:rdar://FB9447729 Date Originated:2021-08-03
Status:Open Resolved:
Product:Xcode Product Version:13 beta 4
Classification:Incorrect/Unexpected Behavior Reproducible:Always
 
Please provide a descriptive title for your feedback:

Xcode 13 ignores GIT proxy settings when resolving SwiftPM packages (and probably for other SCM operations as well).

Which area are you seeing an issue with?
Xcode

Please describe the issue:
This issue is seen with Xcode 13 beta 4 and all previous Xcode versions.

When working behind a proxy (which is common when working from home during the pandemic), XCode IDE built-in SCM does not work.

E.g. our Swift packages are stored in Azure Devops server, which is accessed via a corporate Proxy.

We configure the proxy settings in the user's .gitconfig file.

However, Xcode ignores this file when it tries to connect.

Please list the steps you took to reproduce the issue:

Just try to perform any SCM operation from within Xcode IDE when the SCM server must be accessed through a proxy.

What did you expect to happen?
Xcode must use .gitconfig (or the relevant environment variables) to determine that a proxy must be used.

What actually happened?
I debugged the problem and found out the following:

Xcode uses a helper service (com.apple.dt.Xcode.sourcecontrol.Git) to communicate with GIT servers. For that it uses the open source library libgit2.dylib (version 0.26.0)

When connecting to a remote GIT server, the service com.apple.dt.Xcode.sourcecontrol.Git calls libgit2 API git_remote_connect(...), where it passes a pointer to  git_proxy_options struct.

The struct git_proxy_options a type field with 3 possible values:

/**
 * The type of proxy to use.
 */
typedef enum {
	/**
	 * Do not attempt to connect through a proxy
	 *
	 * If built against libcurl, it itself may attempt to connect
	 * to a proxy if the environment variables specify it.
	 */
	GIT_PROXY_NONE,
	/**
	 * Try to auto-detect the proxy from the git configuration.
	 */
	GIT_PROXY_AUTO,
	/**
	 * Connect via the URL given in the options
	 */
	GIT_PROXY_SPECIFIED,
} git_proxy_t;

Xcode specifies GIT_PROXY_NONE.

I built a custom version of libgit2.dylib where I fixed the type to GIT_PROXY_AUTO, and resolution of packages started working from within Xcode IDE.

Comments

This issue when working for a corporation with a proxy is very annoying, and compiling libgit2.dlyb is no longer an option because the library is signed and XCode wont load it anymore.

As of now, it falls to Apple to fix this, and respect the proxy settings set in the OS.

By sebastian.vieiraulargui at Jan. 10, 2023, 10:05 a.m. (reply...)

In the latest xcode changes seem to have expired, I use libGit 1.3.0 source code to compile and replace

int git_remote_connect(git_remote remote, git_direction direction, const git_remote_callbacks callbacks, const git_proxy_options proxy, const git_strarray custom_headers) { git_remote_connection_opts conn;

// this is my change git_proxy_options proxy_ptr = &proxy; (*proxy_ptr)->type = GIT_PROXY_AUTO;

conn.proxy = proxy; conn.custom_headers = custom_headers;

return git_remote__connect(remote, direction, callbacks, &conn); }

But it doesn't work, it was fine before updating Xcode. It looks like Xcode has changed the process and I can't even see the readme file anymore

Thanks for describing your findings, I've recently run into this problem as well. If it's not too much trouble, would you be able to post a snippet or gist of your changes to fix the type to GIT_PROXY_AUTO? I wanted to do something similar and try to build a custom version of libgit2.dylib, and would appreciate seeing what you modified if it's not not that large of a changeset.

libgit2.dylib compiled after being modified. Don't forget to change the permissions. If you want to do it yourself, just leave your contact.

https://drive.google.com/file/d/19oyv33Saa4hXjaNmT0PJSJerx11kQa9E/view?usp=sharing

By tepmntharzjc at Jan. 12, 2022, 11:48 a.m. (reply...)

Can't change the permissions by myself. Can you please share some instructions on how to do it or the way you compiled libgit2.dylib. Thank you in advance

By maxim3124 at June 3, 2022, 7:57 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!