user7092160
user7092160

Reputation: 71

Git pull from perl

I'm attempting to automate code backups into git, with little success. In this case I'm attempting it in perl. My current issue is that git expects to be in the proper directory when run. (pay attention to the third line.) I'm receiving the error: fatal: Invalid refspec 'dest=c:\data\git\aperio\Scratch\src\rich' Is there a way to define my directory as an arg? Or failing that running in an environment pointed to the directory?

Note: I recognize this will be a problem for most git commands, not just the pull.

    ...
    @file=("deploy*.bat","deploy.ini","product.lic");
    system("$gitexe checkout integrate");
    system("$gitexe pull url=https://github.com/Aperio/aperio/Scratch/src/rich dest=c:\\data\\git\\aperio\\Scratch\\src\\rich");
    exit if ($testing);
    my $message="Changed: ";
    foreach $file (@file) {
        my ($src,$git,$timestamp,$sb,$message);
        my @files = glob($file);
        foreach my $f (@files) {
            $git=$gitdir."\\rich\\".$f;
            say $git;
            # Update git if needed
            if ((stat($git))[9] < (stat($f))[9]) { 
                $message.="$f, ";
                system("robocopy.exe . $gitdir /R:3 /Z /XO $f"); # Copy file to git folder
                system("$gitexe add $gitdir\\rich\\$f");
            }
        }
    }
    system("$gitexe commit -m $message");
    system("$gitexe status");
    system("$gitexe push origin ");

Upvotes: 1

Views: 1573

Answers (1)

Schwern
Schwern

Reputation: 164709

Yes, you can set the GIT_DIR environment variable or the --git-dir option to tell git what .git directory to use.

However, you're better off using something like Git.pm.

use Git;

my $repo = Git->repository(Directory => '/srv/git/cogito.git');
$repo->command("commit", "-m", $message);

This avoids numerous problems like shell escaping, error handling, capturing output, and forgetting to set --git-dir.

Upvotes: 5

Related Questions