'origin'似乎不是一个git存储库'

时间:2011-10-30 04:39:31

标签: perl git

我编写了一个真正简单的Perl脚本来访问GitHub并设置一个repo,但我收到>>fatal: 'origin' does not appear to be a git repository错误。

非常感谢任何见解。

#!/usr/bin/perl

use 5.006;
use strict;
#use warnings

my $file;
my $dir;
my $user;
my $email;
my $repo;

print ("Enter your user name\n");
$user = <STDIN>;
chomp $user;

print ("\nEnter your email address\n");
$email = <STDIN>;
chomp $email;

print ("\nEnter a directory path..\n");
$dir = <STDIN>;
chomp ($dir);

sub openDIR{
  if (opendir(DIR, $dir)) {
    chdir $dir;
    print ("You are now in directory >>> ", $dir, "\n");
    system 'touch README';
    system 'ls -l'
  } else {
    print ("The directory can not be found, please try again");
    die;

  }
}

sub git{
  print ("Enter the name of the repo you created on Git Hub.\n");
  $repo = <STDIN>;
  chomp $repo;

  system 'git config --global user.name', $user;
  system 'git config --global user.email', $email;

  system 'git init';  
  system 'git add README';
  system "git commit -m 'first commit'";
  system "git remote add origin git\@github.com:", $user,"/", $repo, ".git";
  system  'git push origin master'
}

openDIR();
git();

1 个答案:

答案 0 :(得分:1)

这里至少有两个问题。

您没有指示perl对命令输出执行任何操作,也没有测试错误,因此任何错误消息和返回代码都将被丢弃。请阅读perldoc -f system以了解如何捕获它。至少重写一次system这样的电话:

system 'git init' or die $!;

这条线实际出了什么问题:

system "git remote add origin git\@github.com:", $user,"/", $repo, ".git";

逗号运算符不会将事物连接在一起,所以让我添加一些括号来向您展示该行对perl的看法:

(system "git remote add origin git\@github.com:"), $user,"/", $repo, ".git";

这会运行一个非常有用的system命令,抛弃错误,然后按顺序评估一串字符串(也不是非常有用)。

如果要将字符串连接在一起,请使用句点运算符。把它放在一起,你可能想要这样的东西:

    system "git remote add origin git\@github.com:". $user."/". $repo. ".git" or die $!;

您还需要修复git config行。

相关问题