upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/git_remote_helper.rs66
1 files changed, 41 insertions, 25 deletions
diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs
index 64604a4..71dc7e1 100644
--- a/src/git_remote_helper.rs
+++ b/src/git_remote_helper.rs
@@ -92,33 +92,10 @@ async fn main() -> Result<()> {
92 println!("unsupported"); 92 println!("unsupported");
93 } 93 }
94 ["fetch", _oid, refstr] => { 94 ["fetch", _oid, refstr] => {
95 temp_remote.connect(git2::Direction::Fetch)?; 95 fetch(&mut temp_remote, &stdin, refstr)?;
96 temp_remote.download(&get_refstrs_from_fetch_batch(&stdin, refstr)?, None)?;
97 temp_remote.disconnect()?;
98 println!();
99 } 96 }
100 ["push", refspec] => { 97 ["push", refspec] => {
101 let auth = GitAuthenticator::default(); 98 push(&git_repo.git_repo, url, &mut temp_remote, &stdin, refspec)?;
102 let git_config = git_repo.git_repo.config()?;
103 let mut push_options = git2::PushOptions::new();
104 let mut remote_callbacks = git2::RemoteCallbacks::new();
105 remote_callbacks.credentials(auth.credentials(&git_config));
106 remote_callbacks.push_update_reference(|name, error| {
107 if let Some(error) = error {
108 println!("error {name} {error}");
109 } else {
110 println!("ok {name}",);
111 }
112 Ok(())
113 });
114 push_options.remote_callbacks(remote_callbacks);
115 temp_remote.push(
116 &get_refspecs_from_push_batch(&stdin, refspec)?,
117 Some(&mut push_options),
118 )?;
119 update_remote_refs_from_push_refspecs(&git_repo.git_repo, refspec, url)?;
120 temp_remote.disconnect()?;
121 println!();
122 } 99 }
123 ["list"] => { 100 ["list"] => {
124 temp_remote.connect(git2::Direction::Fetch)?; 101 temp_remote.connect(git2::Direction::Fetch)?;
@@ -173,6 +150,45 @@ fn nostr_git_url_to_repo_coordinates(url: &str) -> Result<HashSet<Coordinate>> {
173 Ok(repo_coordinattes) 150 Ok(repo_coordinattes)
174} 151}
175 152
153fn fetch(temp_remote: &mut Remote, stdin: &Stdin, refstr: &str) -> Result<()> {
154 temp_remote.connect(git2::Direction::Fetch)?;
155 temp_remote.download(&get_refstrs_from_fetch_batch(stdin, refstr)?, None)?;
156 temp_remote.disconnect()?;
157 println!();
158 Ok(())
159}
160
161fn push(
162 git_repo: &Repository,
163 nostr_url: &str,
164 temp_remote: &mut Remote,
165 stdin: &Stdin,
166 initial_refspec: &str,
167) -> Result<()> {
168 let auth = GitAuthenticator::default();
169 let git_config = git_repo.config()?;
170 let mut push_options = git2::PushOptions::new();
171 let mut remote_callbacks = git2::RemoteCallbacks::new();
172 remote_callbacks.credentials(auth.credentials(&git_config));
173 remote_callbacks.push_update_reference(|name, error| {
174 if let Some(error) = error {
175 println!("error {name} {error}");
176 } else {
177 println!("ok {name}",);
178 }
179 Ok(())
180 });
181 push_options.remote_callbacks(remote_callbacks);
182 temp_remote.push(
183 &get_refspecs_from_push_batch(stdin, initial_refspec)?,
184 Some(&mut push_options),
185 )?;
186 update_remote_refs_from_push_refspecs(git_repo, initial_refspec, nostr_url)?;
187 temp_remote.disconnect()?;
188 println!();
189 Ok(())
190}
191
176fn update_remote_refs_from_push_refspecs( 192fn update_remote_refs_from_push_refspecs(
177 git_repo: &Repository, 193 git_repo: &Repository,
178 refspec: &str, 194 refspec: &str,