Skip to content

Commit a84f766

Browse files
committed
Update git2 dependency
1 parent 253037d commit a84f766

File tree

4 files changed

+20
-33
lines changed

4 files changed

+20
-33
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ s3 = { path = "src/s3" }
4343
migrate = { path = "src/migrate" }
4444
rand = "0.3"
4545
time = "0.1"
46-
git2 = "0.2"
46+
git2 = "0.3"
4747
flate2 = "0.2"
4848
semver = "0.1.3"
4949
url = "0.2.0"

src/bin/server.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ fn main() {
2525
fs::create_dir_all(&checkout).unwrap();
2626
let mut cb = git2::RemoteCallbacks::new();
2727
cb.credentials(cargo_registry::git::credentials);
28+
let mut opts = git2::FetchOptions::new();
29+
opts.remote_callbacks(cb);
2830
git2::build::RepoBuilder::new()
29-
.remote_callbacks(cb)
31+
.fetch_options(opts)
3032
.clone(&url, &checkout).unwrap()
3133
}
3234
};

src/git.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,21 @@ fn commit_and_push<F>(repo: &git2::Repository, mut f: F) -> CargoResult<()>
134134
let mut callbacks = git2::RemoteCallbacks::new();
135135
callbacks.credentials(credentials);
136136
let mut origin = try!(repo.find_remote("origin"));
137-
138-
origin.set_callbacks(callbacks);
139-
140-
{
141-
let mut push = try!(origin.push());
142-
try!(push.add_refspec("refs/heads/master"));
143-
144-
match push.finish() {
145-
Ok(()) => {
146-
try!(push.update_tips(None, None));
147-
return Ok(())
148-
}
149-
Err(..) => {}
150-
}
137+
let mut opts = git2::PushOptions::new();
138+
opts.remote_callbacks(callbacks);
139+
match origin.push(&["refs/heads/master"], Some(&mut opts)) {
140+
Ok(()) => return Ok(()),
141+
Err(..) => {}
151142
}
152143

144+
let mut callbacks = git2::RemoteCallbacks::new();
145+
callbacks.credentials(credentials);
146+
try!(origin.update_tips(Some(&mut callbacks), true,
147+
git2::AutotagOption::Unspecified,
148+
None));
149+
153150
// Ok, we need to update, so fetch and reset --hard
154-
try!(origin.add_fetch("refs/heads/*:refs/heads/*"));
155-
try!(origin.fetch(&[], None));
151+
try!(origin.fetch(&["refs/heads/*:refs/heads/*"], None, None));
156152
let head = try!(repo.head()).target().unwrap();
157153
let obj = try!(repo.find_object(head, None));
158154
try!(repo.reset(&obj, git2::ResetType::Hard, None));

src/tests/git.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ pub fn init() {
3636
let url = Url::from_file_path(&*bare()).ok().unwrap().to_string();
3737

3838
// Setup the `origin` remote
39-
let mut origin = checkout.remote("origin", &url).unwrap();
40-
origin.set_pushurl(Some(&url)).unwrap();
41-
origin.add_push("refs/heads/master").unwrap();
42-
origin.save().unwrap();
39+
checkout.remote_set_url("origin", &url).unwrap();
40+
checkout.remote_set_pushurl("origin", Some(&url)).unwrap();
41+
checkout.remote_add_push("origin", "refs/heads/master").unwrap();
4342

4443
// Create an empty initial commit
4544
let mut config = checkout.config().unwrap();
@@ -55,15 +54,5 @@ pub fn init() {
5554

5655
// Push the commit to the remote repo
5756
let mut origin = checkout.find_remote("origin").unwrap();
58-
let mut push = origin.push().unwrap();
59-
push.add_refspec("refs/heads/master").unwrap();
60-
push.finish().unwrap();
61-
assert!(!push.statuses().unwrap().iter().any(|s| s.message.is_some()));
62-
push.update_tips(None, None).unwrap();
63-
64-
// Set up master to track origin/master
65-
let branch = checkout.find_reference("refs/heads/master");
66-
let mut branch = git2::Branch::wrap(branch.unwrap());
67-
branch.set_upstream(Some("origin/master")).unwrap();
68-
57+
origin.push(&["refs/heads/master"], None).unwrap();
6958
}

0 commit comments

Comments
 (0)