heroku/heroku-git

View on GitHub
src/commands/git/clone.ts

Summary

Maintainability
A
0 mins
Test Coverage
import {Command, flags} from '@heroku-cli/command'

import Git from '../../git'

export class GitClone extends Command {
  static description = 'clones a heroku app to your local machine at DIRECTORY (defaults to app name)'
  static example = `$ heroku git:clone -a example
Cloning into 'example'...
remote: Counting objects: 42, done.
...`
  static args = [
    {name: 'DIRECTORY', optional: true, description: 'where to clone the app'}
  ]
  static flags = {
    app: flags.string({char: 'a', env: 'HEROKU_APP', required: true, description: 'the Heroku app to use'}),
    remote: flags.string({char: 'r', description: 'the git remote to create, default "heroku"'}),
    'ssh-git': flags.boolean({description: 'use SSH git protocol'}),
  }
  async run() {
    const git = new Git()
    const {flags, args} = this.parse(GitClone)
    const {body: app} = await this.heroku.get(`/apps/${flags.app}`)
    const directory = args.DIRECTORY || app.name
    const remote = flags.remote || 'heroku'
    await git.spawn(['clone', '-o', remote, git.url(app.name, flags['ssh-git']), directory])
  }
}