2020-03-05 18:15:00 +00:00
|
|
|
const AbstractGitState = require('./AbstractGitState')
|
2020-03-05 17:48:38 +00:00
|
|
|
|
2020-06-14 14:07:26 +00:00
|
|
|
// TODO add 'bare' option
|
|
|
|
// TODO add 'new_repo' option (rm -rf .git && git init)
|
2020-03-05 18:15:00 +00:00
|
|
|
class CloneState extends AbstractGitState {
|
2020-03-05 17:48:38 +00:00
|
|
|
|
|
|
|
async apply() {
|
|
|
|
if ( !(await this.check()) ) {
|
|
|
|
const repo = await this._repo()
|
|
|
|
await repo.clone(this._config.source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async check() {
|
|
|
|
const repo = await this._repo()
|
|
|
|
return repo.is_repo()
|
|
|
|
}
|
|
|
|
|
|
|
|
async reverse() {
|
|
|
|
if ( await this.check() ) {
|
|
|
|
const path = await this._host.get_path(this._config.path)
|
|
|
|
await path.unlink()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-15 14:11:10 +00:00
|
|
|
failure_message() {
|
|
|
|
return `Could not find the cloned Git repo at "${this._config.path}" on host "${this._host.name}."`
|
|
|
|
}
|
|
|
|
|
|
|
|
check_message() {
|
|
|
|
return this.failure_message()
|
|
|
|
}
|
2020-08-14 01:28:23 +00:00
|
|
|
|
|
|
|
display() {
|
|
|
|
return `Clone repo at ${this._config.source} to ${this._config.path}...`
|
|
|
|
}
|
2020-03-05 17:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = CloneState
|