Skip to content

Commit

Permalink
Merge pull request #733 from hyoo-ru/git-no-existing
Browse files Browse the repository at this point in the history
$mol_build_ensure_git do not init existing directory as git
  • Loading branch information
zerkalica authored Feb 6, 2025
2 parents 379c21e + 7dfe700 commit 0ba3283
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions build/ensure/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,18 @@ namespace $ {
return this.is_git(path) || this.submodules().has(path)
}

@ $mol_mem_key
protected branch_remote(dir: string) {
const repo = this.repo(dir)
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) {
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 } )
if (! repo) return null

const branch_norm = branch ?? this.branch_remote(dir)
const { url, branch } = repo

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 } )
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'}`,
})

return null
}
Expand Down

0 comments on commit 0ba3283

Please sign in to comment.