git-simple:致命:无法自动检测电子邮件地址

时间:2018-02-15 10:06:06

标签: node.js git

我正在尝试使用“git-simple”包提交。

我们的想法是使用github api提供的令牌进行身份验证,创建远程存储库,创建.gitignore然后设置文件。

这是我运行脚本的代码

const run = async () => {
try {
// Retrieve & Set Authentication Token
const token = await getGithubToken();
github.githubAuth(token);

// Create remote repository
const url = await repo.createRemoteRepo();

// Create .gitignore file
await repo.createGitignore();

// Setup local repository and push to remote
const done = await repo.setupRepo(url);

if(done) {
  console.log(chalk.green('All done!'));
}
} catch(err) {
  if (err) {
    switch (err.code) {
      case 401:
        console.log(chalk.red('Couldn\'t log you in. Please provide correct credentials/token.'));
        break;
      case 422:
        console.log(chalk.red('There already exists a remote repository with the same name'));
        break;
      default:
        console.log(err);
    }
  }
 }
}

在执行 repo.setupRepo(url)

之前,一切都很好

这里是setupRepo(url)的代码

    setupRepo : async(url) =>{
    const status = new Spinner('Initializing local repository and pushing to remote...')
    status.start()

    try{
        await git
            .init()
            .add('.gitignore')
            .add('./*')
            .commit('initial commit')
            .addRemote('origin',url)
            .push('origin','master')
        return true
    }
    catch(err){
        console.log(err)
    }
    finally{
        status.stop()
    }
}

我收到了这条消息:

 Git#then is deprecated after version 1.72 and will be removed in version 2.x
 Please switch to using Git#exec to run arbitrary functions as part of the 
 command chain.

 / Initializing local repository and pushing to remote...
 *** Please tell me who you are.

 Run

 git config --global user.email "you@example.com"
 git config --global user.name "Your Name"

 to set your account's default identity.
 Omit --global to set the identity only in this repository.

 fatal: unable to auto-detect email address (got 'Anes@DESKTOP-E9U575A.
(none)')

| Initializing local repository and pushing to remote...

当我打开我的github帐户时,我发现存储库已经创建但它是空的。

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

我也有这个问题。

如何解决?

请参阅下面的代码,将ssh_url更改为clone_url。

    createRemoteRepo: async () => {
    const github = gh.getInstance();
    const answers = await inquirer.askRepoDetails();

    const data = {
        name: answers.name,
        description: answers.description,
        private: (answers.visibility === 'private')
    };

    const status = new Spinner('Creating remote repository...');
    status.start();

    try {
        const response = await github.repos.create(data);
        // return response.data.ssh_url;
        return response.data.clone_url;
    } catch (err) {
        throw err;
    } finally {
        status.stop();
    }
}

详细回复请参阅此处create repo

为什么?

区别:SSH和https。Which remote URL should I use?

其他解决方案,但我没有试验。

ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts