'origin'似乎不是一个git仓库'

问题描述:

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

任何有识之士将不胜感激。

#!/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(); 
+0

尝试在添加存储库以查看它是否实际添加后停止该程序。 – lc2817

+0

尝试[Git :: Wrapper](http://search.cpan.org/perldoc/Git::Wrapper) –

这里至少有两个问题。

您还没有指示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命令,扔掉的错误,然后计算负载Ø f字符串顺序(也不是非常有用)。

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

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

您还需要修复git config行。

+2

除了关于如何解析断开的'system'命令,这大部分都是正确的。它实际上意味着'system(“git remote add origin git \ @ github.com:”,$ user,“/”,$ repo,“.git”);'即运行一个名为''git remote add origin git @ github.com:''传递4个参数:$ user,“/”,$ repo,“.git”。由于您可能没有命名的命令,因此失败,但您没有检查错误。 – cjm

+0

感谢您的建议,它非常有帮助,目前正在阅读'perldocs'atm。然而在改变为“或者死亡$!”之后在我的系统调用我现在得到一个错误:“坏文件描述符” – user1020372

+2

系统成功返回0,不像大多数其他事情。检查$也是没有用的!而不是$ ?.我会建议在顶部使用'use autodie'系统''(内部使用IPC :: System :: Simple) – ysth