2016-10-30 2 views
1

나는 작은 성공을 통해 자식에게 코드 백업을 자동화하려고 시도하고있다. 이 경우 나는 perl에서 시도하고있다. 현재 문제는 git이 실행될 때 적절한 디렉토리에 있어야한다는 것입니다. (세 번째 줄에주의하십시오.) 오류 : 치명적 : 잘못된 refspec 'dest = c : \ data \ git \ aperio \ Scratch \ src \ rich' 내 디렉토리를 다음과 같이 정의 할 수 있습니까? arg? 또는 디렉터리를 가리키는 환경에서 실행되는 것을 실패 했습니까?Perl에서 힘내 당기기

참고 : 나는 이것이 대부분의 힘내 명령에 문제가 될 것임을 알고 있습니다.

... 
    @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 "); 
+0

당신이 구현하고있는 것은 [rsync] (https://en.wikipedia.org/wiki/Rsync)와 하나의'git add .' 호출로 더 잘 할 수 있습니다. – Schwern

+0

처음부터 명령을 작성하거나 (git 또는 shell 문제), Perl (Perl 문제)에서 명령을 실행하는 데 문제가 있습니까? – ikegami

답변

5

예, the GIT_DIR environment variable or the --git-dir option이 사용하는 어떤 .git 디렉토리 자식에게 설정할 수 있습니다.

그러나 Git.pm 같은 것을 사용하는 것이 좋습니다.

use Git; 

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

이것은 쉘 벗어나 오류 처리 출력을 캡쳐하고 --git-dir 설정 잊는 등 많은 문제를 피할 수있다.