public void TestCommitFiles() { Commit c = git.GetCommit("74af98c8b7bad77364e46965f68a9ccbf4c0dd6c"); if (c.EnumFiles().Count != 4) { Assert.Fail("Cannot enumerate files in commit!"); } }
public void TestCommitFileDiff() { Commit c = git.GetCommit("74af98c8b7bad77364e46965f68a9ccbf4c0dd6c"); if (Git.DiffFriendOutput(c.EnumFiles()[0].Diff).Count != 18) { Assert.Fail("Cannot get file history!"); } }
public static List <string> Commit(string key, List <int> indexes, string comment, string user) { List <string> output = new List <string>(); output.Add("Starting job..."); lock (_commitobj) { try { ListOfChanges changes = Get(key); string gitpath = Settings.CurrentSettings.WORKGIT; if (!Directory.Exists(Settings.CurrentSettings.WORKGIT)) { throw new Exception("Git Directory does not exist!: " + Settings.CurrentSettings.WORKGIT); } Git git = new Git(gitpath); output.AddRange(git.ResetHard()); output.AddRange(git.FetchAll()); output.AddRange(git.Checkout(changes.Branch)); if (git.CurrentBranch() != changes.Branch) { output.Add("Failed to switch branch!"); return(Git.DiffFriendOutput(output)); } output.AddRange(git.PullOrigin()); foreach (int i in indexes) { FileChange fc = changes[i]; string gitfile = fc.BST.Replace(@"S:\", gitpath).Replace(@"s:\", gitpath); string gitdir = Path.GetDirectoryName(gitfile); if (!Directory.Exists(gitdir)) { Directory.CreateDirectory(gitdir); } output.Add("Copying file: " + gitfile + "..."); File.Copy(fc.NEW, gitfile, true); output.AddRange(git.AddFile(gitfile)); } Commit oldcommit = git.GetTopCommit(); output.AddRange(git.CommitAll("WEB: " + comment, user)); Commit newcommit = git.GetTopCommit(); if (oldcommit.COMMIT == newcommit.COMMIT) { output.Add("-No files have been commited!"); } else { output.Add(string.Format("+{0} files have been commited!", newcommit.EnumFiles().Count)); } output.AddRange(git.PushCurrentBranch()); output.AddRange(git.ResetHard()); output.AddRange(git.Checkout("master")); Remove(key); } catch (Exception e) { output.Add(e.ToString()); } } return(Git.DiffFriendOutput(output)); }