0
ローカルドライブにレポをクローンしました。 libgit2sharpを使ってブランチを作成することができました。以下は私が使ったコードです。libgit2sharpは特定のブランチにのみファイルをコミットできません。ヘルプが必要
//Clone
var WorkDir = Repository.Clone(<git-url>, <local-path>);
//Branch create
var branch = repo.CreateBranch("<branchName>");
repo.Branches.Update(branch,
b => b.Remote = repo.Network.Remotes["origin"].Name,
b => b.UpstreamBranch = branch.CanonicalName);
repo.Network.Push(branch);
上記のコードが動作し、ローカルの.gitフォルダとgitサーバーの両方でブランチが表示されています。
しかし、作成したブランチにファイルをコミットしようとすると、リモートのgitでは表示されません。
以下はコードです。
Commands.Stage(repo, <local-clone-path-with-file>);
serName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split(new string[] { "\\" }, StringSplitOptions.None)[1];
// Create the committer's signature and commit
Signature author = new Signature(userName,userName+"@atkinsglobal.com", DateTime.Now);
Signature committer = author;
string comment = timeStamp + "_" + "<BranchName>" + "_" + userName;
//// Commit to the repository
Commit commit = repo.Commit(comment+"_initial", author, committer);
Remote remote = repo.Network.Remotes["origin"];
repo.Network.Push(remote, @"refs/heads/"+<BranchName>, new PushOptions());
注意してください:要件は、ファイルのみを指定したブランチにコミットしなければならないということで、マスター・ブランチは、これらのファイルを持っていなければなりません。