History

[ref] another test; failing for now

Sebastian Thiel committed 5 years ago

Commit 1908b691 parent bf7783d6 files · +53 −12Browse files

Unified · Split

6 files
  1. git-ref/src/store/file/mod.rs +1 −1
  2. git-ref/src/store/file/reference/mod.rs +14 −0
  3. git-ref/src/transaction.rs +1 −1
  4. git-ref/tests/file/reference.rs +3 −3
  5. git-ref/tests/file/store/find_one.rs +2 −2
  6. git-ref/tests/file/transaction.rs +32 −5
git-ref/src/store/file/mod.rs+1−1
@@ -20,7 +20,7 @@ impl Default for WriteReflog { · 19 unmodified lines
2020 pub struct Reference<'a> {
2121 parent: &'a Store,
2222 /// The path to uniquely identify this ref within its store.
23− pub relative_path: PathBuf,
23+ relative_path: PathBuf,
2424 state: reference::State,
2525 }
2626
git-ref/src/store/file/reference/mod.rs+14−0
@@ -1,6 +1,8 @@
1+use crate::transaction::FullName;
12 use crate::{file::Reference, Kind, Target};
23 use bstr::BString;
34 use git_hash::{oid, ObjectId};
5+use std::path::Path;
46
57 #[derive(Debug, PartialOrd, PartialEq, Ord, Eq, Hash, Clone)]
68 #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
@@ -33,6 +35,18 @@ impl<'a> Reference<'a> { · 26 unmodified lines
3335 State::Id(ref oid) => Target::Peeled(oid.as_ref()),
3436 }
3537 }
38+
39+ /// Return the full name of this reference as path
40+ pub fn relative_path(&self) -> &Path {
41+ &self.relative_path
42+ }
43+
44+ /// Return the full validated name of the reference
45+ pub fn name(&self) -> FullName {
46+ use os_str_bytes::OsStrBytes;
47+ let name = self.relative_path.as_path().to_raw_bytes();
48+ FullName(name.to_vec().into())
49+ }
3650 }
3751
3852 mod iter;
git-ref/src/transaction.rs+1−1
@@ -35,7 +35,7 @@ use std::{borrow::Cow, convert::TryFrom, path::Path}; · 34 unmodified lines
3535 /// Indicate that the given BString is a validate reference name or path that can be used as path on disk or written as target
3636 /// of a symbolic reference
3737 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
38−pub struct FullName(BString);
38+pub struct FullName(pub(crate) BString);
3939
4040 impl TryFrom<&str> for FullName {
4141 type Error = git_validate::refname::Error;
git-ref/tests/file/reference.rs+3−3
@@ -55,7 +55,7 @@ mod peel { · 54 unmodified lines
5555 r.peel_to_id_in_place()?,
5656 hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03")
5757 );
58− assert_eq!(r.relative_path, Path::new("refs/remotes/origin/multi-link-target3"));
58+ assert_eq!(r.relative_path(), Path::new("refs/remotes/origin/multi-link-target3"));
5959
6060 Ok(())
6161 }
@@ -65,14 +65,14 @@ mod peel { · 3 unmodified lines
6565 let store = file::store()?;
6666 let mut r = store.find_one_existing("loop-a")?;
6767 assert_eq!(r.kind(), git_ref::Kind::Symbolic, "there is something to peel");
68− assert_eq!(r.relative_path, Path::new("refs/loop-a"));
68+ assert_eq!(r.relative_path(), Path::new("refs/loop-a"));
6969
7070 assert!(matches!(
7171 r.peel_to_id_in_place().unwrap_err(),
7272 git_ref::file::reference::peel::to_id::Error::Cycle { .. }
7373 ));
7474 assert_eq!(
75− r.relative_path,
75+ r.relative_path(),
7676 Path::new("refs/loop-a"),
7777 "the ref is not changed on error"
7878 );
git-ref/tests/file/store/find_one.rs+2−2
@@ -11,7 +11,7 @@ mod existing { · 10 unmodified lines
1111 for (partial_name, expected_path) in &[("main", Some("refs/heads/main")), ("does-not-exist", None)] {
1212 let reference = store.find_one_existing(*partial_name);
1313 match expected_path {
14− Some(expected_path) => assert_eq!(reference?.relative_path, Path::new(expected_path)),
14+ Some(expected_path) => assert_eq!(reference?.relative_path(), Path::new(expected_path)),
1515 None => match reference {
1616 Ok(_) => panic!("Expected error"),
1717 Err(git_ref::file::find_one::existing::Error::NotFound(name)) => {
@@ -42,7 +42,7 @@ fn success() -> crate::Result { · 24 unmodified lines
4242 ("refs/heads/main", "refs/heads/main", git_ref::Kind::Peeled),
4343 ] {
4444 let reference = store.find_one(*partial_name)?.expect("exists");
45− assert_eq!(reference.relative_path, Path::new(expected_path));
45+ assert_eq!(reference.relative_path(), Path::new(expected_path));
4646 assert_eq!(reference.target().kind(), *expected_ref_kind);
4747 }
4848 Ok(())
git-ref/tests/file/transaction.rs+32−5
@@ -11,6 +11,7 @@ mod prepare_and_commit { · 10 unmodified lines
1111 mod create {
1212 use crate::file::transaction::prepare_and_commit::empty_store;
1313 use bstr::ByteSlice;
14+ use git_lock::acquire::Fail;
1415 use git_ref::transaction::{Change, RefEdit, Reflog, Target};
1516 use std::{convert::TryInto, path::Path};
1617
@@ -49,12 +50,12 @@ mod prepare_and_commit { · 32 unmodified lines
4950 },
5051 name: "HEAD".try_into()?,
5152 }),
52− git_lock::acquire::Fail::Immediately,
53+ Fail::Immediately,
5354 );
5455 let edits = t.commit()?;
5556 assert_eq!(edits.len(), 1, "no split was performed");
5657 let written = store.find_one_existing(edits[0].name.to_partial())?;
57− assert_eq!(written.relative_path, Path::new("HEAD"));
58+ assert_eq!(written.relative_path(), Path::new("HEAD"));
5859 assert_eq!(written.kind(), git_ref::Kind::Symbolic);
5960 assert_eq!(written.target().as_name(), Some(referent.as_bytes().as_bstr()));
6061 assert!(!written.log_exists()?, "no revlog is written for symbolic ref");
@@ -83,6 +84,7 @@ mod prepare_and_commit { · 22 unmodified lines
8384 use crate::file::store_writable;
8485 use crate::file::transaction::prepare_and_commit::empty_store;
8586 use git_hash::ObjectId;
87+ use git_lock::acquire::Fail;
8688 use git_ref::{
8789 file::WriteReflog,
8890 transaction::{Change, RefEdit, Target},
@@ -98,7 +100,7 @@ mod prepare_and_commit { · 9 unmodified lines
98100 change: Change::Delete { previous: None },
99101 name: "DOES_NOT_EXIST".try_into().unwrap(),
100102 }),
101− git_lock::acquire::Fail::Immediately,
103+ Fail::Immediately,
102104 )
103105 .commit()
104106 .unwrap();
@@ -116,7 +118,7 @@ mod prepare_and_commit { · 11 unmodified lines
116118 },
117119 name: "DOES_NOT_EXIST".try_into().unwrap(),
118120 }),
119− git_lock::acquire::Fail::Immediately,
121+ Fail::Immediately,
120122 )
121123 .commit();
122124 match res {
@@ -128,9 +130,34 @@ mod prepare_and_commit { · 5 unmodified lines
128130 }
129131 }
130132
133+ #[test]
134+ #[should_panic]
135+ fn delete_reflog_only_of_symbolic_no_deref() {
136+ let (_keep, store) = store_writable("make_repo_for_reflog.sh").unwrap();
137+ let head = store.find_one_existing("HEAD").unwrap();
138+ assert!(head.log_exists().unwrap());
139+
140+ let edits = store
141+ .transaction(
142+ Some(RefEdit {
143+ change: Change::Delete {
144+ previous: Some(Target::Peeled(ObjectId::null_sha1())),
145+ },
146+ name: head.name().into(),
147+ }),
148+ Fail::Immediately,
149+ )
150+ .commit()
151+ .unwrap();
152+
153+ assert_eq!(edits.len(), 1);
154+ let head = store.find_one_existing("HEAD").unwrap();
155+ assert!(!head.log_exists().unwrap());
156+ }
157+
131158 #[test]
132159 #[ignore]
133− fn delete_reflog_only() {
160+ fn delete_reflog_only_of_symbolic_with_deref() {
134161 let _store = store_writable("make_repo_for_reflog.sh").unwrap();
135162 todo!("assure it won't delete the ref")
136163 }