SVN 预提交挂钩以确保 .csproj 中引用的所有文件都进行版本控制?

发布于 2024-12-10 23:02:56 字数 96 浏览 0 评论 0原文

有时,我们将 C# 项目文件提交到 SVN,该文件引用了我们忘记添加到 SVN 的文件。是否有任何预提交挂钩脚本可以解析 .csproj 文件并在引用未版本控制的文件时拒绝提交?

Occasionally we commit a C# project file to SVN that references files we forgot to add to SVN. Are there any pre-commit hook scripts out there that parse the .csproj file and reject the commit if it references unversioned files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

桃扇骨 2024-12-17 23:02:56
#!/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?";
        }
    }
}
#!/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?";
        }
    }
}
后来的我们 2024-12-17 23:02:56

如果您使用的是 Windows 服务器,您可以查看 Subversion Notify for Windows -http://sourceforge .net/projects/svn-notify/

我用它对提交消息进行简单的检查,以确保用户确认我们的内部规则。我还没有讨论任何其他预提交用途,但它可能值得一试!

I 引自手册:

预提交检查

 通过执行提交消息标准来确保存储库的完整性

 限制可以提交的文件类型(消除临时或开发人员特定配置文件的意外提交)

 执行文件类型检查 -可以提交的文件,但需要特殊的提交标签来确保它按照您的规则提交

 检查您的任务跟踪/错误跟踪系统,以确保它是有效的跟踪项目并且您的标准得到执行(无提交)例如,针对已关闭的错误)

If you are using a windows server, you can have a look at Subversion Notify for Windows -http://sourceforge.net/projects/svn-notify/

I use it to do a simple check on the commit message, to ensure users confirm with our in house rules. I have not gone into any of the other pre-commit uses, but it might be worth a shot!

I Quote from the Manual:

PRE-COMMIT CHECKS

 Ensure the integrity of your repository by enforcing commit message standards

 Restrict the types of files that can be committed (eliminate accidental commits of temporary or developer specific configuration files)

 Enforce file type checks - files that can be committed, but require a special commit tag to make sure it's being committed as per your rules

 Check against your task tracking/ bug tracking system to ensure it's a valid tracking item and your standards are enforced (no commits against closed bugs for example)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文