[英]Doing a Move and an edit in one Commit with Git TFS API in C#?
I am trying to edit one of our files and also move it to another place in our repo and so far have this setup: 我正在尝试编辑其中一个文件,并将其移动到我们的仓库中的另一个位置,到目前为止,已经进行了以下设置:
GitRepository repo = new GitRepository();
repo.Id = new Guid(RepositoryId);
repo.Url = "Working.url.goes.here.com";
repo.DefaultBranch = "heads/master";
GitRef defaultBranch = GitClient.GetRefsAsync(repo.Id, filter: repo.DefaultBranch).Result.First();
string result = testpath.Replace(ACTUALFILEPATH, "");
GitCommitRef newCommit;
List<GitChange> changes;
GitRefUpdate newBranch = new GitRefUpdate()
{
Name = currBranch,
OldObjectId = defaultBranch.ObjectId,
};
changes = new List<GitChange>(3);
//the changes for the test being edited
changes.Add(new GitChange()
{
ChangeType = VersionControlChangeType.Add,
Item = new GitItem() { Path = result },
NewContent = new ItemContent()
{
Content = TestContent,
ContentType = ItemContentType.RawText
},
});
//the changes for the csproj file
changes.Add(new GitChange()
{
ChangeType = VersionControlChangeType.Edit,
Item = new GitItem() { Path = projPath },
NewContent = new ItemContent()
{
Content = projContent,
ContentType = ItemContentType.RawText
},
});
//The deletion of the old file
changes.Add(new GitChange()
{
ChangeType = VersionControlChangeType.Delete,
Item = new GitItem() { Path = origpath },
});
newCommit = new GitCommitRef()
{
Comment = commitmessage,
Changes = changes.ToArray()
};
GitPush push = GitClient.CreatePushAsync(new GitPush()
{
RefUpdates = new GitRefUpdate[] { newBranch },
Commits = new GitCommitRef[] { newCommit },
Repository = repo
}, repo.Id).Result;
return result;
Everytime I try to run it, either the delete causes an error that says you cant modify the same file twice in one commit, or if I move the delete to before it says the file doesnt exist in the directory of the branch. 每次我尝试运行它时,删除都会导致一个错误,提示您一次提交不能两次修改同一文件,或者在删除之前将其移动到分支目录中不存在该文件之前。
What I need: To be able to move a test from one directory to another, edit its contents, and also edit the contents of another file, and push all that to the server. 我需要什么:为了能够将测试从一个目录移动到另一个目录,编辑其内容,还编辑另一个文件的内容,然后将所有内容推送到服务器。
Other Notes: Use of Powershell and Cmd are very limited. 其他说明:Powershell和Cmd的使用非常有限。
Any Thoughts or suggestions or know what is wrong? 有任何想法或建议,或知道有什么问题吗? Thanks so much for helping!
非常感谢您的帮助!
Well, after testing for several more hours, I finally figured it out.. 好了,经过几个小时的测试,我终于找到答案了。
I was using the wrong argument for origpath, and was passing it the same path as the new file that I was adding. 我为origpath使用了错误的参数,并以与我要添加的新文件相同的路径传递了它。
TLDR: Double check your arguments when writing a function TLDR:编写函数时,请仔细检查您的参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.