@@ -46,93 +46,33 @@ def _create_clone_command(ssh_command, repo, dest) -> str:
46
46
47
47
48
48
def do_clone (
49
- ssh_command : str , repo : str , profile : Profile , dest : str , add_to_known_hosts = False
50
- ):
49
+ ssh_command : str ,
50
+ repo : str ,
51
+ dest : str ,
52
+ add_to_known_hosts = False ,
53
+ ) -> None :
51
54
if add_to_known_hosts :
52
55
ssh_command = f"{ ssh_command } -o StrictHostKeyChecking=no"
53
56
54
57
cmd = _create_clone_command (ssh_command , repo , dest )
55
58
56
- pipes = subprocess .Popen (
59
+ process = subprocess .Popen (
57
60
cmd ,
58
61
stdout = subprocess .PIPE ,
59
- stderr = subprocess .PIPE ,
60
62
shell = True ,
61
63
)
62
- stdout , stderr = pipes .communicate ()
63
64
64
- if pipes .returncode != 0 :
65
- ux .print_header ("CLONE FAILED" , newlines_before = 2 )
65
+ print ()
66
66
67
- stdout , stderr = (
68
- i .decode ("utf-8" ).replace ("\r " , "" ).strip () for i in (stdout , stderr )
69
- )
70
- stdcombined = stdout + stderr
71
-
72
- print (stdout )
73
- print (stderr )
74
-
75
- def advice ():
76
- ux .print_header ("ADVICE" , newlines_before = 2 )
67
+ for c in iter (lambda : process .stdout .read (1 ), b"" ):
68
+ sys .stdout .buffer .write (c )
77
69
78
- not_in_known_hosts = re . findall (
79
- r"Host key verification failed" ,
80
- stdcombined ,
81
- re . MULTILINE ,
70
+ process . wait ()
71
+ if process . returncode != 0 :
72
+ print (
73
+ f" \n Error: clone failed. Please view the error message above for details."
82
74
)
83
-
84
- if re .match ("Identity file (.*) not accessible" , stdcombined ):
85
- advice ()
86
- print ("Your SSH key seems to be missing." )
87
- elif "Permission denied" in stdcombined :
88
- advice ()
89
-
90
- pub = ssh .get_public_key (profile .ssh_key )
91
- print (f"\n Your SSH public key is:\n \n { pub } " )
92
-
93
- ux .sleep (1 )
94
-
95
- url = services .get_ssh_url_for (profile .service )
96
- if url :
97
- print (
98
- f"You may need to add the SSH key to "
99
- f"your account on '{ profile .service } '."
100
- )
101
- yes = (
102
- ux .get_simple_input (
103
- question = "Would you like to open the settings page for this [Y/n]" ,
104
- default = "Y" ,
105
- show_default = False ,
106
- ).lower ()
107
- == "y"
108
- )
109
-
110
- if yes :
111
- import webbrowser
112
-
113
- webbrowser .open_new_tab (url )
114
-
115
- sys .exit (1 )
116
- elif not_in_known_hosts :
117
- print (stdcombined )
118
-
119
- if (
120
- ux .get_simple_input (
121
- question = "The remote server is not in 'known_hosts'. "
122
- "Would you like to add it? [Y/n]" ,
123
- default = "y" ,
124
- show_default = False ,
125
- newlines_before = 2 ,
126
- ).lower ()
127
- == "y"
128
- ):
129
- print (f"Cloning with '-o StrictHostKeyChecking=no' in SSH command..." )
130
- do_clone (ssh_command , repo , profile , dest , add_to_known_hosts = True )
131
- else :
132
- print (f"Sorry, cannot clone when the host key is not accepted." )
133
- sys .exit (1 )
134
- else :
135
- sys .exit (1 )
75
+ sys .exit (1 )
136
76
137
77
138
78
@root .command ("clone" , help = "Clone a Git repository" )
@@ -173,7 +113,7 @@ def clone(repo: str, profile: str):
173
113
dest = re .findall (r".*/(.*?)\.git" , repo )[0 ]
174
114
ssh_command = ssh .get_ssh_command (ssh_key )
175
115
176
- do_clone (ssh_command , repo , profile , dest )
116
+ do_clone (ssh_command , repo , dest )
177
117
cwd = os .getcwd ()
178
118
179
119
try :
0 commit comments