どのように私はSharpSVNを使用してSVNプリコミットメッセージへのアクセスを得ることができますか?

StackOverflow https://stackoverflow.com/questions/1380685

質問

私はすべて私がすることです%レポ%および%TXN%

に設定することができていることがわかり

どのように私は、コミットメッセージ(私の場合は、それはそれにコミットする前にバグデータベースに存在する場合、私が見ることができるので、私は、チケット番号を解析することができますので)

に到達するために、これらを使用することができます
役に立ちましたか?

解決

SharpSvn には、

を使用することができます解放し、最近の使い方
SvnHookArguments ha; 
if (!SvnHookArguments.ParseHookArguments(args, SvnHookType.PreCommit, false, out ha))
{
    Console.Error.WriteLine("Invalid arguments");
    Environment.Exit(1);  
}

前のcommitフックの引数を解析し、

を使用するには
using (SvnLookClient cl = new SvnLookClient())
{
    SvnChangeInfoEventArgs ci;

    cl.GetChangeInfo(ha.LookOrigin, out ci);


    // ci contains information on the commit e.g.
    Console.WriteLine(ci.LogMessage); // Has log message

    foreach (SvnChangeItem i in ci.ChangedPaths)
    {

    }
}

などのログメッセージ、変更されたファイル、を取得する。

他のヒント

私はあなたが説明するように、あなたがフックスクリプトを作成する場合しかし、あなたは%レポ%および%TXN%

引数として取得し、SharpSVNを知りません

は、これらのデータを使用すると、指定したリポジトリのトランザクション(%TXN%)に見ることができます。通常、あなたが使用して行います。

svnlook -t %txn%  %repo%

そして、あなたは、ログ・メッセージが表示されます。

あなたはsharpSVNインターフェイスでsvnlookに相当探さなければならないので。

私はsvnlook.exeのためのC#ラッパーを書いたいくつかの時間前。私は(チケットIDが提供された場合)、バグトラッカーにコミットメッセージを送信するには、このいずれかを使用していました。以下にそれを見つけ、多分それはあなたのために便利です。

/// <summary>
/// Encapsulates the SVNLook command in all of it's flavours
/// </summary>
public static class SvnLookCommand
{
    /// <summary>
    /// The string &quot;&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string AUTHOR = "author";

    /// <summary>
    /// The string &quot;cat&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string CAT = "cat";

    /// <summary>
    /// The string &quot;changed&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string CHANGED = "changed";

    /// <summary>
    /// The string &quot;date&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string DATE = "date";

    /// <summary>
    /// The string &quot;diff&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string DIFF = "diff";

    /// <summary>
    /// The string &quot;dirs-changed&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string DIRSCHANGED = "dirs-changed";

    /// <summary>
    /// The string &quot;history&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string HISTORY = "history";

    /// <summary>
    /// The string &quot;info&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string INFO = "info";

    /// <summary>
    /// The string &quot;lock&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string LOCK = "lock";

    /// <summary>
    /// The string &quot;log&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string LOG = "log";

    /// <summary>
    /// The string &quot;tree&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string TREE = "tree";

    /// <summary>
    /// The string &quot;uuid&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string UUID = "uuid";

    /// <summary>
    /// The string &quot;youngest&quot; used as parameter for the svnlook.exe
    /// </summary>
    private static readonly string YOUNGEST = "youngest";

    /// <summary>
    /// The full path of the svnlook.exe binary
    /// </summary>
    private static string commandPath = String.Empty;

    /// <summary>
    /// Initializes static members of the <see cref="SvnLookCommand"/> class.
    /// </summary>
    static SvnLookCommand()
    {
        commandPath = Settings.Default.SvnDirectoryPath;

        if (!Path.IsPathRooted(commandPath))
        {
            Assembly entryAssembly = Assembly.GetEntryAssembly();
            if (entryAssembly != null)
            {
                commandPath = new FileInfo(entryAssembly.Location).Directory.ToString() + Path.DirectorySeparatorChar + commandPath;
            }
        }

        if (!commandPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
        {
            commandPath = commandPath + Path.DirectorySeparatorChar;
        }

        commandPath += "svnlook.exe";
    }

    /// <summary>
    /// Gets the process info to start a svnlook.exe command with parameter &quot;author&quot;
    /// </summary>
    /// <param name="repository">The repository.</param>
    /// <param name="revision">The revision.</param>
    /// <returns>Gets the author of the revision in scope</returns>
    public static ProcessStartInfo GetAuthor(string repository, string revision)
    {
        ProcessStartInfo svnLookProcessStartInfo = new ProcessStartInfo(commandPath);
        svnLookProcessStartInfo.Arguments = String.Format("{0} {1} -r {2}", AUTHOR, repository, revision);
        return svnLookProcessStartInfo;
    }

    /// <summary>
    /// Gets the process info to start a svnlook.exe command with parameter &quot;log&quot;
    /// </summary>
    /// <param name="repository">The repository.</param>
    /// <param name="revision">The revision.</param>
    /// <returns>The svn log of the revision in scope</returns>
    public static ProcessStartInfo GetLog(string repository, string revision)
    {
        ProcessStartInfo svnLookProcessStartInfo = new ProcessStartInfo(commandPath);
        svnLookProcessStartInfo.Arguments = String.Format("{0} {1} -r {2}", LOG, repository, revision);
        return svnLookProcessStartInfo;
    }

    /// <summary>
    /// Gets the process info to start a svnlook.exe command with parameter &quot;changed&quot;
    /// </summary>
    /// <param name="repository">The repository.</param>
    /// <param name="revision">The revision.</param>
    /// <returns>The change log of the revision in scope</returns>
    public static ProcessStartInfo GetChangeLog(string repository, string revision)
    {
        ProcessStartInfo svnLookProcessStartInfo = new ProcessStartInfo(commandPath);
        svnLookProcessStartInfo.Arguments = String.Format("{0} {1} -r {2}", CHANGED, repository, revision);
        return svnLookProcessStartInfo;
    }

    /// <summary>
    /// Gets the process info to start a svnlook.exe command with parameter &quot;info&quot;
    /// </summary>
    /// <param name="repository">The repository.</param>
    /// <param name="revision">The revision.</param>
    /// <returns>The info of the revision in scope</returns>
    public static ProcessStartInfo GetInfo(string repository, string revision)
    {
        ProcessStartInfo svnLookProcessStartInfo = new ProcessStartInfo(commandPath);
        svnLookProcessStartInfo.Arguments = String.Format("{0} {1} -r {2}", INFO, repository, revision);
        return svnLookProcessStartInfo;
    }
}

私はフックを構築するプロセスを経てきた自分自身をアプリとSharpSVNはコミットメッセージを見てのために必要とされていません。

:あなたはすでに自分でコンソールアプリケーションを構築したと仮定すると、svnlook.exe直接呼び出して、このコードを試してみてください
string repos = args[0];
string txn = args[1];

var processStartInfo = new ProcessStartInfo
{
  FileName = "svnlook.exe",
  UseShellExecute = false,
  CreateNoWindow = true,
  RedirectStandardOutput = true,
  RedirectStandardError = true,
  Arguments = String.Format("log -t \"{0}\" \"{1}\"", txn, repos)
};

Process process = Process.Start(processStartInfo);
string message = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return message;
上記の任意の場所から実行できるように、

必ずsvnlook.exeの場所はあなたのマシンのPATH環境変数に追加されていることを確認します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top