如何以编程方式集成2个分支

时间:2015-09-29 20:45:20

标签: perforce perforce-integrate p4.net

我的仓库里有两个分店。

  //depot/project/mainline/...
  //depot/project/staging/...

我正在使用一个管理项目构建的内部工具,并希望创建一个构建步骤,自动将所有文件从主线升级到分段。我一直在尝试使用p4.net API编写它,遵循以下example。我能够从构建工具运行powershell命令。我的计划是编写一个c#控制台应用程序,使用该工具编译它,然后将其作为构建步骤执行。不幸的是,这个例子让我无处可去。我能够创建一个客户端,创建一个分支规范甚至同步文件,但我为我的生活无法弄清楚如何提交集成。 我觉得我正试图过度设计一个解决方案。这应该很容易做到。我在下面附上我破碎的代码。如果它没有意义,那是因为我正在使用反复试验来解决问题并且还没有最终通过它。也就是说,如果我不需要使用p4 api,那就更好了。唯一的要求是运行命令不需要用户输入。如果存在合并冲突,我想自动接受源。

由于

        string uri = "server";
        string user = "user";
        string pass = null;
        string ws_client = "Project-Temp-"+ Guid.NewGuid().ToString();


        Server server = new Server(new ServerAddress(uri));
        Repository rep = new Repository(server);
        Connection con = rep.Connection;

        con.UserName = user;
        con.Client = new Client();
        con.Client.Name = ws_client;
        con.Client.ViewMap = new ViewMap();

        con.Connect(null);
        Credential cred = con.Login(pass, null, null);
        rep.DeleteClient(con.Client, null);
        rep.CreateClient(con.Client);
        con.Client.ViewMap.Clear();
        con.Client.ViewMap.Add("//depot/project/...", String.Format("//{0}/...", con.Client.Name), MapType.Include);
        rep.UpdateClient(con.Client);

        var files = con.Client.SyncFiles(new SyncFilesCmdOptions(SyncFilesCmdFlags.None, -1));

        ViewMap vm = new ViewMap();
        vm.Add(new MapEntry(MapType.Include,new ClientPath("//depot/project/mainline/..."), new ClientPath("//depot/project/staging/...")));
        string msg = "Mainline to Staging";
        BranchSpec bs = new BranchSpec("Project-Temp", user, DateTime.Now, DateTime.Now, msg, true, vm, null, null);
        int change = -1;
        IntegrateFilesCmdOptions BranchOptions = new IntegrateFilesCmdOptions(IntegrateFilesCmdFlags.None, change, -1, "Project-Temp", null, null);
        rep.CreateBranchSpec(bs);
        rep.UpdateClient(con.Client);


        var integrated = con.Client.IntegrateFiles(BranchOptions);
        con.Client.ResolveFiles(files, new ResolveCmdOptions(ResolveFilesCmdFlags.AutomaticYoursMode, change));


        rep.DeleteClient(con.Client, null);

1 个答案:

答案 0 :(得分:2)

从命令行开始,这是:

p4 integrate //depot/project/mainline/... //depot/project/staging/...
p4 resolve -am
p4 resolve -at
p4 resolve -ay
p4 submit -d "Integrate."

"解决-am"自动注释所有文件而不会发生冲突。 "解决-at"接受所有剩余文件的来源。 在非常可能的情况下,有源文件无法被接受(例如,源修订已被删除,或源和目标操作不兼容),"解决-ay"忽略它们。

相关问题