public static void Bind(GitClient client, GitUIBindArgs args) { if (client == null) throw new ArgumentNullException("client"); client.BindArgs = args; }
private void LoadChildControl(GitClient client) { Text = String.Format(Text, Type); switch (Type) { case PushType.Branch: _childControl = new PushBranchControl(); break; case PushType.Tag: _childControl = new PushTagControl(); break; default: throw new NotSupportedException(); } _childControl.Args = Args; _childControl.Context = Context; _childControl.RepositoryPath = RepositoryPath; _childControl.LoadFromClient(client); ((Control)_childControl).Dock = DockStyle.Fill; containerPanel.Controls.Add((Control)_childControl); }
protected GitCommand(GitClient client, GitClientArgs args) { if (client == null) throw new ArgumentNullException("client"); if (args == null) throw new ArgumentNullException("args"); Client = client; Args = args; }
public RevisionGridControl() { InitializeComponent(); Client = new GitClient(); ColumnHeadersVisible = false; Disposed += new EventHandler(RevisionGridControl_Disposed); }
/// <summary> /// Binds the specified client to the user interface defined by args /// </summary> /// <param name="client">The client to bind.</param> /// <param name="parentWindow">The parent window.</param> public static void Bind(GitClient client, IWin32Window parentWindow) { if (client == null) throw new ArgumentNullException("client"); GitUIBindArgs args = new GitUIBindArgs(); args.ParentWindow = parentWindow; Bind(client, args); }
protected void LoadRemoteUris(GitClient client, ComboBox urlBox) { foreach (string value in Config.GetRecentReposUrls()) { if (value != null) { if (!urlBox.Items.Contains(value)) urlBox.Items.Add(value); } } }
public override IDisposable Bind(GitClient client) { if (_clientArgs == null) throw new InvalidOperationException(); _clientArgs.Credentials += new EventHandler<GitCredentialsEventArgs>(_clientArgs_Credentials); _clientArgs.CredentialsSupported += new EventHandler<GitCredentialsEventArgs>(_clientArgs_CredentialsSupported); _clientArgs.Progress += new EventHandler<GitProgressEventArgs>(_clientArgs_Progress); return new UnbindDisposable(this); }
/// <summary> /// Binds the specified client to the user interface defined by args /// </summary> /// <param name="client">The client to bind.</param> /// <param name="args">The args.</param> public static void Bind(GitClient client, GitUIBindArgs args) { if (client == null) throw new ArgumentNullException("client"); else if (args == null) throw new ArgumentNullException("args"); GitClientUIHandler handler = new GitClientUIHandler(args.ParentWindow); handler.Bind(client, args); }
protected void LoadRemotes(GitClient client, ComboBox remoteBox) { var config = client.GetConfig(RepositoryPath); var currentBranch = client.GetCurrentBranch(RepositoryPath); string currentBranchRemote = config.GetString("branch", currentBranch.ShortName, "remote"); remoteBox.BeginUpdate(); remoteBox.Items.Clear(); foreach (string remote in config.GetSubsections("remote")) { remoteBox.Items.Add(remote); if (remote == currentBranchRemote) remoteBox.SelectedIndex = remoteBox.Items.Count - 1; } remoteBox.EndUpdate(); }
public virtual IDisposable Bind(GitClient client) { return null; }
public OutputPaneReporter(IVisualGitServiceProvider context, GitClient client) { if (context == null) throw new ArgumentNullException("context"); else if (client == null) throw new ArgumentNullException("client"); _mgr = context.GetService<IOutputPaneManager>(); _sb = new StringBuilder(); }
internal void Bind(GitClient client, GitUIBindArgs args) { //throw new NotImplementedException(); }
public async Task ShouldDetectChangesToRemotes() { Logger.Trace("Starting ShouldDetectChangesToRemotes"); try { Initialize(TestRepoMasterCleanSynchronized, initializeRepository: false); using (var repositoryWatcher = CreateRepositoryWatcher(TestRepoMasterCleanSynchronized)) { var watcherAutoResetEvent = new RepositoryWatcherAutoResetEvent(); var repositoryWatcherListener = Substitute.For <IRepositoryWatcherListener>(); repositoryWatcherListener.AttachListener(repositoryWatcher, watcherAutoResetEvent); repositoryWatcher.Initialize(); repositoryWatcher.Start(); repositoryWatcher.Stop(); try { Logger.Trace("Issuing Command"); await GitClient.RemoteRemove("origin").StartAsAsync(); await TaskManager.Wait(); Logger.Trace("Continue test"); repositoryWatcher.Start(); watcherAutoResetEvent.ConfigChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.RemoteBranchesChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.Reset(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.Received(1).ConfigChanged(); repositoryWatcherListener.DidNotReceive().RepositoryCommitted(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchesChanged(); repositoryWatcherListener.Received(1).RemoteBranchesChanged(); repositoryWatcherListener.ClearReceivedCalls(); repositoryWatcher.Stop(); Logger.Trace("Issuing 2nd Command"); await GitClient.RemoteAdd("origin", "https://github.com/EvilStanleyGoldman/IOTestsRepo.git").StartAsAsync(); await TaskManager.Wait(); Logger.Trace("Continue 2nd test"); repositoryWatcher.Start(); watcherAutoResetEvent.ConfigChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.RemoteBranchesChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.Received(1).ConfigChanged(); repositoryWatcherListener.DidNotReceive().RepositoryCommitted(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchesChanged(); repositoryWatcherListener.Received(1).RemoteBranchesChanged(); } finally { repositoryWatcher.Stop(); } } } finally { Logger.Trace("Ending ShouldDetectChangesToRemotes"); } }
public async Task ShouldDetectFileChangesAndCommit() { Logger.Trace("Starting ShouldDetectFileChangesAndCommit"); try { Initialize(TestRepoMasterCleanSynchronized, initializeRepository: false); using (var repositoryWatcher = CreateRepositoryWatcher(TestRepoMasterCleanSynchronized)) { var watcherAutoResetEvent = new RepositoryWatcherAutoResetEvent(); var repositoryWatcherListener = Substitute.For <IRepositoryWatcherListener>(); repositoryWatcherListener.AttachListener(repositoryWatcher, watcherAutoResetEvent); repositoryWatcher.Initialize(); repositoryWatcher.Start(); repositoryWatcher.Stop(); try { var foobarTxt = TestRepoMasterCleanSynchronized.Combine("foobar.txt"); Logger.Trace("Issuing Changes"); foobarTxt.WriteAllText("foobar"); await TaskManager.Wait(); Logger.Trace("Continue test"); repositoryWatcher.Start(); watcherAutoResetEvent.RepositoryChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.Reset(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().ConfigChanged(); repositoryWatcherListener.DidNotReceive().RepositoryCommitted(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.Received().RepositoryChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchesChanged(); repositoryWatcherListener.DidNotReceive().RemoteBranchesChanged(); repositoryWatcherListener.ClearReceivedCalls(); repositoryWatcher.Stop(); Logger.Trace("Issuing Command"); await GitClient.AddAll().StartAsAsync(); Logger.Trace("Completed Command"); repositoryWatcher.Start(); watcherAutoResetEvent.IndexChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.Reset(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().ConfigChanged(); repositoryWatcherListener.DidNotReceive().RepositoryCommitted(); repositoryWatcherListener.Received(1).IndexChanged(); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchesChanged(); repositoryWatcherListener.DidNotReceive().RemoteBranchesChanged(); repositoryWatcherListener.ClearReceivedCalls(); repositoryWatcher.Stop(); Logger.Trace("Issuing Command"); await GitClient.Commit("Test Commit", string.Empty).StartAsAsync(); Logger.Trace("Completed Command"); repositoryWatcher.Start(); watcherAutoResetEvent.RepositoryCommitted.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.IndexChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.Reset(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().ConfigChanged(); repositoryWatcherListener.Received(1).RepositoryCommitted(); repositoryWatcherListener.Received(1).IndexChanged(); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.Received(1).LocalBranchesChanged(); repositoryWatcherListener.DidNotReceive().RemoteBranchesChanged(); repositoryWatcherListener.ClearReceivedCalls(); } finally { repositoryWatcher.Stop(); } } } finally { Logger.Trace("Ending ShouldDetectFileChangesAndCommit"); } }
public void StatusTest() { string[] A = new string[] { "A/a", "A/b", "A/c", "A/d" }; string[] B = new string[] { "B/a", "B/b", "B/c", "B/d" }; string[] C = new string[] { "C/a", "C/b", "C/c", "C/d" }; List<string> all = new List<string>(); all.AddRange(A); all.AddRange(B); all.AddRange(C); using (GitRepository repo = GitRepository.Create(GetTempPath())) { foreach (string d in all) { string fp = Path.Combine(repo.WorkingCopyDirectory, d); Directory.CreateDirectory(Path.GetDirectoryName(fp)); File.WriteAllText(fp, string.Format("This is {0}\n", fp)); repo.Index.Add(d); } repo.Index.Write(); using (GitClient git = new GitClient()) { List<string> found = new List<string>(); GitStatusArgs sa = new GitStatusArgs(); git.Status(Path.Combine(repo.WorkingCopyDirectory, "B"), delegate(object sender, GitStatusEventArgs e) { found.Add(e.RelativePath); }); Assert.That(found.Count, Is.EqualTo(4)); Assert.That(found, Is.All.GreaterThan("B")); Assert.That(found, Is.All.LessThan("C")); found.Clear(); git.Status(Path.Combine(repo.WorkingCopyDirectory, "B/c"), delegate(object sender, GitStatusEventArgs e) { found.Add(e.RelativePath); }); Assert.That(found.Count, Is.EqualTo(1)); Assert.That(found, Is.All.Contains("B/c")); } } }
public void UseGitClient() { GitCommitArgs ga = new GitCommitArgs(); ga.Author.Name = "Tester"; ga.Author.EmailAddress = "*****@*****.**"; ga.Signature.Name = "Other"; ga.Signature.EmailAddress = "*****@*****.**"; // Use stable time and offset to always produce the same hash DateTime ct = new DateTime(2002, 01, 01, 0, 0, 0, DateTimeKind.Utc); ga.Author.When = ct; ga.Author.TimeOffsetInMinutes = 120; ga.Signature.When = ct; ga.Signature.TimeOffsetInMinutes = 120; string repoDir = GetTempPath(); string repo2Dir = GetTempPath(); GitId firstResult; GitId lastCommit; using (GitRepository repo = GitRepository.Create(repoDir)) using (GitClient git = new GitClient()) { string ignoreFile = Path.Combine(repoDir, ".gitignore"); string file = Path.Combine(repoDir, "newfile"); string subDir = Path.Combine(repoDir, "dir"); string fileInSubDir = Path.Combine(subDir, "file2"); string file3 = Path.Combine(repoDir, "other"); string file4 = Path.Combine(repoDir, "q.ignore"); File.WriteAllText(file, "Some body"); Directory.CreateDirectory(subDir); File.WriteAllText(fileInSubDir, "Some other body"); File.WriteAllText(file3, "file3"); File.WriteAllText(ignoreFile, "*.ignore\n"); File.WriteAllText(file4, "file4"); git.Add(ignoreFile); git.Add(file); git.Commit(repoDir, ga, out firstResult); git.Add(fileInSubDir); int ticked = 0; File.AppendAllText(file, "\nExtra Line"); GitStatusArgs gsa = new GitStatusArgs(); gsa.IncludeIgnored = true; gsa.IncludeUnmodified = true; Assert.That(git.Status(repoDir, gsa, delegate(object sender, GitStatusEventArgs e) { switch (e.RelativePath) { case "newfile": //Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.Added)); Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.Normal), "newfile index normal"); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Normal), "newfile wc modified"); Assert.That(e.WorkingDirectoryModified); Assert.That(e.Ignored, Is.False); break; case "dir/file2": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.New), "file2 index added"); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Normal), "file2 wc normal"); Assert.That(e.Ignored, Is.False); break; case "other": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.None)); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.New)); Assert.That(e.Ignored, Is.False); break; case ".gitignore": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.Normal)); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Normal)); Assert.That(e.Ignored, Is.False); break; case "q.ignore": // TODO: Make this ignored Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.None)); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Normal)); Assert.That(e.Ignored, Is.True); break; default: Assert.Fail("Invalid node found: {0}", e.RelativePath); break; } Assert.That(e.FullPath, Is.EqualTo(Path.GetFullPath(Path.Combine(repoDir, e.RelativePath)))); ticked++; }), Is.True); Assert.That(ticked, Is.EqualTo(5), "Ticked"); ga.LogMessage = "Intermediate"; git.Commit(repoDir, ga); Assert.That(git.Delete(fileInSubDir)); Assert.That(git.Add(file)); GitId commit; ga.LogMessage = "A log message to remember"; // The passed path is currently just used to find the local repository lastCommit = new GitId("996cf198b49ed6fce3bcba232e2d88eb473560f9"); Assert.That(git.Commit(repoDir, ga, out commit)); Assert.That(commit, Is.EqualTo(lastCommit)); File.Move(file, file + ".a"); ticked = 0; gsa.IncludeIgnored = false; gsa.IncludeUnversioned = true; gsa.IncludeUnmodified = false; Assert.That(git.Status(repoDir, gsa, delegate(object sender, GitStatusEventArgs e) { switch (e.RelativePath) { /*case "dir": * Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.Normal), "dir index normal"); * Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.New), "dir wc normal"); * break;*/ case "newfile": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.None), "newfile index normal"); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Deleted), "newfile wc deleted"); break; case "newfile.a": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.None), "newfile.a index normal"); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.New), "newfile.a wc new"); break; case "other": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.None), "other index normal"); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.New), "other wc normal"); break; default: Assert.Fail("Invalid node found: {0}", e.RelativePath); break; } Assert.That(e.FullPath, Is.EqualTo(Path.GetFullPath(Path.Combine(repoDir, e.RelativePath)))); ticked++; }), Is.True); Assert.That(ticked, Is.EqualTo(3)); GitCloneArgs gc = new GitCloneArgs(); gc.Synchronous = true; git.Clone(repoDir, repo2Dir, gc); GitCommit theCommit; Assert.That(repo.Lookup(commit, out theCommit)); Assert.That(repo.Branches.Create(theCommit, "vNext")); Assert.That(repo.Branches, Is.Not.Empty); } using (GitRepository repo1 = new GitRepository(repoDir)) using (GitRepository repo2 = new GitRepository(repo2Dir)) { GitReference head = repo1.HeadReference; Assert.That(head, Is.Not.Null, "Has head"); Assert.That(head.Name, Is.EqualTo("refs/heads/master")); //Assert.That(repo2.Head, Is.Not.Null); GitId headId; Assert.That(repo1.ResolveReference(repo1.HeadReference, out headId)); Assert.That(headId, Is.EqualTo(lastCommit)); GitCommit commit; Assert.That(repo1.Lookup(headId, out commit)); Assert.That(commit, Is.Not.Null, "Have a commit"); Assert.That(commit.Id, Is.EqualTo(lastCommit)); Assert.That(commit.Ancestors, Is.Not.Empty); Assert.That(commit.Ancestor, Is.Not.Null); Assert.That(commit.Ancestor.Ancestor, Is.Not.Null); Assert.That(commit.Ancestor.Ancestor.Ancestor, Is.Null); Assert.That(commit.Ancestor.Ancestor.Id, Is.EqualTo(firstResult)); Assert.That(commit.Author, Is.Not.Null); Assert.That(commit.Author.Name, Is.EqualTo("Tester")); Assert.That(commit.Author.EmailAddress, Is.EqualTo("*****@*****.**")); Assert.That(commit.Committer, Is.Not.Null); Assert.That(commit.Committer.Name, Is.EqualTo("Other")); Assert.That(commit.Committer.EmailAddress, Is.EqualTo("*****@*****.**")); Assert.That(commit.Committer.TimeOffsetInMinutes, Is.EqualTo(120), "Time offset"); // CEST dependent Assert.That(commit.Committer.When, Is.EqualTo(ct), "Exact time"); Assert.That(commit.LogMessage, Is.EqualTo("A log message to remember\n")); Assert.That(commit.Parents, Is.Not.Empty); Assert.That(commit.ParentIds, Is.Not.Empty); Assert.That(commit.Tree, Is.Not.Empty); Assert.That(commit.Tree.Count, Is.EqualTo(2)); Assert.That(commit.Ancestor.Tree.Count, Is.EqualTo(3)); Assert.That(commit.Ancestor.Ancestor.Tree.Count, Is.EqualTo(2)); Assert.That(commit.Tree.Id, Is.Not.EqualTo(commit.Ancestor.Tree.Id)); GitId id; Assert.That(repo1.LookupViaPrefix(commit.Id.ToString(), out id)); Assert.That(id, Is.EqualTo(commit.Id)); Assert.That(repo1.LookupViaPrefix(commit.Id.ToString().Substring(0, 10), out id)); Assert.That(id, Is.EqualTo(commit.Id)); Assert.That(commit.Peel <GitObject>().Id, Is.EqualTo(commit.Tree.Id)); Assert.That(commit.Peel <GitTree>(), Is.EqualTo(commit.Tree)); // Compares members Assert.That(commit.Tree.Peel <GitObject>(), Is.Null); GitTagArgs ta = new GitTagArgs(); ta.Signature.When = ct; ta.Signature.Name = "Me"; ta.Signature.EmailAddress = "[email protected]"; ta.LogMessage = "Some message"; ga.Author.TimeOffsetInMinutes = 120; Assert.That(commit.Tag("MyTag", ta, out id)); Assert.That(id, Is.EqualTo(new GitId("db31f8333fc64d7e7921ea91f6e007b755dcfcbb"))); GitTag tag; Assert.That(repo1.Lookup(id, out tag)); Assert.That(tag, Is.Not.Null); Assert.That(tag.Name, Is.EqualTo("MyTag")); Assert.That(tag.LogMessage, Is.EqualTo("Some message\n")); Assert.That(tag.Tagger.Name, Is.EqualTo("Me")); Assert.That(tag.Target.Id, Is.EqualTo(commit.Id)); Assert.That(tag.Peel <GitTree>(), Is.EqualTo(commit.Peel <GitTree>())); repo1.CheckOut(commit.Tree); //Console.WriteLine("1:"); //foreach (GitTreeEntry e in commit.Tree) //{ // Console.WriteLine(string.Format("{0}: {1} ({2})", e.Name, e.Kind, e.Children.Count)); //} //Console.WriteLine("2:"); //foreach (GitTreeEntry e in commit.Ancestor.Tree) //{ // Console.WriteLine(string.Format("{0}: {1} ({2})", e.Name, e.Kind, e.Children.Count)); //} //Console.WriteLine("3:"); //foreach (GitTreeEntry e in commit.Ancestor.Ancestor.Tree) //{ // Console.WriteLine(string.Format("{0}: {1} ({2})", e.Name, e.Kind, e.Children.Count)); //} //Console.WriteLine("-"); } }
public void TreeReplacements() { using (GitClient client = new GitClient()) { string dir = GitTools.GetTruePath(GetTempPath(), true); client.Init(dir); GitStatusArgs sa = new GitStatusArgs(); sa.GenerateVersionedDirs = true; sa.IncludeUnmodified = true; sa.IncludeIgnored = true; // Directories with 0 files are ignored sa.IncludeUnversioned = true; BuildGreek(dir); foreach (string[] k in GreekTree()) { string p = Path.Combine(dir, k[0]); if (File.Exists(p)) client.Stage(p); } client.Commit(dir); Directory.Delete(Path.Combine(dir, "A"), true); File.WriteAllText(Path.Combine(dir, "A"), "'A' file"); File.Delete(Path.Combine(dir, "mu")); Directory.CreateDirectory(Path.Combine(dir, "mu")); File.WriteAllText(Path.Combine(dir, "mu/AAAA"), "AAAA file"); List<string> paths = new List<string>(); int n = 0; foreach (string[] s in GreekTree()) paths.Add(GitTools.GetNormalizedFullPath(Path.Combine(dir, s[0]))); paths.Add(dir); paths.Add(Path.Combine(dir, "mu")); paths.Add(Path.Combine(dir, "mu\\AAAA")); /* Empty dirs are not versioned, so not reported deleted */ paths.Remove(Path.Combine(dir, "A\\C")); paths.Remove(Path.Combine(dir, "A\\B\\F")); List<string> paths2 = new List<string>(paths); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); Assert.IsFalse(e.IndexModified); Assert.IsFalse(e.WorkingDirectoryModified); n++; }); Assert.AreEqual(21, n); Assert.AreEqual(0, paths.Count); client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { switch (e.WorkingDirectoryStatus) { case GitStatus.New: case GitStatus.Deleted: case GitStatus.TypeChanged: client.Stage(e.FullPath); break; default: if (e.WorkingDirectoryModified) goto case GitStatus.New; break; } }); paths = new List<string>(paths2); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); Assert.IsFalse(e.IndexModified); Assert.IsFalse(e.WorkingDirectoryModified); n++; }); Assert.AreEqual(21, n); Assert.AreEqual(0, paths.Count); client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { switch (e.IndexStatus) { case GitStatus.New: case GitStatus.Deleted: case GitStatus.TypeChanged: client.Unstage(e.FullPath); break; } }); } }
public void FullStatus() { using(GitClient client = new GitClient()) { string dir = GitTools.GetTruePath(GetTempPath(), true); client.Init(dir); GitStatusArgs sa = new GitStatusArgs(); sa.GenerateVersionedDirs = true; sa.IncludeUnmodified = true; sa.IncludeIgnored = true; // Directories with 0 files are ignored BuildGreek(dir); { List<string> paths = new List<string>(); int n = 0; foreach (string[] s in GreekTree()) paths.Add(GitTools.GetNormalizedFullPath(Path.Combine(dir, s[0]))); paths.Add(dir); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); if (e.NodeKind == GitNodeKind.File) { Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid index status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.New, e.WorkingDirectoryStatus, "Invalid working status on {0}", e.RelativePath); Assert.IsFalse(e.Ignored); } else if (e.FullPath == dir) { Assert.AreEqual(GitStatus.None, e.WorkingDirectoryStatus); Assert.IsFalse(e.Ignored); } else if (Path.GetFileName(e.FullPath) == "F" || Path.GetFileName(e.FullPath) == "C") { // Empty directory Assert.AreEqual(GitStatus.Normal, e.WorkingDirectoryStatus, "Invalid status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid status on {0}", e.RelativePath); Assert.IsTrue(e.Ignored); } else { Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.None, e.WorkingDirectoryStatus, "Invalid status on {0}", e.RelativePath); Assert.IsFalse(e.Ignored); } n++; }); Assert.AreEqual(21, n); Assert.AreEqual(0, paths.Count); } foreach (string[] k in GreekTree()) { string p = Path.Combine(dir, k[0]); if (File.Exists(p)) client.Stage(p); } string A_dir = Path.Combine(dir, "A\\B"); { int n = 0; client.Status(A_dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(e.FullPath.StartsWith(A_dir + "\\") || e.FullPath == A_dir); n++; }); Assert.AreEqual(6, n); } { List<string> paths = new List<string>(); int n = 0; foreach (string[] s in GreekTree()) paths.Add(GitTools.GetNormalizedFullPath(Path.Combine(dir, s[0]))); paths.Add(dir); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(Path.IsPathRooted(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); if (e.NodeKind == GitNodeKind.File) { Assert.AreEqual(GitStatus.New, e.IndexStatus, "Invalid index status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.Normal, e.WorkingDirectoryStatus, "Invalid working status on {0}", e.RelativePath); Assert.IsFalse(e.Ignored); } else if (e.FullPath == dir) { Assert.AreEqual(GitStatus.None, e.WorkingDirectoryStatus); Assert.IsFalse(e.Ignored); } else if (Path.GetFileName(e.FullPath) == "F" || Path.GetFileName(e.FullPath) == "C") { // Empty directory Assert.AreEqual(GitStatus.Normal, e.WorkingDirectoryStatus, "Invalid status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid status on {0}", e.RelativePath); Assert.IsTrue(e.Ignored); } else { Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.None, e.WorkingDirectoryStatus, "Invalid status on {0}", e.RelativePath); Assert.IsFalse(e.Ignored); } n++; }); Assert.AreEqual(21, n); Assert.AreEqual(0, paths.Count); } client.Commit(dir); { List<string> paths = new List<string>(); int n = 0; foreach (string[] s in GreekTree()) paths.Add(GitTools.GetNormalizedFullPath(Path.Combine(dir, s[0]))); paths.Add(dir); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); Assert.AreEqual(e.NodeKind, File.Exists(e.FullPath) ? GitNodeKind.File : GitNodeKind.Directory); Assert.IsFalse(e.IndexModified); Assert.IsFalse(e.WorkingDirectoryModified); n++; }); Assert.AreEqual(21, n); Assert.AreEqual(0, paths.Count); } } }
public async void CreateBranch() { var client = new GitClient(TeamProjectName, CollectionUri, AccessToken); await client.CreateBranch("refs/heads/test/123", "heads/develop", Guid.Parse("6e3239e6-e054-464a-81f5-6e95d72ba79a")); }
public ProgressWorkerArgs(IVisualGitServiceProvider context, GitClient client, ISynchronizeInvoke sync) { if (context == null) throw new ArgumentNullException("context"); _context = context; _client = client; _sync = sync; }
public BumpVSMRoslynActionProvider(GitClient client) { Controller = new BumpVSMRoslynController(client); }
public ReviewPullRequestActionProvider(GitClient client, CancellationToken token) : this(client, token, Enumerable.Empty <string> ()) { }
public GitClientTests() { this.credentials = new VssBasicCredential(string.Empty, TestAccountConstants.SecretToken); this.gitClient = new GitClient(new Uri(TestAccountConstants.AccountUri), this.credentials); }
public void ClonePublic() { string repos = GetTempPath(); using (GitClient git = new GitClient()) { GitCloneArgs ca = new GitCloneArgs(); ca.Synchronous = true; git.Clone(new Uri("https://github.com/libgit2/TestGitRepository.git"), repos, ca); List <string> found = new List <string>(); GitStatusArgs sa = new GitStatusArgs(); sa.IncludeUnmodified = true; sa.UseGlobPath = true; git.Status(repos, sa, delegate(object sender, GitStatusEventArgs e) { found.Add(e.RelativePath); }); Assert.That(found.Count, Is.EqualTo(8)); Assert.That(found, Is.All.Not.Null); Assert.That(found, Is.Unique); found.Clear(); git.Status(repos + "/a/*", sa, delegate(object sender, GitStatusEventArgs e) { found.Add(e.RelativePath); }); Assert.That(found.Count, Is.EqualTo(3)); Assert.That(found, Is.All.Not.Null); Assert.That(found, Is.Unique); GitFetchArgs fa = new GitFetchArgs(); fa.All = true; git.Fetch(repos, fa); using (GitRepository repo = new GitRepository(repos)) { Assert.That(repo.HeadBranch, Is.Not.Null); Assert.That(repo.HeadBranch.Name, Is.EqualTo("refs/heads/master")); Assert.That(repo.HeadBranch.UpstreamReference, Is.Not.Null); Assert.That(repo.HeadBranch.UpstreamReference.Name, Is.EqualTo("refs/remotes/origin/master")); Assert.That(repo.HeadBranch.IsHead, "Head knows that it is head"); //Assert.That(repo.HeadBranch.TrackedBranch, Is.Null); Assert.That(repo.HeadBranch.Name, Is.EqualTo("refs/heads/master")); Assert.That(repo.HeadBranch.IsRemote, Is.False, "Local branch"); Assert.That(repo.HeadBranch.RemoteName, Is.EqualTo("origin")); foreach (GitBranch b in repo.Branches.Remote) { Assert.That(b.IsRemote, "Remote branch"); Assert.That(b.IsLocal, Is.False, "Not local"); Assert.That(b.Name, Is.SubPathOf("refs/remotes/origin/")); Assert.That(b.IsHead, Is.False); Assert.That(b.UpstreamReference, Is.Null); Assert.That(b.LocalUpstreamName, Is.Null); Assert.That(b.RemoteName, Is.EqualTo("origin")); } foreach (GitBranch b in repo.Branches.Local) { Assert.That(b.IsLocal, "Local branch"); Assert.That(b.IsRemote, Is.False, "Not remote"); Assert.That(b.Name, Is.SubPathOf("refs/").Or.EqualTo("master")); Assert.That(b.IsHead, Is.EqualTo(b.ShortName == "master")); Assert.That(b.RemoteName, Is.EqualTo("origin")); if (!b.IsHead) { Assert.That(b.LocalUpstreamName, Is.Not.Null); GitBranch tracked = b.TrackedBranch; Assert.That(tracked, Is.Not.Null, "Have tracked"); Assert.That(b.RemoteName, Is.Not.Null); } } foreach (GitRemote r in repo.Remotes) { Assert.That(r.Name, Is.Not.Null); Assert.That(r.TagSynchronize, Is.EqualTo(GitTagSynchronize.Auto)); //Assert.That(r.Save(new GitFetchArgs())); foreach (GitRefSpec rs in r.FetchRefSpecs) { } foreach (GitRefSpec rs in r.PushRefSpecs) { } } } git.Pull(repos); // libgit2's local push code only supports bare repositories at // this time, so we use a few more clones to test the real push string cloneDir = GetTempPath(); GitCloneArgs cca = new GitCloneArgs(); cca.InitArgs.CreateBareRepository = true; git.Clone(repos, cloneDir, cca); string clone2Dir = GetTempPath(); git.Clone(cloneDir, clone2Dir); GitPushArgs pa = new GitPushArgs(); pa.Mode = GitPushMode.All; git.Push(clone2Dir, pa); } }
public void UseGitClient() { GitCommitArgs ga = new GitCommitArgs(); ga.Author.Name = "Tester"; ga.Author.EmailAddress = "*****@*****.**"; ga.Signature.Name = "Other"; ga.Signature.EmailAddress = "*****@*****.**"; // Use stable time and offset to always produce the same hash DateTime ct = new DateTime(2002, 01, 01, 0, 0, 0, DateTimeKind.Utc); ga.Author.When = ct; ga.Author.TimeOffsetInMinutes = 120; ga.Signature.When = ct; ga.Signature.TimeOffsetInMinutes = 120; string repoDir = GetTempPath(); string repo2Dir = GetTempPath(); GitId firstResult; GitId lastCommit; using (GitRepository repo = GitRepository.Create(repoDir)) using (GitClient git = new GitClient()) { string ignoreFile = Path.Combine(repoDir, ".gitignore"); string file = Path.Combine(repoDir, "newfile"); string subDir = Path.Combine(repoDir, "dir"); string fileInSubDir = Path.Combine(subDir, "file2"); string file3 = Path.Combine(repoDir, "other"); string file4 = Path.Combine(repoDir, "q.ignore"); File.WriteAllText(file, "Some body"); Directory.CreateDirectory(subDir); File.WriteAllText(fileInSubDir, "Some other body"); File.WriteAllText(file3, "file3"); File.WriteAllText(ignoreFile, "*.ignore\n"); File.WriteAllText(file4, "file4"); git.Add(ignoreFile); git.Add(file); git.Commit(repoDir, ga, out firstResult); git.Add(fileInSubDir); int ticked = 0; File.AppendAllText(file, "\nExtra Line"); GitStatusArgs gsa = new GitStatusArgs(); gsa.IncludeIgnored = true; gsa.IncludeUnmodified = true; Assert.That(git.Status(repoDir, gsa, delegate(object sender, GitStatusEventArgs e) { switch (e.RelativePath) { case "newfile": //Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.Added)); Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.Normal), "newfile index normal"); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Normal), "newfile wc modified"); Assert.That(e.WorkingDirectoryModified); Assert.That(e.Ignored, Is.False); break; case "dir/file2": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.New), "file2 index added"); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Normal), "file2 wc normal"); Assert.That(e.Ignored, Is.False); break; case "other": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.None)); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.New)); Assert.That(e.Ignored, Is.False); break; case ".gitignore": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.Normal)); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Normal)); Assert.That(e.Ignored, Is.False); break; case "q.ignore": // TODO: Make this ignored Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.None)); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Normal)); Assert.That(e.Ignored, Is.True); break; default: Assert.Fail("Invalid node found: {0}", e.RelativePath); break; } Assert.That(e.FullPath, Is.EqualTo(Path.GetFullPath(Path.Combine(repoDir, e.RelativePath)))); ticked++; }), Is.True); Assert.That(ticked, Is.EqualTo(5), "Ticked"); ga.LogMessage = "Intermediate"; git.Commit(repoDir, ga); Assert.That(git.Delete(fileInSubDir)); Assert.That(git.Add(file)); GitId commit; ga.LogMessage = "A log message to remember"; // The passed path is currently just used to find the local repository lastCommit = new GitId("996cf198b49ed6fce3bcba232e2d88eb473560f9"); Assert.That(git.Commit(repoDir, ga, out commit)); Assert.That(commit, Is.EqualTo(lastCommit)); File.Move(file, file + ".a"); ticked = 0; gsa.IncludeIgnored = false; gsa.IncludeUnversioned = true; gsa.IncludeUnmodified = false; Assert.That(git.Status(repoDir, gsa, delegate(object sender, GitStatusEventArgs e) { switch (e.RelativePath) { /*case "dir": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.Normal), "dir index normal"); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.New), "dir wc normal"); break;*/ case "newfile": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.None), "newfile index normal"); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Deleted), "newfile wc deleted"); break; case "newfile.a": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.None), "newfile.a index normal"); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.New), "newfile.a wc new"); break; case "other": Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.None), "other index normal"); Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.New), "other wc normal"); break; default: Assert.Fail("Invalid node found: {0}", e.RelativePath); break; } Assert.That(e.FullPath, Is.EqualTo(Path.GetFullPath(Path.Combine(repoDir, e.RelativePath)))); ticked++; }), Is.True); Assert.That(ticked, Is.EqualTo(3)); GitCloneArgs gc = new GitCloneArgs(); gc.Synchronous = true; git.Clone(repoDir, repo2Dir, gc); GitCommit theCommit; Assert.That(repo.Lookup(commit, out theCommit)); Assert.That(repo.Branches.Create(theCommit, "vNext")); Assert.That(repo.Branches, Is.Not.Empty); } using (GitRepository repo1 = new GitRepository(repoDir)) using (GitRepository repo2 = new GitRepository(repo2Dir)) { GitReference head = repo1.HeadReference; Assert.That(head, Is.Not.Null, "Has head"); Assert.That(head.Name, Is.EqualTo("refs/heads/master")); //Assert.That(repo2.Head, Is.Not.Null); GitId headId; Assert.That(repo1.ResolveReference(repo1.HeadReference, out headId)); Assert.That(headId, Is.EqualTo(lastCommit)); GitCommit commit; Assert.That(repo1.Lookup(headId, out commit)); Assert.That(commit, Is.Not.Null, "Have a commit"); Assert.That(commit.Id, Is.EqualTo(lastCommit)); Assert.That(commit.Ancestors, Is.Not.Empty); Assert.That(commit.Ancestor, Is.Not.Null); Assert.That(commit.Ancestor.Ancestor, Is.Not.Null); Assert.That(commit.Ancestor.Ancestor.Ancestor, Is.Null); Assert.That(commit.Ancestor.Ancestor.Id, Is.EqualTo(firstResult)); Assert.That(commit.Author, Is.Not.Null); Assert.That(commit.Author.Name, Is.EqualTo("Tester")); Assert.That(commit.Author.EmailAddress, Is.EqualTo("*****@*****.**")); Assert.That(commit.Committer, Is.Not.Null); Assert.That(commit.Committer.Name, Is.EqualTo("Other")); Assert.That(commit.Committer.EmailAddress, Is.EqualTo("*****@*****.**")); Assert.That(commit.Committer.TimeOffsetInMinutes, Is.EqualTo(120), "Time offset"); // CEST dependent Assert.That(commit.Committer.When, Is.EqualTo(ct), "Exact time"); Assert.That(commit.LogMessage, Is.EqualTo("A log message to remember\n")); Assert.That(commit.Parents, Is.Not.Empty); Assert.That(commit.ParentIds, Is.Not.Empty); Assert.That(commit.Tree, Is.Not.Empty); Assert.That(commit.Tree.Count, Is.EqualTo(2)); Assert.That(commit.Ancestor.Tree.Count, Is.EqualTo(3)); Assert.That(commit.Ancestor.Ancestor.Tree.Count, Is.EqualTo(2)); Assert.That(commit.Tree.Id, Is.Not.EqualTo(commit.Ancestor.Tree.Id)); GitId id; Assert.That(repo1.LookupViaPrefix(commit.Id.ToString(), out id)); Assert.That(id, Is.EqualTo(commit.Id)); Assert.That(repo1.LookupViaPrefix(commit.Id.ToString().Substring(0, 10), out id)); Assert.That(id, Is.EqualTo(commit.Id)); Assert.That(commit.Peel<GitObject>().Id, Is.EqualTo(commit.Tree.Id)); Assert.That(commit.Peel<GitTree>(), Is.EqualTo(commit.Tree)); // Compares members Assert.That(commit.Tree.Peel<GitObject>(), Is.Null); GitTagArgs ta = new GitTagArgs(); ta.Signature.When = ct; ta.Signature.Name = "Me"; ta.Signature.EmailAddress = "[email protected]"; ta.LogMessage = "Some message"; ga.Author.TimeOffsetInMinutes = 120; Assert.That(commit.Tag("MyTag", ta, out id)); Assert.That(id, Is.EqualTo(new GitId("db31f8333fc64d7e7921ea91f6e007b755dcfcbb"))); GitTag tag; Assert.That(repo1.Lookup(id, out tag)); Assert.That(tag, Is.Not.Null); Assert.That(tag.Name, Is.EqualTo("MyTag")); Assert.That(tag.LogMessage, Is.EqualTo("Some message\n")); Assert.That(tag.Tagger.Name, Is.EqualTo("Me")); Assert.That(tag.Target.Id, Is.EqualTo(commit.Id)); Assert.That(tag.Peel<GitTree>(), Is.EqualTo(commit.Peel<GitTree>())); repo1.CheckOut(commit.Tree); //Console.WriteLine("1:"); //foreach (GitTreeEntry e in commit.Tree) //{ // Console.WriteLine(string.Format("{0}: {1} ({2})", e.Name, e.Kind, e.Children.Count)); //} //Console.WriteLine("2:"); //foreach (GitTreeEntry e in commit.Ancestor.Tree) //{ // Console.WriteLine(string.Format("{0}: {1} ({2})", e.Name, e.Kind, e.Children.Count)); //} //Console.WriteLine("3:"); //foreach (GitTreeEntry e in commit.Ancestor.Ancestor.Tree) //{ // Console.WriteLine(string.Format("{0}: {1} ({2})", e.Name, e.Kind, e.Children.Count)); //} //Console.WriteLine("-"); } }
public void PushChanges() { string master = GetTempPath(); using (GitClient git = new GitClient()) { GitInitArgs ia = new GitInitArgs(); ia.CreateBareRepository = true; ia.Description = "Harry & Sally root"; git.Init(master, ia); } Uri masterUri = new Uri(master); string harry = GetTempPath(); string sally = GetTempPath(); using (GitClient git = new GitClient()) // Harry { git.Clone(masterUri, harry); using (GitRepository harryRepo = new GitRepository(harry)) { harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Harry"); harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**"); } string src = Path.Combine(harry, "src"); Directory.CreateDirectory(src); string index = Path.Combine(src, "index.txt"); File.WriteAllText(index, "This is index.txt\n"); string appCode = Path.Combine(harry, "app.c"); File.WriteAllText(appCode, @" #include <stdio.h> int main(int argc, const char **argv) { printf(""hello world\n""); return 0; } "); git.Add(index); git.Add(appCode); GitId result; GitCommitArgs cma = new GitCommitArgs(); cma.Signature.When = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); cma.Author.When = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); git.Commit(harry, cma, out result); using (GitRepository harryRepo = new GitRepository(harry)) { GitCommit commit; Assert.That(harryRepo.Lookup(result, out commit)); Assert.That(commit.Author.Name, Is.EqualTo("Harry")); } } using (GitClient git = new GitClient()) // Sally { git.Clone(masterUri, sally); using (GitRepository sallyRepo = new GitRepository(sally)) { sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Sally"); sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**"); } string src = Path.Combine(sally, "src"); string index = Path.Combine(src, "index.txt"); Assert.That(File.Exists(index), Is.False); } using (GitClient git = new GitClient()) // Harry { GitPushArgs pa = new GitPushArgs(); pa.Mode = GitPushMode.All; git.Push(harry, pa); } using (GitClient git = new GitClient()) // Sally { GitPullArgs pa = new GitPullArgs(); pa.FetchArgs.All = true; git.Pull(sally, pa); string src = Path.Combine(sally, "src"); string index = Path.Combine(src, "index.txt"); Assert.That(File.Exists(index), Is.True); string appCode = Path.Combine(sally, "app.c"); File.WriteAllText(appCode, @" #include <stdio.h> int main(int argc, const char **argv) { int i; if (argc != 1) { fprintf(stderr, ""Usage %s <int>\n"", argv[0]); return 1; } for (i = 0; i < atoi(argv[1]); i++ printf(""hello world %d\n"", i); return 0; } "); git.Add(appCode); GitId result; GitCommitArgs cma = new GitCommitArgs(); cma.Signature.When = new DateTime(2000, 1, 2, 0, 0, 0, DateTimeKind.Utc); cma.Author.When = new DateTime(2000, 1, 2, 0, 0, 0, DateTimeKind.Utc); git.Commit(sally, cma, out result); GitPushArgs ph = new GitPushArgs(); ph.Mode = GitPushMode.All; git.Push(sally, ph); } using (GitClient git = new GitClient()) // Harry { string appCode = Path.Combine(harry, "app.c"); File.WriteAllText(appCode, @" #include <stdio.h> int main(int argc, const char **argv) { if (argc > 0 && strcmp(argv[1], ""-V"") { printf(""%s version 1.0 (c) QQn\n""); return 0; } printf(""hello world\n""); return 0; } "); git.Add(appCode); GitId result; GitCommitArgs cma = new GitCommitArgs(); cma.Signature.When = new DateTime(2000, 1, 3, 0, 0, 0, DateTimeKind.Utc); cma.Author.When = new DateTime(2000, 1, 3, 0, 0, 0, DateTimeKind.Utc); git.Commit(harry, cma, out result); // Local commit will succeed GitPushArgs ph = new GitPushArgs(); ph.Mode = GitPushMode.All; try { git.Push(harry, ph); // But push fails, as it conflicts Assert.Fail("Should have failed"); // ### } catch (GitException ge) { Assert.That(ge.Message, Contains.Substring(/*C*/ "annot push")); } GitPullArgs pa = new GitPullArgs(); pa.FetchArgs.All = true; git.Pull(harry, pa); bool gotConflict = false; git.Status(harry, delegate(object sender, GitStatusEventArgs e) { switch (e.RelativePath) { case "app.c": gotConflict = true; Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Normal)); Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.Normal)); Assert.That(e.Conflicted, Is.True, "Conflicted"); break; default: Assert.Fail("Unexpected path: {0}", e.RelativePath); break; } }); Assert.That(gotConflict, "Found conflict status"); try { git.Push(harry, ph); // But push fails, as it conflicts Assert.Fail("Should still fail"); } catch (GitException ge) { Assert.That(ge.Message, Contains.Substring(/*C*/ "annot push")); } GitResetArgs ra = new GitResetArgs(); ra.Mode = GitResetMode.Hard; git.Reset(harry, ra); } }
public async Task ShouldDetectBranchCreate() { Logger.Trace("Starting ShouldDetectBranchCreate"); try { Initialize(TestRepoMasterCleanSynchronized, initializeRepository: false); using (var repositoryWatcher = CreateRepositoryWatcher(TestRepoMasterCleanSynchronized)) { var watcherAutoResetEvent = new RepositoryWatcherAutoResetEvent(); var repositoryWatcherListener = Substitute.For <IRepositoryWatcherListener>(); repositoryWatcherListener.AttachListener(repositoryWatcher, watcherAutoResetEvent); repositoryWatcher.Initialize(); repositoryWatcher.Start(); repositoryWatcher.Stop(); try { Logger.Trace("Issuing Command"); await GitClient.CreateBranch("feature/document2", "feature/document").StartAsAsync(); await TaskManager.Wait(); Logger.Trace("Continue test"); repositoryWatcher.Start(); watcherAutoResetEvent.LocalBranchesChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.Reset(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().ConfigChanged(); repositoryWatcherListener.DidNotReceive().RepositoryCommitted(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.Received(1).LocalBranchesChanged(); repositoryWatcherListener.DidNotReceive().RemoteBranchesChanged(); repositoryWatcherListener.ClearReceivedCalls(); repositoryWatcher.Stop(); Logger.Trace("Issuing Command"); await GitClient.CreateBranch("feature2/document2", "feature/document").StartAsAsync(); await TaskManager.Wait(); Logger.Trace("Continue test"); repositoryWatcher.Start(); watcherAutoResetEvent.LocalBranchesChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().ConfigChanged(); repositoryWatcherListener.DidNotReceive().RepositoryCommitted(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.Received(1).LocalBranchesChanged(); repositoryWatcherListener.DidNotReceive().RemoteBranchesChanged(); } finally { repositoryWatcher.Stop(); } } } finally { Logger.Trace("Ending ShouldDetectBranchCreate"); } }
public void DualStart() { string master = GetTempPath(); using (GitClient git = new GitClient()) { GitInitArgs ia = new GitInitArgs(); ia.CreateBareRepository = true; ia.Description = "Harry & Sally root"; git.Init(master, ia); } Uri masterUri = new Uri(master); string harry = GetTempPath(); string sally = GetTempPath(); using (GitClient git = new GitClient()) // Harry { git.Clone(masterUri, harry); using (GitRepository harryRepo = new GitRepository(harry)) { harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Harry"); harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**"); } string src = Path.Combine(harry, "src"); Directory.CreateDirectory(src); string index = Path.Combine(src, "index.txt"); File.WriteAllText(index, "This is index.txt\n"); git.Add(index); GitId result; GitCommitArgs cma = new GitCommitArgs(); cma.Signature.When = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); cma.Author.When = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); git.Commit(harry, cma, out result); using (GitRepository harryRepo = new GitRepository(harry)) { GitCommit commit; Assert.That(harryRepo.Lookup(result, out commit)); Assert.That(commit.Author.Name, Is.EqualTo("Harry")); } } using (GitClient git = new GitClient()) // Sally { git.Clone(masterUri, sally); using (GitRepository sallyRepo = new GitRepository(sally)) { sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Sally"); sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**"); } string iota = Path.Combine(sally, "iota.txt"); File.WriteAllText(iota, "This is iota\n"); git.Stage(iota); GitCommitArgs cma = new GitCommitArgs(); cma.Signature.When = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc); cma.Author.When = new DateTime(2001, 1, 1, 0, 0, 0, DateTimeKind.Utc); git.Commit(sally, cma); string src = Path.Combine(sally, "src"); string index = Path.Combine(src, "index.txt"); Assert.That(File.Exists(index), Is.False); } using (GitClient git = new GitClient()) // Harry { GitPushArgs pa = new GitPushArgs(); pa.Mode = GitPushMode.All; git.Push(harry, pa); } using (GitClient git = new GitClient()) // Sally { GitPullArgs pa = new GitPullArgs(); pa.FetchArgs.All = true; git.Pull(sally, pa); string src = Path.Combine(sally, "src"); string index = Path.Combine(src, "index.txt"); Assert.That(File.Exists(index), Is.True); } }
public void LoadFromClient(GitClient client) { localBox.BeginUpdate(); remoteBox.BeginUpdate(); localBox.Items.Clear(); remoteBox.Items.Clear(); var currentBranch = client.GetCurrentBranch(RepositoryPath); foreach (var @ref in client.GetRefs(RepositoryPath)) { if (@ref.Type == GitRefType.Branch) { remoteBox.Items.Add(@ref.ShortName); localBox.Items.Add(@ref.ShortName); if (@ref == currentBranch) { remoteBox.SelectedIndex = remoteBox.Items.Count - 1; localBox.SelectedIndex = remoteBox.Items.Count - 1; } } } localBox.EndUpdate(); remoteBox.EndUpdate(); }
public BumpProvisionatorDependenciesActionProvider(GitClient client, bool allowExternalActions = true) { Client = client; this.allowExternalActions = allowExternalActions; }
public override void ExecuteCmdlet() { WebsitesClient = WebsitesClient ?? new WebsitesClient(CurrentSubscription, WriteDebug); string suffix = WebsitesClient.GetWebsiteDnsSuffix(); if (Git && GitHub) { throw new Exception("Please run the command with either -Git or -GitHub options. Not both."); } if (Git) { PublishingUsername = GetPublishingUser(); } WebSpaces webspaceList = null; InvokeInOperationContext(() => { webspaceList = RetryCall(s => Channel.GetWebSpacesWithCache(s)); }); if (Git && webspaceList.Count == 0) { // If location is still empty or null, give portal instructions. string error = string.Format(Resources.PortalInstructions, Name); throw new Exception(!Git ? error : string.Format("{0}\n{1}", error, Resources.PortalInstructionsGit)); } WebSpace webspace = null; if (string.IsNullOrEmpty(Location)) { // If no location was provided as a parameter, try to default it webspace = webspaceList.FirstOrDefault(); if (webspace == null) { webspace = new WebSpace { GeoRegion = WebsitesClient.GetDefaultLocation(), Subscription = CurrentSubscription.SubscriptionId, Plan = "VirtualDedicatedPlan" }; } } else { // Find the webspace that corresponds to the georegion webspace = webspaceList.FirstOrDefault(w => w.GeoRegion.Equals(Location, StringComparison.OrdinalIgnoreCase)); if (webspace == null) { // If no webspace corresponding to the georegion was found, attempt to create it webspace = new WebSpace { Name = Regex.Replace(Location.ToLower(), " ", "") + "webspace", GeoRegion = Location, Subscription = CurrentSubscription.SubscriptionId, Plan = "VirtualDedicatedPlan" }; } } SiteWithWebSpace website = new SiteWithWebSpace { Name = Name, HostNames = new[] { string.Format("{0}.{1}", Name, suffix) }, WebSpace = webspace.Name, WebSpaceToCreate = webspace }; if (!string.IsNullOrEmpty(Hostname)) { List <string> newHostNames = new List <string>(website.HostNames); newHostNames.Add(Hostname); website.HostNames = newHostNames.ToArray(); } try { InvokeInOperationContext(() => RetryCall(s => Channel.CreateSite(s, webspace.Name, website))); // If operation succeeded try to update cache with new webspace if that's the case if (webspaceList.FirstOrDefault(ws => ws.Name.Equals(webspace.Name)) == null) { Cache.AddWebSpace(CurrentSubscription.SubscriptionId, webspace); } Cache.AddSite(CurrentSubscription.SubscriptionId, website); SiteConfig websiteConfiguration = null; InvokeInOperationContext(() => { websiteConfiguration = RetryCall(s => Channel.GetSiteConfig(s, website.WebSpace, website.Name)); WaitForOperation(CommandRuntime.ToString()); }); WriteObject(new SiteWithConfig(website, websiteConfiguration)); } catch (ProtocolException ex) { // Handle site creating indepently so that cmdlet is idempotent. string message = ProcessException(ex, false); if (message.Equals(string.Format(Resources.WebsiteAlreadyExistsReplacement, Name)) && (Git || GitHub)) { WriteWarning(message); } else if (message.Equals(Resources.DefaultHostnamesValidation)) { WriteExceptionError(new Exception(Resources.InvalidHostnameValidation)); } else { WriteExceptionError(new Exception(message)); } } if (Git || GitHub) { try { Directory.SetCurrentDirectory(SessionState.Path.CurrentFileSystemLocation.Path); } catch (Exception) { // Do nothing if session state is not present } LinkedRevisionControl linkedRevisionControl = null; if (Git) { linkedRevisionControl = new GitClient(this); } else if (GitHub) { linkedRevisionControl = new GithubClient(this, GithubCredentials, GithubRepository); } linkedRevisionControl.Init(); CopyIisNodeWhenServerJsPresent(); UpdateLocalConfigWithSiteName(Name, webspace.Name); InitializeRemoteRepo(webspace.Name, Name); Site updatedWebsite = RetryCall(s => Channel.GetSite(s, webspace.Name, Name, "repositoryuri,publishingpassword,publishingusername")); if (Git) { AddRemoteToLocalGitRepo(updatedWebsite); } linkedRevisionControl.Deploy(updatedWebsite); linkedRevisionControl.Dispose(); } }
internal override void ExecuteCommand() { if (Git && GitHub) { throw new Exception("Please run the command with either -Git or -GitHub options. Not both."); } if (Git) { PublishingUsername = GetPublishingUser(); } WebSpaces webspaceList = null; InvokeInOperationContext(() => { webspaceList = RetryCall(s => Channel.GetWebSpacesWithCache(s)); }); if (webspaceList.Count == 0) { // If location is still empty or null, give portal instructions. string error = string.Format(Resources.PortalInstructions, Name); throw new Exception(!Git ? error : string.Format("{0}\n{1}", error, Resources.PortalInstructionsGit)); } WebSpace webspace = null; if (string.IsNullOrEmpty(Location)) { // If no location was provided as a parameter, try to default it webspace = webspaceList.FirstOrDefault(); if (webspace == null) { // Use east us webspace = new WebSpace { Name = "eastuswebspace", GeoRegion = "East US", Subscription = CurrentSubscription.SubscriptionId, Plan = "VirtualDedicatedPlan" }; } } else { // Find the webspace that corresponds to the georegion webspace = webspaceList.FirstOrDefault(w => w.GeoRegion.Equals(Location, StringComparison.OrdinalIgnoreCase)); if (webspace == null) { // If no webspace corresponding to the georegion was found, attempt to create it webspace = new WebSpace { Name = Regex.Replace(Location.ToLower(), " ", "") + "webspace", GeoRegion = Location, Subscription = CurrentSubscription.SubscriptionId, Plan = "VirtualDedicatedPlan" }; } } SiteWithWebSpace website = new SiteWithWebSpace { Name = Name, HostNames = new[] { Name + General.AzureWebsiteHostNameSuffix }, WebSpace = webspace.Name, WebSpaceToCreate = webspace }; if (!string.IsNullOrEmpty(Hostname)) { List<string> newHostNames = new List<string>(website.HostNames); newHostNames.Add(Hostname); website.HostNames = newHostNames.ToArray(); } try { InvokeInOperationContext(() => RetryCall(s => Channel.CreateSite(s, webspace.Name, website))); // If operation succeeded try to update cache with new webspace if that's the case if (webspaceList.FirstOrDefault(ws => ws.Name.Equals(webspace.Name)) == null) { Cache.AddWebSpace(CurrentSubscription.SubscriptionId, webspace); } Cache.AddSite(CurrentSubscription.SubscriptionId, website); } catch (ProtocolException ex) { // Handle site creating indepently so that cmdlet is idempotent. string message = ProcessException(ex, false); if (message.Equals(string.Format(Resources.WebsiteAlreadyExistsReplacement, Name)) && (Git || GitHub)) { WriteWarning(message); } else { SafeWriteError(new Exception(message)); } } if (Git || GitHub) { try { Directory.SetCurrentDirectory(SessionState.Path.CurrentFileSystemLocation.Path); } catch (Exception) { // Do nothing if session state is not present } LinkedRevisionControl linkedRevisionControl = null; if (Git) { linkedRevisionControl = new GitClient(this); } else if (GitHub) { linkedRevisionControl = new GithubClient(this, GithubCredentials, GithubRepository); } linkedRevisionControl.Init(); CopyIisNodeWhenServerJsPresent(); UpdateLocalConfigWithSiteName(Name, webspace.Name); InitializeRemoteRepo(webspace.Name, Name); Site updatedWebsite = RetryCall(s => Channel.GetSite(s, webspace.Name, Name, "repositoryuri,publishingpassword,publishingusername")); if (Git) { AddRemoteToLocalGitRepo(updatedWebsite); } linkedRevisionControl.Deploy(updatedWebsite); linkedRevisionControl.Dispose(); } }
private IDisposable BindOutputPane(GitClient client) { return new OutputPaneReporter(_context, client); }
public override IDisposable Bind(GitClient client) { if (client == null) throw new ArgumentNullException("client"); //client.Processing += new EventHandler<SvnProcessingEventArgs>(OnClientProcessing); client.Notify += new EventHandler<GitNotifyEventArgs>(OnClientNotify); //client.Progress += new EventHandler<SvnProgressEventArgs>(OnClientProgress); //client.Cancel += new EventHandler<SvnCancelEventArgs>(OnClientCancel); return new UnbindDisposer(client, this); }
public void TestInstantiate() { GitClient task = new GitClient(); task.WorkingDirectory = @"C:\Program Files\Git\bin\"; task.Execute(); }
public UnbindDisposer(GitClient client, ProgressDialog dlg) { if (client == null) throw new ArgumentNullException("client"); else if (dlg == null) throw new ArgumentNullException("dlg"); _client = client; _dlg = dlg; }
public void FullStatus() { using (GitClient client = new GitClient()) { string dir = GitTools.GetTruePath(GetTempPath(), true); client.Init(dir); GitStatusArgs sa = new GitStatusArgs(); sa.GenerateVersionedDirs = true; sa.IncludeUnmodified = true; sa.IncludeIgnored = true; // Directories with 0 files are ignored BuildGreek(dir); { List <string> paths = new List <string>(); int n = 0; foreach (string[] s in GreekTree()) { paths.Add(GitTools.GetNormalizedFullPath(Path.Combine(dir, s[0]))); } paths.Add(dir); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); if (e.NodeKind == GitNodeKind.File) { Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid index status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.New, e.WorkingDirectoryStatus, "Invalid working status on {0}", e.RelativePath); Assert.IsFalse(e.Ignored); } else if (e.FullPath == dir) { Assert.AreEqual(GitStatus.None, e.WorkingDirectoryStatus); Assert.IsFalse(e.Ignored); } else if (Path.GetFileName(e.FullPath) == "F" || Path.GetFileName(e.FullPath) == "C") { // Empty directory Assert.AreEqual(GitStatus.Normal, e.WorkingDirectoryStatus, "Invalid status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid status on {0}", e.RelativePath); Assert.IsTrue(e.Ignored); } else { Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.None, e.WorkingDirectoryStatus, "Invalid status on {0}", e.RelativePath); Assert.IsFalse(e.Ignored); } n++; }); Assert.AreEqual(21, n); Assert.AreEqual(0, paths.Count); } foreach (string[] k in GreekTree()) { string p = Path.Combine(dir, k[0]); if (File.Exists(p)) { client.Stage(p); } } string A_dir = Path.Combine(dir, "A\\B"); { int n = 0; client.Status(A_dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(e.FullPath.StartsWith(A_dir + "\\") || e.FullPath == A_dir); n++; }); Assert.AreEqual(6, n); } { List <string> paths = new List <string>(); int n = 0; foreach (string[] s in GreekTree()) { paths.Add(GitTools.GetNormalizedFullPath(Path.Combine(dir, s[0]))); } paths.Add(dir); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(Path.IsPathRooted(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); if (e.NodeKind == GitNodeKind.File) { Assert.AreEqual(GitStatus.New, e.IndexStatus, "Invalid index status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.Normal, e.WorkingDirectoryStatus, "Invalid working status on {0}", e.RelativePath); Assert.IsFalse(e.Ignored); } else if (e.FullPath == dir) { Assert.AreEqual(GitStatus.None, e.WorkingDirectoryStatus); Assert.IsFalse(e.Ignored); } else if (Path.GetFileName(e.FullPath) == "F" || Path.GetFileName(e.FullPath) == "C") { // Empty directory Assert.AreEqual(GitStatus.Normal, e.WorkingDirectoryStatus, "Invalid status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid status on {0}", e.RelativePath); Assert.IsTrue(e.Ignored); } else { Assert.AreEqual(GitStatus.None, e.IndexStatus, "Invalid status on {0}", e.RelativePath); Assert.AreEqual(GitStatus.None, e.WorkingDirectoryStatus, "Invalid status on {0}", e.RelativePath); Assert.IsFalse(e.Ignored); } n++; }); Assert.AreEqual(21, n); Assert.AreEqual(0, paths.Count); } client.Commit(dir); { List <string> paths = new List <string>(); int n = 0; foreach (string[] s in GreekTree()) { paths.Add(GitTools.GetNormalizedFullPath(Path.Combine(dir, s[0]))); } paths.Add(dir); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); Assert.AreEqual(e.NodeKind, File.Exists(e.FullPath) ? GitNodeKind.File : GitNodeKind.Directory); Assert.IsFalse(e.IndexModified); Assert.IsFalse(e.WorkingDirectoryModified); n++; }); Assert.AreEqual(21, n); Assert.AreEqual(0, paths.Count); } } }
public async Task ShouldDetectChangesToRemotes() { await Initialize(TestRepoMasterCleanSynchronized); using (var repositoryWatcher = CreateRepositoryWatcher(TestRepoMasterCleanSynchronized)) { var watcherAutoResetEvent = new RepositoryWatcherAutoResetEvent(); var repositoryWatcherListener = Substitute.For <IRepositoryWatcherListener>(); repositoryWatcherListener.AttachListener(repositoryWatcher, watcherAutoResetEvent); repositoryWatcher.Initialize(); repositoryWatcher.Start(); try { Logger.Trace("Issuing Command"); await GitClient.RemoteRemove("origin").StartAsAsync(); await TaskManager.Wait(); watcherAutoResetEvent.ConfigChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.RemoteBranchDeleted.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.RemoteBranchDeleted.WaitOne(TimeSpan.FromSeconds(2)); watcherAutoResetEvent.RemoteBranchDeleted.WaitOne(TimeSpan.FromSeconds(2)); Logger.Trace("Continue test"); repositoryWatcherListener.Received().ConfigChanged(); repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchChanged(Args.String); repositoryWatcherListener.Received(1).RemoteBranchDeleted("origin", "feature/document-2"); repositoryWatcherListener.Received(1).RemoteBranchDeleted("origin", "feature/other-feature"); repositoryWatcherListener.Received(1).RemoteBranchDeleted("origin", "master"); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.ClearReceivedCalls(); watcherAutoResetEvent.ConfigChanged.Reset(); Logger.Trace("Issuing 2nd Command"); await GitClient.RemoteAdd("origin", "https://github.com/EvilStanleyGoldman/IOTestsRepo.git").StartAsAsync(); // give the fs watcher a bit of time to catch up await TaskEx.Delay(500); await TaskManager.Wait(); watcherAutoResetEvent.ConfigChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); Logger.Trace("Continue 2nd test"); repositoryWatcherListener.Received().ConfigChanged(); repositoryWatcherListener.DidNotReceive().HeadChanged(Args.String); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchChanged(Args.String); repositoryWatcherListener.DidNotReceive().RemoteBranchChanged(Args.String, Args.String); repositoryWatcherListener.DidNotReceive().RemoteBranchCreated(Args.String, Args.String); repositoryWatcherListener.DidNotReceive().RemoteBranchDeleted(Args.String, Args.String); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); } finally { repositoryWatcher.Stop(); } } }
public GitSccContext(IVisualGitServiceProvider context) : base(context) { _client = context.GetService<IGitClientPool>().GetNoUIClient(); _statusCache = GetService<IFileStatusCache>(); }
public void TreeReplacements() { using (GitClient client = new GitClient()) { string dir = GitTools.GetTruePath(GetTempPath(), true); client.Init(dir); GitStatusArgs sa = new GitStatusArgs(); sa.GenerateVersionedDirs = true; sa.IncludeUnmodified = true; sa.IncludeIgnored = true; // Directories with 0 files are ignored sa.IncludeUnversioned = true; BuildGreek(dir); foreach (string[] k in GreekTree()) { string p = Path.Combine(dir, k[0]); if (File.Exists(p)) { client.Stage(p); } } client.Commit(dir); Directory.Delete(Path.Combine(dir, "A"), true); File.WriteAllText(Path.Combine(dir, "A"), "'A' file"); File.Delete(Path.Combine(dir, "mu")); Directory.CreateDirectory(Path.Combine(dir, "mu")); File.WriteAllText(Path.Combine(dir, "mu/AAAA"), "AAAA file"); List <string> paths = new List <string>(); int n = 0; foreach (string[] s in GreekTree()) { paths.Add(GitTools.GetNormalizedFullPath(Path.Combine(dir, s[0]))); } paths.Add(dir); paths.Add(Path.Combine(dir, "mu")); paths.Add(Path.Combine(dir, "mu\\AAAA")); /* Empty dirs are not versioned, so not reported deleted */ paths.Remove(Path.Combine(dir, "A\\C")); paths.Remove(Path.Combine(dir, "A\\B\\F")); List <string> paths2 = new List <string>(paths); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); Assert.IsFalse(e.IndexModified); Assert.IsFalse(e.WorkingDirectoryModified); n++; }); Assert.AreEqual(21, n); Assert.AreEqual(0, paths.Count); client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { switch (e.WorkingDirectoryStatus) { case GitStatus.New: case GitStatus.Deleted: case GitStatus.TypeChanged: client.Stage(e.FullPath); break; default: if (e.WorkingDirectoryModified) { goto case GitStatus.New; } break; } }); paths = new List <string>(paths2); n = 0; client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { Assert.IsTrue(GitTools.IsNormalizedFullPath(e.FullPath)); Assert.IsTrue(paths.Remove(e.FullPath), "Can remove {0}", e.FullPath); Assert.IsFalse(e.IndexModified); Assert.IsFalse(e.WorkingDirectoryModified); n++; }); Assert.AreEqual(21, n); Assert.AreEqual(0, paths.Count); client.Status(dir, sa, delegate(object sender, GitStatusEventArgs e) { switch (e.IndexStatus) { case GitStatus.New: case GitStatus.Deleted: case GitStatus.TypeChanged: client.Unstage(e.FullPath); break; } }); } }
void Unbind(GitClient client) { client.Notify -= new EventHandler<GitNotifyEventArgs>(OnClientNotify); //client.Processing -= new EventHandler<GitProcessingEventArgs>(OnClientProcessing); //client.Progress -= new EventHandler<GitProgressEventArgs>(OnClientProgress); //client.Cancel -= new EventHandler<CancelEventArgs>(OnClientCancel); }
public void LoadFromClient(GitClient client) { tagBox.BeginUpdate(); tagBox.Items.Clear(); foreach (var @ref in client.GetRefs(RepositoryPath)) { switch (@ref.Type) { case GitRefType.Tag: tagBox.Items.Add(@ref.ShortName); break; } } if (tagBox.Items.Count > 0) tagBox.SelectedIndex = 0; tagBox.EndUpdate(); }
public void ClonePublic() { string repos = GetTempPath(); using (GitClient git = new GitClient()) { GitCloneArgs ca = new GitCloneArgs(); ca.Synchronous = true; git.Clone(new Uri("https://github.com/libgit2/TestGitRepository.git"), repos, ca); List<string> found = new List<string>(); GitStatusArgs sa = new GitStatusArgs(); sa.IncludeUnmodified = true; sa.UseGlobPath = true; git.Status(repos, sa, delegate(object sender, GitStatusEventArgs e) { found.Add(e.RelativePath); }); Assert.That(found.Count, Is.EqualTo(8)); Assert.That(found, Is.All.Not.Null); Assert.That(found, Is.Unique); found.Clear(); git.Status(repos + "/a/*", sa, delegate(object sender, GitStatusEventArgs e) { found.Add(e.RelativePath); }); Assert.That(found.Count, Is.EqualTo(3)); Assert.That(found, Is.All.Not.Null); Assert.That(found, Is.Unique); GitFetchArgs fa = new GitFetchArgs(); fa.All = true; git.Fetch(repos, fa); using (GitRepository repo = new GitRepository(repos)) { Assert.That(repo.HeadBranch, Is.Not.Null); Assert.That(repo.HeadBranch.Name, Is.EqualTo("refs/heads/master")); Assert.That(repo.HeadBranch.UpstreamReference, Is.Not.Null); Assert.That(repo.HeadBranch.UpstreamReference.Name, Is.EqualTo("refs/remotes/origin/master")); Assert.That(repo.HeadBranch.IsHead, "Head knows that it is head"); //Assert.That(repo.HeadBranch.TrackedBranch, Is.Null); Assert.That(repo.HeadBranch.Name, Is.EqualTo("refs/heads/master")); Assert.That(repo.HeadBranch.IsRemote, Is.False, "Local branch"); Assert.That(repo.HeadBranch.RemoteName, Is.EqualTo("origin")); foreach (GitBranch b in repo.Branches.Remote) { Assert.That(b.IsRemote, "Remote branch"); Assert.That(b.IsLocal, Is.False, "Not local"); Assert.That(b.Name, Is.StringStarting("refs/remotes/origin/")); Assert.That(b.IsHead, Is.False); Assert.That(b.UpstreamReference, Is.Null); Assert.That(b.LocalUpstreamName, Is.Null); Assert.That(b.RemoteName, Is.EqualTo("origin")); } foreach (GitBranch b in repo.Branches.Local) { Assert.That(b.IsLocal, "Local branch"); Assert.That(b.IsRemote, Is.False, "Not remote"); Assert.That(b.Name, Is.StringStarting("refs/").Or.EqualTo("master")); Assert.That(b.IsHead, Is.EqualTo(b.ShortName == "master")); Assert.That(b.RemoteName, Is.EqualTo("origin")); if (!b.IsHead) { Assert.That(b.LocalUpstreamName, Is.Not.Null); GitBranch tracked = b.TrackedBranch; Assert.That(tracked, Is.Not.Null, "Have tracked"); Assert.That(b.RemoteName, Is.Not.Null); } } foreach (GitRemote r in repo.Remotes) { Assert.That(r.Name, Is.Not.Null); Assert.That(r.TagSynchronize, Is.EqualTo(GitTagSynchronize.Auto)); //Assert.That(r.Save(new GitFetchArgs())); foreach (GitRefSpec rs in r.FetchRefSpecs) { } foreach (GitRefSpec rs in r.PushRefSpecs) { } } } git.Pull(repos); // libgit2's local push code only supports bare repositories at // this time, so we use a few more clones to test the real push string cloneDir = GetTempPath(); GitCloneArgs cca = new GitCloneArgs(); cca.InitArgs.CreateBareRepository = true; git.Clone(repos, cloneDir, cca); string clone2Dir = GetTempPath(); git.Clone(cloneDir, clone2Dir); GitPushArgs pa = new GitPushArgs(); pa.Mode = GitPushMode.All; git.Push(clone2Dir, pa); } }
public void PushChanges() { string master = GetTempPath(); using (GitClient git = new GitClient()) { GitInitArgs ia = new GitInitArgs(); ia.CreateBareRepository = true; ia.Description = "Harry & Sally root"; git.Init(master, ia); } Uri masterUri = new Uri(master); string harry = GetTempPath(); string sally = GetTempPath(); using (GitClient git = new GitClient()) // Harry { git.Clone(masterUri, harry); using (GitRepository harryRepo = new GitRepository(harry)) { harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Harry"); harryRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**"); } string src = Path.Combine(harry, "src"); Directory.CreateDirectory(src); string index = Path.Combine(src, "index.txt"); File.WriteAllText(index, "This is index.txt\n"); string appCode = Path.Combine(harry, "app.c"); File.WriteAllText(appCode, @" #include <stdio.h> int main(int argc, const char **argv) { printf(""hello world\n""); return 0; } "); git.Add(index); git.Add(appCode); GitId result; GitCommitArgs cma = new GitCommitArgs(); cma.Signature.When = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); cma.Author.When = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc); git.Commit(harry, cma, out result); using (GitRepository harryRepo = new GitRepository(harry)) { GitCommit commit; Assert.That(harryRepo.Lookup(result, out commit)); Assert.That(commit.Author.Name, Is.EqualTo("Harry")); } } using (GitClient git = new GitClient()) // Sally { git.Clone(masterUri, sally); using (GitRepository sallyRepo = new GitRepository(sally)) { sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.name", "Sally"); sallyRepo.Configuration.Set(GitConfigurationLevel.Repository, "user.email", "*****@*****.**"); } string src = Path.Combine(sally, "src"); string index = Path.Combine(src, "index.txt"); Assert.That(File.Exists(index), Is.False); } using (GitClient git = new GitClient()) // Harry { GitPushArgs pa = new GitPushArgs(); pa.Mode = GitPushMode.All; git.Push(harry, pa); } using (GitClient git = new GitClient()) // Sally { GitPullArgs pa = new GitPullArgs(); pa.FetchArgs.All = true; git.Pull(sally, pa); string src = Path.Combine(sally, "src"); string index = Path.Combine(src, "index.txt"); Assert.That(File.Exists(index), Is.True); string appCode = Path.Combine(sally, "app.c"); File.WriteAllText(appCode, @" #include <stdio.h> int main(int argc, const char **argv) { int i; if (argc != 1) { fprintf(stderr, ""Usage %s <int>\n"", argv[0]); return 1; } for (i = 0; i < atoi(argv[1]); i++ printf(""hello world %d\n"", i); return 0; } "); git.Add(appCode); GitId result; GitCommitArgs cma = new GitCommitArgs(); cma.Signature.When = new DateTime(2000, 1, 2, 0, 0, 0, DateTimeKind.Utc); cma.Author.When = new DateTime(2000, 1, 2, 0, 0, 0, DateTimeKind.Utc); git.Commit(sally, cma, out result); GitPushArgs ph = new GitPushArgs(); ph.Mode = GitPushMode.All; git.Push(sally, ph); } using (GitClient git = new GitClient()) // Harry { string appCode = Path.Combine(harry, "app.c"); File.WriteAllText(appCode, @" #include <stdio.h> int main(int argc, const char **argv) { if (argc > 0 && strcmp(argv[1], ""-V"") { printf(""%s version 1.0 (c) QQn\n""); return 0; } printf(""hello world\n""); return 0; } "); git.Add(appCode); GitId result; GitCommitArgs cma = new GitCommitArgs(); cma.Signature.When = new DateTime(2000, 1, 3, 0, 0, 0, DateTimeKind.Utc); cma.Author.When = new DateTime(2000, 1, 3, 0, 0, 0, DateTimeKind.Utc); git.Commit(harry, cma, out result); // Local commit will succeed GitPushArgs ph = new GitPushArgs(); ph.Mode = GitPushMode.All; try { git.Push(harry, ph); // But push fails, as it conflicts Assert.Fail("Should have failed"); // ### } catch(GitException ge) { Assert.That(ge.Message, Is.StringContaining("Cannot push")); } GitPullArgs pa = new GitPullArgs(); pa.FetchArgs.All = true; git.Pull(harry, pa); bool gotConflict = false; git.Status(harry, delegate(object sender, GitStatusEventArgs e) { switch (e.RelativePath) { case "app.c": gotConflict = true; Assert.That(e.WorkingDirectoryStatus, Is.EqualTo(GitStatus.Normal)); Assert.That(e.IndexStatus, Is.EqualTo(GitStatus.Normal)); Assert.That(e.Conflicted, Is.True, "Conflicted"); break; default: Assert.Fail("Unexpected path: {0}", e.RelativePath); break; } }); Assert.That(gotConflict, "Found conflict status"); try { git.Push(harry, ph); // But push fails, as it conflicts Assert.Fail("Should still fail"); } catch (GitException ge) { Assert.That(ge.Message, Is.StringContaining("Cannot push")); } GitResetArgs ra = new GitResetArgs(); ra.Mode = GitResetMode.Hard; git.Reset(harry, ra); } }
public GitHubFollowerController(IConfiguration configuration) { gitClient = new GitClient(configuration); }