parent
9dc6f9d214
commit
a6c0b5884a
@ -0,0 +1,14 @@
|
|||||||
|
const State = require('../State')
|
||||||
|
const Repository = require('../../git/Repository')
|
||||||
|
|
||||||
|
class AbstractGitState extends State {
|
||||||
|
|
||||||
|
async _repo() {
|
||||||
|
const path = await this._host.get_path(this._config.path)
|
||||||
|
if ( !path.is_valid() ) await path.touch(true)
|
||||||
|
return new Repository(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = AbstractGitState
|
@ -0,0 +1,31 @@
|
|||||||
|
const AbstractGitState = require('./AbstractGitState')
|
||||||
|
|
||||||
|
class TagState extends AbstractGitState {
|
||||||
|
|
||||||
|
async apply() {
|
||||||
|
if ( !(await this.check()) ) {
|
||||||
|
const repo = await this._repo()
|
||||||
|
await repo.create_tag(this._config.tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async check() {
|
||||||
|
const repo = await this._repo()
|
||||||
|
try {
|
||||||
|
await repo.get_tag(this._config.tag)
|
||||||
|
return true
|
||||||
|
} catch (e) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async reverse() {
|
||||||
|
if ( await this.check() ) {
|
||||||
|
const repo = await this._repo()
|
||||||
|
await repo.delete_tag(this._config.tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = TagState
|
Loading…
Reference in new issue