Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$mol_build added MAM_NO_PULL, back init existing not-git directory #736

Merged
merged 3 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions build/ensure/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,39 @@ namespace $ {
return this.is_git(path) || this.submodules().has(path)
}

protected override init_existing(dir: string) {
protected repo_ensured(dir: string) {
const repo = this.repo(dir)
if (! repo) return null
if (! repo) throw new Error(`"${dir}" not a repo`)
return repo
}

@ $mol_mem_key
protected branch_remote(dir: string) {
const repo = this.repo_ensured(dir)

const res = this.$.$mol_run.spawn( { command: ['git', 'remote', 'show', repo.url ], dir } )

return res.stdout.toString().match( /HEAD branch: (.*?)\n/ )?.[1] ?? 'master'
}

protected override init_existing(dir: string) {
// Например, если вручную склонить ревизию папки в глубине (например, hyoo/mol) перед запуском билда,
// то hyoo надо проинициалзировать в соответствии с meta.ree
const repo = this.repo_ensured(dir)
const { url, branch } = repo
this.$.$mol_run.spawn( { command: ['git', 'init'], dir } )

this.$.$mol_log3_warn({
place: `${this}.init_existing()`,
message: 'directory exsists in meta.tree, but not an a git repository',
dir,
hint: `git pull ${url} ${branch ?? 'master'}`,
})
const branch_norm = branch ?? this.branch_remote(dir)

this.$.$mol_run.spawn( { command: [ 'git', 'remote', 'add', '--track', branch_norm, 'origin' , url ], dir } )
this.$.$mol_run.spawn( { command: [ 'git', 'pull', 'origin', branch_norm ], dir } )

return null
}

protected override init(path: string) {
const mod = this.$.$mol_file.absolute( path )
const repo = this.repo(path)
if (! repo) throw new Error(`"${path}" not a repo`)
const repo = this.repo_ensured(path)

const command = [
'git', 'clone' , '--depth', '1',
Expand Down
9 changes: 8 additions & 1 deletion build/ensure/vcs/vcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,18 @@ namespace $ {
}
}

protected pull_disabled() {
return Boolean(this.$.$mol_env()['MAM_PULL_DISABLED'])
}

@ $mol_mem_key
ensure( path : string ) {

const mod = $mol_file.absolute( path )

if( mod.exists()) {
if( mod.exists() ) {
if ( this.pull_disabled() ) return false

if (! this.inited(path)) {
if (! this.repo(path) ) return false

Expand Down