Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Show how to clone/commit/push from a local bare repository

  • Loading branch information...
commit f192fc75081cc10a041dc49a9586ef8b4ae78787 1 parent 7081cd6
@yorah yorah authored
Showing with 45 additions and 0 deletions.
  1. +45 −0 LibGit2Sharp.Tests/CloneFixture.cs
View
45 LibGit2Sharp.Tests/CloneFixture.cs
@@ -51,6 +51,51 @@ private void AssertLocalClone(string path)
}
[Fact]
+ public void CanLocallyCloneAndCommitAndPush()
+ {
+ var scd = BuildSelfCleaningDirectory();
+ using (var originalRepo = new Repository(BuildTemporaryCloneOfTestRepo(BareTestRepoPath).RepositoryPath))
+ using (Repository clonedRepo = Repository.Clone(originalRepo.Info.Path, scd.RootedDirectoryPath))
+ {
+ Remote remote = clonedRepo.Network.Remotes["origin"];
+
+ // Compare before
+ Assert.Equal(originalRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier,
+ clonedRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier);
+ Assert.Equal(clonedRepo.Network.ListReferences(remote).Single(r => r.CanonicalName == "refs/heads/master"),
+ clonedRepo.Refs.Head.ResolveToDirectReference());
+
+ // Change local state (commit)
+ const string relativeFilepath = "new_file.txt";
+ string filePath = Path.Combine(clonedRepo.Info.WorkingDirectory, relativeFilepath);
+ File.WriteAllText(filePath, "__content__");
+ clonedRepo.Index.Stage(relativeFilepath);
+ clonedRepo.Commit("__commit_message__", DummySignature, DummySignature);
+
+ // Assert local state has changed
+ Assert.NotEqual(originalRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier,
+ clonedRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier);
+ Assert.NotEqual(clonedRepo.Network.ListReferences(remote).Single(r => r.CanonicalName == "refs/heads/master"),
+ clonedRepo.Refs.Head.ResolveToDirectReference());
+
+ // Push the change upstream (remote state is supposed to change)
+ clonedRepo.Network.Push(remote, "HEAD", @"refs/heads/master", OnPushStatusError);
+
+ // Assert that both local and remote repos are in sync
+ Assert.Equal(originalRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier,
+ clonedRepo.Refs["HEAD"].ResolveToDirectReference().TargetIdentifier);
+ Assert.Equal(clonedRepo.Network.ListReferences(remote).Single(r => r.CanonicalName == "refs/heads/master"),
+ clonedRepo.Refs.Head.ResolveToDirectReference());
+ }
+ }
+
+ private void OnPushStatusError(PushStatusError pushStatusErrors)
+ {
+ Assert.True(false, string.Format("Failed to update reference '{0}': {1}",
+ pushStatusErrors.Reference, pushStatusErrors.Message));
+ }
+
+ [Fact]
public void CanCloneALocalRepositoryFromALocalUri()
{
var uri = new Uri(BareTestRepoPath);
Please sign in to comment.
Something went wrong with that request. Please try again.