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
16 MissingUrl { direction: remote::Direction },16 MissingUrl { direction: remote::Direction },
17 #[error("Protocol named {given:?} is not a valid protocol. Choose between 1 and 2")]17 #[error("Protocol named {given:?} is not a valid protocol. Choose between 1 and 2")]
18 UnknownProtocol { given: BString },18 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),
19 }21 }
20}22}
21pub use error::Error;23pub use error::Error;
@@ -70,7 +72,17 @@ impl<'repo> Remote<'repo> { · 48 unmodified lines
70 })72 })
71 })?;73 })?;
72 74
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 }
74 let transport = git_protocol::transport::connect(url, protocol).await?;86 let transport = git_protocol::transport::connect(url, protocol).await?;
75 Ok(self.to_connection_with_transport(transport, progress))87 Ok(self.to_connection_with_transport(transport, progress))
76 }88 }
git-repository/src/remote/connection/list_refs.rs+2−2
@@ -1,4 +1,6 @@
1use crate::remote::connection::State;
1use crate::remote::{Connection, Direction};2use crate::remote::{Connection, Direction};
3use git_features::progress::Progress;
2use git_protocol::transport::client::Transport;4use git_protocol::transport::client::Transport;
3 5
4mod error {6mod error {
@@ -10,9 +12,7 @@ mod error { · 5 unmodified lines
10 ListRefs(#[from] git_protocol::fetch::refs::Error),12 ListRefs(#[from] git_protocol::fetch::refs::Error),
11 }13 }
12}14}
13use crate::remote::connection::State;
14pub use error::Error;15pub use error::Error;
15use git_features::progress::Progress;
16 16
17impl<'a, 'repo, T, P> Connection<'a, 'repo, T, P>17impl<'a, 'repo, T, P> Connection<'a, 'repo, T, P>
18where18where
git-repository/src/remote/connection/mod.rs+22−7
@@ -10,24 +10,39 @@ pub(crate) enum State { · 9 unmodified lines
10 },10 },
11}11}
12 12
13pub struct Connection<'a, 'repo, T, P> {13pub struct Connection<'a, 'repo, T, P>
14where
15 T: git_protocol::transport::client::Transport,
16{
14 pub(crate) remote: &'a Remote<'repo>,17 pub(crate) remote: &'a Remote<'repo>,
15 pub(crate) transport: T,18 pub(crate) transport: T,
16 pub(crate) progress: P,19 pub(crate) progress: P,
17 pub(crate) state: State,20 pub(crate) state: State,
18}21}
19 22
23mod 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
20mod access {37mod access {
21 use crate::remote::Connection;38 use crate::remote::Connection;
22 use crate::Remote;39 use crate::Remote;
23 40
24 /// Access and conversion41 /// Access and conversion
25 impl<'a, 'repo, T, P> Connection<'a, 'repo, T, P> {42 impl<'a, 'repo, T, P> Connection<'a, 'repo, T, P>
26 /// Obtain the transport from this instance.43 where
27 pub fn into_transport(self) -> T {44 T: git_protocol::transport::client::Transport,
28 self.transport45 {
29 }
30
31 /// Drop the transport and additional state to regain the original remote.46 /// Drop the transport and additional state to regain the original remote.
32 pub fn remote(&self) -> &Remote<'repo> {47 pub fn remote(&self) -> &Remote<'repo> {
33 self.remote48 self.remote
git-repository/tests/remote/list_refs.rs+2−2
@@ -5,11 +5,11 @@ mod blocking_io { · 4 unmodified lines
5 use git_repository::remote::Direction::Fetch;5 use git_repository::remote::Direction::Fetch;
6 6
7 #[test]7 #[test]
8 #[ignore]
9 fn all() {8 fn all() {
10 let repo = remote::repo("clone");9 let repo = remote::repo("clone");
11 let remote = repo.find_remote("origin").unwrap();10 let remote = repo.find_remote("origin").unwrap();
12 let mut connection = remote.connect(Fetch, progress::Discard).unwrap();11 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.");
14 }14 }
15}15}

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