upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/nostr/builder.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-21 15:35:19 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-21 15:35:19 +0000
commitee7e115b2d0e6a6eee42eb875199c965696017d5 (patch)
tree634ab7f960d56dc9073ebc85baf9fa6c193a32c8 /src/nostr/builder.rs
parent97e21b62eab89bab1456db7df27df8f1c85399f0 (diff)
fixed http clone
but do we really nedd to create a blank commit? I dont think ngit-relay does that. Do we need to se the default branch or is this automatic?
Diffstat (limited to 'src/nostr/builder.rs')
-rw-r--r--src/nostr/builder.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs
index 259c380..a0b82f4 100644
--- a/src/nostr/builder.rs
+++ b/src/nostr/builder.rs
@@ -73,6 +73,40 @@ impl Nip34WritePolicy {
73 return Err(format!("git init failed: {}", stderr)); 73 return Err(format!("git init failed: {}", stderr));
74 } 74 }
75 75
76 // Create an initial empty commit so the repository can be cloned
77 // This is required because git clone fails on completely empty repositories
78 let output = std::process::Command::new("git")
79 .args(&[
80 "--git-dir", repo_path.to_str().unwrap(),
81 "commit-tree", "-m", "Initial empty commit",
82 "4b825dc642cb6eb9a060e54bf8d69288fbee4904" // Empty tree hash
83 ])
84 .output()
85 .map_err(|e| format!("Failed to create initial commit: {}", e))?;
86
87 if !output.status.success() {
88 let stderr = String::from_utf8_lossy(&output.stderr);
89 tracing::warn!("Failed to create initial commit (repository may not be cloneable): {}", stderr);
90 // Don't fail here - the repository was created successfully
91 } else {
92 // Extract commit hash from stdout
93 let commit_hash = String::from_utf8_lossy(&output.stdout).trim().to_string();
94
95 // Create master branch pointing to this commit
96 let output = std::process::Command::new("git")
97 .args(&[
98 "--git-dir", repo_path.to_str().unwrap(),
99 "update-ref", "refs/heads/master", &commit_hash
100 ])
101 .output()
102 .map_err(|e| format!("Failed to create master branch: {}", e))?;
103
104 if !output.status.success() {
105 let stderr = String::from_utf8_lossy(&output.stderr);
106 tracing::warn!("Failed to create master branch: {}", stderr);
107 }
108 }
109
76 tracing::info!("Created bare repository at {}", repo_path.display()); 110 tracing::info!("Created bare repository at {}", repo_path.display());
77 Ok(()) 111 Ok(())
78 } 112 }