2017-07-27 65 views
1

我正在编写一个自定义Perl脚本,它应该能够以编程方式处理合并冲突,并在GIT用户执行git rebase命令时进行最小交互。目前,我能够检测到if GIT进入REBASE状态,我在while循环内执行我的命令列表。但问题是我无法检测GIT何时离开REBASE状态。如何通过自定义Perl脚本处理合并冲突

定制的Perl脚本

while(system("ls `git rev-parse --git-dir` | grep rebase") eq 'rebase-apply/'){ 
     my $mergeToolMsg=system("git mergetool"); 
     chomp $mergeToolMsg; 
     if($mergeToolMsg != 0){ 
      //This doesnt hit even 
      last; 
     }else{ 
      system("git rebase --continue"); 
     } 

    } 

我的要求是,我怎样才能终止循环,如果没有合并冲突或请让我知道是否有任何其他更好的方式来做到这一点。

+0

ch the退出状态是无用的。 – choroba

回答

1

system返回该命令的退出状态,而不是其输出。检查`qxperlop中存储外部命令输出的方式。

+0

我怎样才能捕捉出内部while循环和检查condition.i试着下面的方式,而不是工作.'while('ls \'git rev-parse --git-dir \'| grep rebase || echo没有rebase 'eq'rebase-apply'){ print“in rebase state”; }' – gihan

0

终于可以做到了。请让我知道是否有更好的方法来做到这一点。

my $ifRebaseState=`ls \`git rev-parse --git-dir\` | grep rebase || echo no rebase`; 
    chomp $ifRebaseState; 
    while($ifRebaseState eq "rebase-apply"){ 
     $ifRebaseState=`ls \`git rev-parse --git-dir\` | grep rebase || echo no rebase`; 
     chomp $ifRebaseState; 
     my $ifMergeNeed=`git mergetool`; 
     chomp $ifMergeNeed; 
     if($ifMergeNeed ne "No files need merging"){ 
      system("git rebase --continue"); 
     }else{ 
      last; 
     } 

    }