1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
//! ref: composer/src/Composer/Downloader/HgDownloader.php
use crate::downloader::vcs_downloader::VcsDownloaderBase;
use crate::package::package_interface::PackageInterface;
use crate::util::hg::Hg as HgUtils;
use anyhow::Result;
use shirabe_external_packages::react::promise::promise_interface::PromiseInterface;
use shirabe_php_shim::RuntimeException;
#[derive(Debug)]
pub struct HgDownloader {
inner: VcsDownloaderBase,
}
impl HgDownloader {
pub(crate) fn do_download(
&self,
package: &dyn PackageInterface,
path: String,
url: String,
prev_package: Option<&dyn PackageInterface>,
) -> Result<Box<dyn PromiseInterface>> {
if HgUtils::get_version(&self.inner.process).is_none() {
return Err(RuntimeException {
message: "hg was not found in your PATH, skipping source download".to_string(),
code: 0,
}
.into());
}
Ok(shirabe_external_packages::react::promise::resolve(None))
}
pub(crate) fn do_install(
&self,
package: &dyn PackageInterface,
path: String,
url: String,
) -> Result<Box<dyn PromiseInterface>> {
let hg_utils = HgUtils::new(&self.inner.io, &self.inner.config, &self.inner.process);
let path_clone = path.clone();
let clone_command = move |url: String| -> Vec<String> {
vec![
"hg".to_string(),
"clone".to_string(),
"--".to_string(),
url,
path_clone.clone(),
]
};
hg_utils.run_command(clone_command, url, Some(path.clone()));
let command = vec![
"hg".to_string(),
"up".to_string(),
"--".to_string(),
package.get_source_reference().unwrap_or_default(),
];
let mut ignored_output = String::new();
if self.inner.process.execute(
&command,
&mut ignored_output,
shirabe_php_shim::realpath(&path),
) != 0
{
return Err(RuntimeException {
message: format!(
"Failed to execute {}\n\n{}",
command.join(" "),
self.inner.process.get_error_output()
),
code: 0,
}
.into());
}
Ok(shirabe_external_packages::react::promise::resolve(None))
}
pub(crate) fn do_update(
&self,
initial: &dyn PackageInterface,
target: &dyn PackageInterface,
path: String,
url: String,
) -> Result<Box<dyn PromiseInterface>> {
let hg_utils = HgUtils::new(&self.inner.io, &self.inner.config, &self.inner.process);
let ref_ = target.get_source_reference().unwrap_or_default();
self.inner.io.write_error(&format!(
" Updating to {}",
target.get_source_reference().unwrap_or_default()
));
if !self.has_metadata_repository(path.clone()) {
return Err(RuntimeException {
message: format!(
"The .hg directory is missing from {}, see https://getcomposer.org/commit-deps for more information",
path
),
code: 0,
}.into());
}
let pull_command = |url: String| -> Vec<String> {
vec!["hg".to_string(), "pull".to_string(), "--".to_string(), url]
};
hg_utils.run_command(pull_command, url.clone(), Some(path.clone()));
let ref_clone = ref_.clone();
let up_command = move |_url: String| -> Vec<String> {
vec![
"hg".to_string(),
"up".to_string(),
"--".to_string(),
ref_clone.clone(),
]
};
hg_utils.run_command(up_command, url, Some(path));
Ok(shirabe_external_packages::react::promise::resolve(None))
}
pub fn get_local_changes(
&self,
package: &dyn PackageInterface,
path: String,
) -> Option<String> {
if !std::path::Path::new(&format!("{}/.hg", path)).is_dir() {
return None;
}
let mut output = String::new();
self.inner.process.execute(
&["hg".to_string(), "st".to_string()],
&mut output,
shirabe_php_shim::realpath(&path),
);
let output = output.trim().to_string();
if !output.is_empty() {
Some(output)
} else {
None
}
}
pub(crate) fn get_commit_logs(
&self,
from_reference: String,
to_reference: String,
path: String,
) -> Result<String> {
let command = vec![
"hg".to_string(),
"log".to_string(),
"-r".to_string(),
format!("{}:{}", from_reference, to_reference),
"--style".to_string(),
"compact".to_string(),
];
let mut output = String::new();
if self
.inner
.process
.execute(&command, &mut output, shirabe_php_shim::realpath(&path))
!= 0
{
return Err(RuntimeException {
message: format!(
"Failed to execute {}\n\n{}",
command.join(" "),
self.inner.process.get_error_output()
),
code: 0,
}
.into());
}
Ok(output)
}
pub(crate) fn has_metadata_repository(&self, path: String) -> bool {
std::path::Path::new(&format!("{}/.hg", path)).is_dir()
}
}
|