gpt4 book ai didi

visual-studio - SVN 预提交 Hook 以确保 .csproj 中引用的所有文件都是版本化的?

转载 作者:行者123 更新时间:2023-12-04 21:49:22 25 4
gpt4 key购买 nike

有时我们会向 SVN 提交一个 C# 项目文件,其中引用了我们忘记添加到 SVN 的文件。是否有任何预提交钩子(Hook)脚本可以解析 .csproj 文件并在它引用未版本控制的文件时拒绝提交?

最佳答案

#!/usr/bin/perl
# Checks for source files which have been added to a csproj in a commit
# but haven't themselves been committed.
use Modern::Perl;
use warnings FATAL => 'syntax';
use File::Basename qw(basename);
use XML::Simple;

die "usage: $0 repo transaction\n" if @ARGV != 2;
my $opt = "-t"; # -r for testing
my ($repos, $txn) = @ARGV;

# If you really, really want to add a file to the proj and
# not commit it, start your commit message with a !
my @info = `svnlook info $opt $txn "$repos"`;
exit 0 if ($info[3] =~ /\A!/);

my @lines = `svnlook changed $opt $txn "$repos"`;

my @projects = grep { /\AU/ }
grep { /[.]csproj\z/ }
map { chomp; $_ } @lines;

my @filelist = `svnlook tree $opt $txn "$repos" --full-paths`;
my %present;

foreach (@filelist) {
chomp;
$present{$_} = 1;
}

foreach (@projects) {
m"\AU.\s\s([\w/.]+/)([\w]+\.csproj)\z" or die "bad line $_";
my ($path, $proj) = ($1, $2);

my $projfile = `svnlook cat $opt $txn "$repos" $path/$proj`;
my $xml = XMLin($projfile);

# Tested with VS 2012 project files
my @includes = @{$xml->{ItemGroup}->[1]->{Compile}};
# All the source files in the csproj
my @filenames = map {$_->{Include}} @includes;

foreach (@filenames) {
# ignore "../etc", not below the project file in the tree
next if /\A[.][.]/;
# if you have files that are in the proj but shouldn't be committed
# eg some generated files, add checks for them here
# next if /MyGeneratedFile.cs\z/;

my $file = $path . $_;
# The csproj file speaks windows paths, but svn will output unix ones
$file =~ tr|\\|/|;

if (!defined $present{$file}) {
die "The file $file is included in the project $path\\$proj, but is not present in the tree, did you forget to commit it?";
}
}
}

关于visual-studio - SVN 预提交 Hook 以确保 .csproj 中引用的所有文件都是版本化的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7797942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com