Skip to content

Commit c45c219

Browse files
committed
Auto merge of #3583 - alexcrichton:fix-tags, r=brson
Handle `rev` being a `tag` Previously if a rev was specified as a tag then we'd trip an assertion because resetting to that tag would reset to the tag that the commit pointed to, which would then cause the head id of the repo to be different than what we thought it was. Instead, we handle the case where a `rev` specification is a tag explicitly by using the tag's target id as the revision that we're going to check out, not the id of the tag itself. Closes #3580
2 parents fa1b12a + c0cc8ff commit c45c219

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

src/cargo/sources/git/utils.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ impl GitDatabase {
217217
}
218218
GitReference::Rev(ref s) => {
219219
let obj = self.repo.revparse_single(s)?;
220-
obj.id()
220+
match obj.as_tag() {
221+
Some(tag) => tag.target_id(),
222+
None => obj.id(),
223+
}
221224
}
222225
};
223226
Ok(GitRevision(id))

tests/git.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,3 +1826,48 @@ fn add_a_git_dep() {
18261826

18271827
assert_that(p.cargo("build"), execs().with_status(0));
18281828
}
1829+
1830+
#[test]
1831+
fn two_at_rev_instead_of_tag() {
1832+
let git = git::new("git", |p| {
1833+
p.file("Cargo.toml", r#"
1834+
[project]
1835+
name = "git1"
1836+
version = "0.5.0"
1837+
authors = []
1838+
"#)
1839+
.file("src/lib.rs", "")
1840+
.file("a/Cargo.toml", r#"
1841+
[project]
1842+
name = "git2"
1843+
version = "0.5.0"
1844+
authors = []
1845+
"#)
1846+
.file("a/src/lib.rs", "")
1847+
}).unwrap();
1848+
1849+
// Make a tag corresponding to the current HEAD
1850+
let repo = git2::Repository::open(&git.root()).unwrap();
1851+
let head = repo.head().unwrap().target().unwrap();
1852+
repo.tag("v0.1.0",
1853+
&repo.find_object(head, None).unwrap(),
1854+
&repo.signature().unwrap(),
1855+
"make a new tag",
1856+
false).unwrap();
1857+
1858+
let p = project("foo")
1859+
.file("Cargo.toml", &format!(r#"
1860+
[package]
1861+
name = "foo"
1862+
version = "0.0.1"
1863+
authors = []
1864+
1865+
[dependencies]
1866+
git1 = {{ git = '{0}', rev = 'v0.1.0' }}
1867+
git2 = {{ git = '{0}', rev = 'v0.1.0' }}
1868+
"#, git.url()))
1869+
.file("src/lib.rs", "");
1870+
1871+
assert_that(p.cargo_process("generate-lockfile"), execs().with_status(0));
1872+
assert_that(p.cargo("build").arg("-v"), execs().with_status(0));
1873+
}

0 commit comments

Comments
 (0)