summaryrefslogtreecommitdiffstats
path: root/vendor/git2-curl/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
commit10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch)
treebdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/git2-curl/tests
parentReleasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff)
downloadrustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz
rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/git2-curl/tests')
-rw-r--r--vendor/git2-curl/tests/all.rs74
1 files changed, 74 insertions, 0 deletions
diff --git a/vendor/git2-curl/tests/all.rs b/vendor/git2-curl/tests/all.rs
new file mode 100644
index 000000000..c7f09dd40
--- /dev/null
+++ b/vendor/git2-curl/tests/all.rs
@@ -0,0 +1,74 @@
+use civet::{Config, Server};
+use conduit_git_http_backend as git_backend;
+use std::fs::File;
+use std::path::Path;
+use tempfile::TempDir;
+
+const PORT: u16 = 7848;
+
+fn main() {
+ unsafe {
+ git2_curl::register(curl::easy::Easy::new());
+ }
+
+ // Spin up a server for git-http-backend
+ let td = TempDir::new().unwrap();
+ let mut cfg = Config::new();
+ cfg.port(PORT).threads(1);
+ let _a = Server::start(cfg, git_backend::Serve(td.path().to_path_buf()));
+
+ // Prep a repo with one file called `foo`
+ let sig = git2::Signature::now("foo", "bar").unwrap();
+ let r1 = git2::Repository::init(td.path()).unwrap();
+ File::create(&td.path().join(".git").join("git-daemon-export-ok")).unwrap();
+ {
+ let mut index = r1.index().unwrap();
+ File::create(&td.path().join("foo")).unwrap();
+ index.add_path(Path::new("foo")).unwrap();
+ index.write().unwrap();
+ let tree_id = index.write_tree().unwrap();
+ r1.commit(
+ Some("HEAD"),
+ &sig,
+ &sig,
+ "test",
+ &r1.find_tree(tree_id).unwrap(),
+ &[],
+ )
+ .unwrap();
+ }
+
+ // Clone through the git-http-backend
+ let td2 = TempDir::new().unwrap();
+ let r = git2::Repository::clone(&format!("http://localhost:{}", PORT), td2.path()).unwrap();
+ assert!(File::open(&td2.path().join("foo")).is_ok());
+ {
+ File::create(&td.path().join("bar")).unwrap();
+ let mut index = r1.index().unwrap();
+ index.add_path(&Path::new("bar")).unwrap();
+ index.write().unwrap();
+ let tree_id = index.write_tree().unwrap();
+ let parent = r1.head().ok().and_then(|h| h.target()).unwrap();
+ let parent = r1.find_commit(parent).unwrap();
+ r1.commit(
+ Some("HEAD"),
+ &sig,
+ &sig,
+ "test",
+ &r1.find_tree(tree_id).unwrap(),
+ &[&parent],
+ )
+ .unwrap();
+ }
+
+ let mut remote = r.find_remote("origin").unwrap();
+ remote
+ .fetch(&["refs/heads/*:refs/heads/*"], None, None)
+ .unwrap();
+ let b = r.find_branch("master", git2::BranchType::Local).unwrap();
+ let id = b.get().target().unwrap();
+ let obj = r.find_object(id, None).unwrap();
+ r.reset(&obj, git2::ResetType::Hard, None).unwrap();
+
+ assert!(File::open(&td2.path().join("bar")).is_ok());
+}