我提交文件的常用方法是:
p4 submit –d “some description” filename
我能做到:
p4 submit
并使用编辑器,但我总是打开很多文件,因此该方法不方便
有几次,我错误地输入了
p4 submit –d "some description"
(忘了文件名)
这提交了数十个打开的文件到生产中,带来意想不到的后果。
恐慌的时候,花一个下午来进行伤害控制。
我想在未指定文件名时阻止p4 -d
。
答案 0 :(得分:0)
如果您使用的是Linux,您可以在.bashrs
文件中定义验证参数数量的函数,如果您错过了第4个参数,则不会让您提交。
function p4()
{
# validate what parameters are passed and if they are correct
# pass them to /opt/perforce/p4 ...
}
答案 1 :(得分:0)
谢谢@pitseeker
我创建了一个Perl包装器" p4s"它检查参数并将呼叫转发给真正的" p4提交"。
#!/usr/bin/perl
use warnings;
use strict;
use Capture::Tiny 'capture_merged';
die "Description and file is required!\n" if @ARGV < 2;
my ($description, @files) = @ARGV;
if ( -f $description ) {
die "It looks like you forgot the description before the filenames";
}
my $cmd;
my %summary;
print `date`;
for my $file (@files) {
if ( ! -f $file ) {
$summary{$file} = "File $file not found!";
next;
}
my $pwd = `pwd`;
chomp $pwd;
# print p4 filelog to screen
print `ls -l $file`;
$cmd = "p4 filelog $file | head -n 2";
$cmd = "p4 fstat -T 'headRev' $file";
print $cmd . "\n";
my $filelog = `$cmd`;
print "$filelog" . "\n";
$cmd = "p4 diff -sa $file";
my ($merged, $status) = Capture::Tiny::capture_merged {system($cmd)};
if ( ! $merged ) {
$summary{$file} = "Skipped since the local file does not differ from p4";
next;
}
# p4 submit
$cmd = "p4 submit -r -d \"$description\" $file";
print $cmd . "\n";
($merged, $status) = Capture::Tiny::capture_merged {system($cmd)};
chomp $merged;
print $merged . "\n";
if ( $merged =~ /No files to submit from the default changelist/ ) {
$summary{$file} = "$merged (You may need to 'p4 add' or 'p4 edit' this file)";
next;
}
$summary{$file} = "Success";
}
if ( scalar @files > 0 ) {
print "\nSummary:\n";
for my $file (@files) {
printf "%s %s\n", $file, $summary{$file};
}
}