History

A first working test to show all refs of a remote. (#450)

Sebastian Thiel committed 4 years ago

Commit 86c80e61 parent 5ba9e1d4 files · +39 −12Browse files

Unified · Split

4 files
  1. git-repository/src/remote/connect.rs +13 −1
  2. git-repository/src/remote/connection/list_refs.rs +2 −2
  3. git-repository/src/remote/connection/mod.rs +22 −7
  4. git-repository/tests/remote/list_refs.rs +2 −2
git-repository/src/remote/connect.rs+13−1
@@ -16,6 +16,8 @@ mod error { · 15 unmodified lines
1616 MissingUrl { direction: remote::Direction },
1717 #[error("Protocol named {given:?} is not a valid protocol. Choose between 1 and 2")]
1818 UnknownProtocol { given: BString },
19+ #[error("Could not verify that file:// url is a valid git directory before attempting to use it")]
20+ FileUrl(#[from] git_discover::is_git::Error),
1921 }
2022 }
2123 pub use error::Error;
@@ -70,7 +72,17 @@ impl<'repo> Remote<'repo> { · 48 unmodified lines
7072 })
7173 })?;
7274
73− let url = self.url(direction).ok_or(Error::MissingUrl { direction })?.to_owned();
75+ let mut url = self.url(direction).ok_or(Error::MissingUrl { direction })?.to_owned();
76+ if url.scheme == git_url::Scheme::File {
77+ let mut dir = git_path::from_bstr(url.path.as_ref());
78+ let kind = git_discover::is_git(dir.as_ref()).or_else(|_| {
79+ dir.to_mut().push(git_discover::DOT_GIT_DIR);
80+ git_discover::is_git(dir.as_ref())
81+ })?;
82+ let (git_dir, _work_dir) = git_discover::repository::Path::from_dot_git_dir(dir.into_owned(), kind)
83+ .into_repository_and_work_tree_directories();
84+ url.path = git_path::into_bstr(git_dir).into_owned();
85+ }
7486 let transport = git_protocol::transport::connect(url, protocol).await?;
7587 Ok(self.to_connection_with_transport(transport, progress))
7688 }
git-repository/src/remote/connection/list_refs.rs+2−2
@@ -1,4 +1,6 @@
1+use crate::remote::connection::State;
12 use crate::remote::{Connection, Direction};
3+use git_features::progress::Progress;
24 use git_protocol::transport::client::Transport;
35
46 mod error {
@@ -10,9 +12,7 @@ mod error { · 5 unmodified lines
1012 ListRefs(#[from] git_protocol::fetch::refs::Error),
1113 }
1214 }
13−use crate::remote::connection::State;
1415 pub use error::Error;
15−use git_features::progress::Progress;
1616
1717 impl<'a, 'repo, T, P> Connection<'a, 'repo, T, P>
1818 where
git-repository/src/remote/connection/mod.rs+22−7
@@ -10,24 +10,39 @@ pub(crate) enum State { · 9 unmodified lines
1010 },
1111 }
1212
13−pub struct Connection<'a, 'repo, T, P> {
13+pub struct Connection<'a, 'repo, T, P>
14+where
15+ T: git_protocol::transport::client::Transport,
16+{
1417 pub(crate) remote: &'a Remote<'repo>,
1518 pub(crate) transport: T,
1619 pub(crate) progress: P,
1720 pub(crate) state: State,
1821 }
1922
23+mod impls {
24+ use crate::remote::Connection;
25+ use git_protocol::transport::client::Transport;
26+
27+ impl<'a, 'repo, T, P> Drop for Connection<'a, 'repo, T, P>
28+ where
29+ T: Transport,
30+ {
31+ fn drop(&mut self) {
32+ git_protocol::fetch::indicate_end_of_interaction(&mut self.transport).ok();
33+ }
34+ }
35+}
36+
2037 mod access {
2138 use crate::remote::Connection;
2239 use crate::Remote;
2340
2441 /// Access and conversion
25− impl<'a, 'repo, T, P> Connection<'a, 'repo, T, P> {
26− /// Obtain the transport from this instance.
27− pub fn into_transport(self) -> T {
28− self.transport
29− }
30−
42+ impl<'a, 'repo, T, P> Connection<'a, 'repo, T, P>
43+ where
44+ T: git_protocol::transport::client::Transport,
45+ {
3146 /// Drop the transport and additional state to regain the original remote.
3247 pub fn remote(&self) -> &Remote<'repo> {
3348 self.remote
git-repository/tests/remote/list_refs.rs+2−2
@@ -5,11 +5,11 @@ mod blocking_io { · 4 unmodified lines
55 use git_repository::remote::Direction::Fetch;
66
77 #[test]
8− #[ignore]
98 fn all() {
109 let repo = remote::repo("clone");
1110 let remote = repo.find_remote("origin").unwrap();
1211 let mut connection = remote.connect(Fetch, progress::Discard).unwrap();
13− let _refs = connection.list_refs().unwrap();
12+ let refs = connection.list_refs().unwrap();
13+ assert_eq!(refs.len(), 14, "it gets all remote refs, independently of the refspec.");
1414 }
1515 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t