user1020372
user1020372

Reputation: 41

'origin' does not appear to be a git repository'

I wrote a real simple Perl script to access GitHub and set up a repo, but I'm getting >>fatal: 'origin' does not appear to be a git repository error.

Any insight would be greatly appreciated.

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

Upvotes: 0

Views: 1152

Answers (1)

crazyscot
crazyscot

Reputation: 11989

There are at least two issues here.

You have not instructed perl to do anything with the command output, nor are you testing for errors, so any error messages and return codes are being thrown away. Go read perldoc -f system for how to trap that. At the very least rewrite your system calls like this:

system 'git init' or die $!;

What's actually going wrong is this line:

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

The comma operator does not join things together, so let me add some brackets to show you how that line looks to perl:

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

This runs a not-very-useful system command, throws away the error, and then evaluates a load of strings in order (also not very usefully).

If you want to join strings together use the period operator. Putting it together, you probably want something like this:

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

You will need to fix the git config lines as well.

Upvotes: 1

Related Questions