public async Task UpstreamWithCheckout() { using (var dir = new SelfDeletingDirectory(Path.GetFullPath(Path.Combine(basePath, nameof(this.UpstreamWithCheckout))))) { var upstreamPath = Path.Combine(dir.Path, "Upstream"); var authorPath = Path.Combine(dir.Path, "Author"); var downstreamPath = Path.Combine(dir.Path, "Downstream"); var contents = "Main Branch"; var sideContents = "Side branch"; var sideContentsRemoteChanges = "Side branch remote changes"; var identity = new Identity("Test Bot", "*****@*****.**"); Repository.Init(upstreamPath, true); Repository.Clone(upstreamPath, authorPath); using (var repo = new Repository(authorPath)) { var testFilePath = Path.Combine(dir.Path, "Author/test.txt"); //Create some test data on master File.WriteAllText(testFilePath, contents); Commands.Stage(repo, testFilePath); var sig = new Signature(identity, DateTime.Now); repo.Commit("Added test data", sig, sig); //Switch to side branch, and make update var authorBranchRepo = new BranchRepository(repo, mockup.Get <ICommitRepository>()); authorBranchRepo.Add("sidebranch"); authorBranchRepo.Checkout("sidebranch", new Signature(identity, DateTime.Now)); File.WriteAllText(testFilePath, sideContents); Commands.Stage(repo, testFilePath); sig = new Signature(identity, DateTime.Now); repo.Commit("Updated branch data", sig, sig); var syncRepo = new SyncRepository(repo, mockup.Get <ICommitRepository>(), mockup.Get <IGitCredentialsProvider>(), mockup.Get <IProcessRunner>()); //Push side branch await syncRepo.Push(); //Back to master authorBranchRepo.Checkout("master", new Signature(identity, DateTime.Now)); String masterText = File.ReadAllText(testFilePath); Assert.Equal(contents, masterText); await syncRepo.Push(); } Repository.Clone(upstreamPath, downstreamPath); using (var repo = new Repository(downstreamPath)) { var testFilePath = Path.Combine(dir.Path, "Downstream/test.txt"); var branchRepo = new BranchRepository(repo, mockup.Get <ICommitRepository>()); //First check master String masterText = File.ReadAllText(testFilePath); Assert.Equal(contents, masterText); //Swith to side branch and check branchRepo.Checkout("sidebranch", new Signature(identity, DateTime.Now)); String sideText = File.ReadAllText(testFilePath); Assert.Equal(sideContents, sideText); //Now make some changes and send them back File.WriteAllText(testFilePath, sideContentsRemoteChanges); Commands.Stage(repo, testFilePath); var sig = new Signature(identity, DateTime.Now); repo.Commit("Updated branch remotely", sig, sig); var syncRepo = new SyncRepository(repo, mockup.Get <ICommitRepository>(), mockup.Get <IGitCredentialsProvider>(), mockup.Get <IProcessRunner>()); await syncRepo.Push(); } using (var repo = new Repository(authorPath)) { var syncRepo = new SyncRepository(repo, mockup.Get <ICommitRepository>(), mockup.Get <IGitCredentialsProvider>(), mockup.Get <IProcessRunner>()); await syncRepo.Pull(new Signature(identity, DateTime.Now)); var testFilePath = Path.Combine(dir.Path, "Author/test.txt"); var branchRepo = new BranchRepository(repo, mockup.Get <ICommitRepository>()); branchRepo.Checkout("sidebranch", new Signature(identity, DateTime.Now)); String text = File.ReadAllText(testFilePath); Assert.Equal(sideContentsRemoteChanges, text); } } }