From 977f5756de1cc8aa617c22da34b9d6cb332551d8 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sat, 8 Feb 2025 14:22:23 +0300 Subject: [PATCH 1/3] $mol_build added MAM_NO_PULL, back init existing not-git directory --- build/ensure/git/git.ts | 25 +++++++++++++++++-------- build/ensure/vcs/vcs.ts | 6 ++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/build/ensure/git/git.ts b/build/ensure/git/git.ts index 7de59470da8..2e406de8fe1 100644 --- a/build/ensure/git/git.ts +++ b/build/ensure/git/git.ts @@ -117,18 +117,27 @@ namespace $ { return this.is_git(path) || this.submodules().has(path) } - protected override init_existing(dir: string) { + @ $mol_mem_key + protected branch_remote(dir: string) { const repo = this.repo(dir) - if (! repo) return null + if (! repo) return 'master' + + 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(dir) + if (! repo) throw new Error(`"${dir}" not a repo`) 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 } diff --git a/build/ensure/vcs/vcs.ts b/build/ensure/vcs/vcs.ts index 2865389d0a0..c3849be98d3 100644 --- a/build/ensure/vcs/vcs.ts +++ b/build/ensure/vcs/vcs.ts @@ -68,8 +68,14 @@ namespace $ { } } + protected no_pull() { + return Boolean(this.$.$mol_env()['MAM_NO_PULL']) + } + @ $mol_mem_key ensure( path : string ) { + if (this.no_pull()) return false + const mod = $mol_file.absolute( path ) if( mod.exists()) { From 33cf2e05529c2f10dcd69e21e38fb9840fc0f242 Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sat, 8 Feb 2025 14:26:50 +0300 Subject: [PATCH 2/3] $mol_build comment about init non-git dir --- build/ensure/git/git.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/ensure/git/git.ts b/build/ensure/git/git.ts index 2e406de8fe1..a9e87419db5 100644 --- a/build/ensure/git/git.ts +++ b/build/ensure/git/git.ts @@ -128,7 +128,8 @@ namespace $ { } protected override init_existing(dir: string) { - // Если вручную hyoo/mol перед запуском билда, то hyoo надо проинициалзировать в соответствии с meta.ree + // Если вручную склонить ревизию hyoo/mol перед запуском билда, + // то hyoo надо проинициалзировать в соответствии с meta.ree const repo = this.repo(dir) if (! repo) throw new Error(`"${dir}" not a repo`) const { url, branch } = repo From 5624cebd59d00c243256e3751db082654cb8e32d Mon Sep 17 00:00:00 2001 From: Stefan Zerkalica Date: Sat, 8 Feb 2025 15:14:51 +0300 Subject: [PATCH 3/3] $mol_build review fixes --- build/ensure/git/git.ts | 17 ++++++++++------- build/ensure/vcs/vcs.ts | 9 +++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/build/ensure/git/git.ts b/build/ensure/git/git.ts index a9e87419db5..5f19c833696 100644 --- a/build/ensure/git/git.ts +++ b/build/ensure/git/git.ts @@ -117,10 +117,15 @@ namespace $ { return this.is_git(path) || this.submodules().has(path) } + protected repo_ensured(dir: string) { + const repo = this.repo(dir) + if (! repo) throw new Error(`"${dir}" not a repo`) + return repo + } + @ $mol_mem_key protected branch_remote(dir: string) { - const repo = this.repo(dir) - if (! repo) return 'master' + const repo = this.repo_ensured(dir) const res = this.$.$mol_run.spawn( { command: ['git', 'remote', 'show', repo.url ], dir } ) @@ -128,10 +133,9 @@ namespace $ { } protected override init_existing(dir: string) { - // Если вручную склонить ревизию hyoo/mol перед запуском билда, + // Например, если вручную склонить ревизию папки в глубине (например, hyoo/mol) перед запуском билда, // то hyoo надо проинициалзировать в соответствии с meta.ree - const repo = this.repo(dir) - if (! repo) throw new Error(`"${dir}" not a repo`) + const repo = this.repo_ensured(dir) const { url, branch } = repo this.$.$mol_run.spawn( { command: ['git', 'init'], dir } ) @@ -145,8 +149,7 @@ namespace $ { 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', diff --git a/build/ensure/vcs/vcs.ts b/build/ensure/vcs/vcs.ts index c3849be98d3..41809d9cea1 100644 --- a/build/ensure/vcs/vcs.ts +++ b/build/ensure/vcs/vcs.ts @@ -68,17 +68,18 @@ namespace $ { } } - protected no_pull() { - return Boolean(this.$.$mol_env()['MAM_NO_PULL']) + protected pull_disabled() { + return Boolean(this.$.$mol_env()['MAM_PULL_DISABLED']) } @ $mol_mem_key ensure( path : string ) { - if (this.no_pull()) return false 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