santosh
santosh

Reputation: 501

perforce: Source of integration in perforce

I am trying to find source of integration from one of my opened file on my perforce client.

My command :-

/grid/common/pkgs/perforce/v2018.1/bin/p4 -p 10.202.176.19:1641 -Ztag -F %clientFile% opened -c default -C cheruvu_client | /grid/common/pkgs/perforce/v2018.1/bin/p4 -p 10.202.176.19:1641 -F %fromFile% -x - resolved

Command working as expected when i run it explicitly.

But when i try to run in my script it's not working as expected.

My script :-

use strict;
use warnings;
my $Client = $ARGV[0];
my $ChangeNum = $ARGV[1];
my $Port = $ARGV[2];
my $p4 = "/grid/common/pkgs/perforce/v2018.1/bin/p4 -p $Port";
my @files = `$p4 -Ztag -F %clientFile% opened -c $ChangeNum -C $Client | $p4 -F %fromFile% -x - resolved`;
if (@files){
 foreach my $file(@files){
 chomp($file);
 if ($file =~ /\/\/depot\/vip\/src\/branches\/private_branch\/.*/i){
   print "Integrations from private_branch-> main is not allowed.\n\n";
  exit(1);
 }
 }
 }

@files array value is empty. Though i have opened file for integrate.

Purpose my script is to setup a trigger to avoid integrations from private_branch to main branch. Not sure is something is wrong in my command mentioned in script.

Run time arguments to script is passed while submitting file. There is no issue in run time argument parsing.

Please help.

Upvotes: 1

Views: 204

Answers (1)

Samwise
Samwise

Reputation: 71464

The commands you're running are getting an error message somewhere and the -F arguments you've passed are stripping it out:

my @files = `$p4 -Ztag -F %clientFile% opened -c $ChangeNum -C $Client | $p4 -F %fromFile% -x - resolved`;

Replace this with:

open(STDERR, ">&STDOUT");
my @files = `$p4 -Ztag -F %clientFile% opened -c $ChangeNum -C $Client | $p4 -x - resolved`;
print @files;

to find out what error message you're getting.

If that's empty too, back up a step:

open(STDERR, ">&STDOUT");
my @files = `$p4 -Ztag opened -c $ChangeNum -C $Client`;
print @files;

Once you can see the error message, it will tell you what's wrong with the way you're calling the command.

My hunch is that the problem is that your resolved command isn't using the same client that the files are opened on. If that's the case, the error will be something like no file(s) resolved; you can confirm by passing the filename to p4 opened (without specifying -C client) to see if it's open on the current client.

Upvotes: 2

Related Questions