1
+ use crate :: fixture_bytes;
2
+ use bstr:: ByteSlice ;
3
+ use git_object:: owned;
1
4
use git_protocol:: fetch;
2
5
use git_transport:: client:: Capabilities ;
3
6
@@ -22,21 +25,37 @@ impl fetch::Delegate for LsRemoteDelegate {
22
25
}
23
26
}
24
27
28
+ fn oid ( hex_sha : & str ) -> owned:: Id {
29
+ owned:: Id :: from_40_bytes_in_hex ( hex_sha. as_bytes ( ) ) . expect ( "valid input" )
30
+ }
31
+
32
+ fn transport < ' a > (
33
+ out : & ' a mut Vec < u8 > ,
34
+ path : & str ,
35
+ version : git_transport:: Protocol ,
36
+ ) -> git_transport:: client:: git:: Connection < std:: io:: Cursor < Vec < u8 > > , & ' a mut Vec < u8 > > {
37
+ let response = fixture_bytes ( path) ;
38
+ git_transport:: client:: git:: Connection :: new (
39
+ std:: io:: Cursor :: new ( response) ,
40
+ out,
41
+ version,
42
+ b"does/not/matter" . as_bstr ( ) . to_owned ( ) ,
43
+ None :: < ( & str , _ ) > ,
44
+ git_transport:: client:: git:: ConnectMode :: Process ,
45
+ )
46
+ }
47
+
25
48
mod v1 {
26
- use crate :: {
27
- fetch:: { CloneDelegate , LsRemoteDelegate } ,
28
- fixture_bytes,
29
- } ;
30
- use bstr:: ByteSlice ;
31
- use git_object:: owned;
49
+ use crate :: fetch:: { oid, transport, CloneDelegate , LsRemoteDelegate } ;
32
50
use git_protocol:: fetch;
51
+ use git_transport:: Protocol ;
33
52
34
53
#[ test]
35
54
#[ ignore]
36
55
fn clone ( ) -> crate :: Result {
37
56
let mut out = Vec :: new ( ) ;
38
57
git_protocol:: fetch (
39
- transport ( & mut out, "v1/clone.response" ) ,
58
+ transport ( & mut out, "v1/clone.response" , Protocol :: V1 ) ,
40
59
& mut CloneDelegate ,
41
60
git_protocol:: credentials:: helper,
42
61
) ?;
@@ -48,7 +67,7 @@ mod v1 {
48
67
let mut out = Vec :: new ( ) ;
49
68
let mut delegate = LsRemoteDelegate :: default ( ) ;
50
69
git_protocol:: fetch (
51
- transport ( & mut out, "v1/clone.response" ) ,
70
+ transport ( & mut out, "v1/clone.response" , Protocol :: V1 ) ,
52
71
& mut delegate,
53
72
git_protocol:: credentials:: helper,
54
73
) ?;
@@ -73,23 +92,47 @@ mod v1 {
73
92
) ;
74
93
Ok ( ( ) )
75
94
}
95
+ }
76
96
77
- fn oid ( hex_sha : & str ) -> owned:: Id {
78
- owned:: Id :: from_40_bytes_in_hex ( hex_sha. as_bytes ( ) ) . expect ( "valid input" )
79
- }
97
+ mod v2 {
98
+ use crate :: fetch:: { oid, transport, LsRemoteDelegate } ;
99
+ use bstr:: ByteSlice ;
100
+ use git_protocol:: fetch;
101
+ use git_transport:: Protocol ;
102
+
103
+ #[ test]
104
+ fn ls_remote ( ) -> crate :: Result {
105
+ let mut out = Vec :: new ( ) ;
106
+ let mut delegate = LsRemoteDelegate :: default ( ) ;
107
+ git_protocol:: fetch (
108
+ transport ( & mut out, "v2/clone.response" , Protocol :: V2 ) ,
109
+ & mut delegate,
110
+ git_protocol:: credentials:: helper,
111
+ ) ?;
80
112
81
- fn transport < ' a > (
82
- out : & ' a mut Vec < u8 > ,
83
- path : & str ,
84
- ) -> git_transport:: client:: git:: Connection < std:: io:: Cursor < Vec < u8 > > , & ' a mut Vec < u8 > > {
85
- let response = fixture_bytes ( path) ;
86
- git_transport:: client:: git:: Connection :: new (
87
- std:: io:: Cursor :: new ( response) ,
88
- out,
89
- git_transport:: Protocol :: V1 ,
90
- b"does/not/matter" . as_bstr ( ) . to_owned ( ) ,
91
- None :: < ( & str , _ ) > ,
92
- git_transport:: client:: git:: ConnectMode :: Process ,
93
- )
113
+ assert_eq ! (
114
+ delegate. refs,
115
+ vec![
116
+ fetch:: Ref :: Symbolic {
117
+ path: "HEAD" . into( ) ,
118
+ object: oid( "808e50d724f604f69ab93c6da2919c014667bedb" ) ,
119
+ target: "refs/heads/master" . into( )
120
+ } ,
121
+ fetch:: Ref :: Direct {
122
+ path: "refs/heads/master" . into( ) ,
123
+ object: oid( "808e50d724f604f69ab93c6da2919c014667bedb" )
124
+ }
125
+ ]
126
+ ) ;
127
+ assert_eq ! (
128
+ out. as_bstr( ) ,
129
+ b"0014command=ls-refs
130
+ 001aagent=git/oxide-0.1.0
131
+ 0001000csymrefs
132
+ 0009peel
133
+ 00000000"
134
+ . as_bstr( )
135
+ ) ;
136
+ Ok ( ( ) )
94
137
}
95
138
}
0 commit comments