Skip to content

Commit dec24c1

Browse files
authored
feat(patchable): respect http proxy environment variables (#1563)
1 parent 55cc699 commit dec24c1

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

rust/patchable/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use snafu::{OptionExt, ResultExt as _, Snafu};
1717
use tracing_indicatif::IndicatifLayer;
1818
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _};
1919

20-
use crate::utils::setup_git_credentials;
20+
use crate::utils::{setup_git_credentials, setup_git_proxy};
2121

2222
#[derive(clap::Parser)]
2323
struct ProductVersion {
@@ -622,6 +622,7 @@ fn main() -> Result<()> {
622622

623623
let mut push_options = git2::PushOptions::new();
624624
push_options.remote_callbacks(callbacks);
625+
push_options.proxy_options(setup_git_proxy());
625626

626627
// Always push the commit as a Git tag named like the value of `base`
627628
let refspec = format!("{base_commit}:refs/tags/{base}");

rust/patchable/src/repo.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use snafu::{ResultExt, Snafu};
55

66
use crate::{
77
error::{self, CommitRef},
8-
utils::{setup_git_credentials, setup_progress_tracking},
8+
utils::{setup_git_credentials, setup_git_proxy, setup_progress_tracking},
99
};
1010

1111
#[derive(Debug, Snafu)]
@@ -177,6 +177,7 @@ pub fn resolve_and_fetch_commitish(
177177
FetchOptions::new()
178178
.update_fetchhead(true)
179179
.remote_callbacks(callbacks)
180+
.proxy_options(setup_git_proxy())
180181
// TODO: could be 1, CLI option maybe?
181182
.depth(0),
182183
),

rust/patchable/src/utils.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,16 @@ pub fn setup_git_credentials<'a>() -> git2::RemoteCallbacks<'a> {
132132
});
133133
callbacks
134134
}
135+
136+
/// Proxy configuration for Git operations.
137+
///
138+
/// Enables libgit2's automatic proxy detection, which honours the `http.proxy`
139+
/// Git config and the `HTTP_PROXY`/`HTTPS_PROXY`/`NO_PROXY` environment variables
140+
/// (just like the `git` CLI). This is what lets patchable run inside sandboxes
141+
/// (e.g. nono) that force all traffic through an HTTP proxy; it is a no-op when no
142+
/// proxy is configured.
143+
pub fn setup_git_proxy<'a>() -> git2::ProxyOptions<'a> {
144+
let mut proxy_options = git2::ProxyOptions::new();
145+
proxy_options.auto();
146+
proxy_options
147+
}

0 commit comments

Comments
 (0)