public virtual void TestSetForceUpdate() { string s = "refs/heads/*:refs/remotes/origin/*"; RefSpec a = new RefSpec(s); NUnit.Framework.Assert.IsFalse(a.IsForceUpdate()); RefSpec b = a.SetForceUpdate(true); NUnit.Framework.Assert.AreNotSame(a, b); NUnit.Framework.Assert.IsFalse(a.IsForceUpdate()); NUnit.Framework.Assert.IsTrue(b.IsForceUpdate()); NUnit.Framework.Assert.AreEqual(s, a.ToString()); NUnit.Framework.Assert.AreEqual("+" + s, b.ToString()); }
public virtual void TestSetForceUpdate() { string s = "refs/heads/*:refs/remotes/origin/*"; RefSpec a = new RefSpec(s); NUnit.Framework.Assert.IsFalse(a.IsForceUpdate()); RefSpec b = a.SetForceUpdate(true); NUnit.Framework.Assert.AreNotSame(a, b); NUnit.Framework.Assert.IsFalse(a.IsForceUpdate()); NUnit.Framework.Assert.IsTrue(b.IsForceUpdate()); NUnit.Framework.Assert.AreEqual(s, a.ToString()); NUnit.Framework.Assert.AreEqual("+" + s, b.ToString()); }
public static FileRepository Init (string targetLocalPath, string url, IProgressMonitor monitor) { InitCommand ci = new InitCommand (); ci.SetDirectory (targetLocalPath); var git = ci.Call (); FileRepository repo = (FileRepository) git.GetRepository (); string branch = Constants.R_HEADS + "master"; RefUpdate head = repo.UpdateRef (Constants.HEAD); head.DisableRefLog (); head.Link (branch); RemoteConfig remoteConfig = new RemoteConfig (repo.GetConfig (), "origin"); remoteConfig.AddURI (new URIish (url)); string dst = Constants.R_REMOTES + remoteConfig.Name; RefSpec wcrs = new RefSpec(); wcrs = wcrs.SetForceUpdate (true); wcrs = wcrs.SetSourceDestination (Constants.R_HEADS + "*", dst + "/*"); remoteConfig.AddFetchRefSpec (wcrs); // we're setting up for a clone with a checkout repo.GetConfig().SetBoolean ("core", null, "bare", false); remoteConfig.Update (repo.GetConfig()); repo.GetConfig().Save(); return repo; }
public static FileRepository Clone (string targetLocalPath, string url, IProgressMonitor monitor) { // Initialize InitCommand ci = new InitCommand (); ci.SetDirectory (targetLocalPath); var git = ci.Call (); FileRepository repo = (FileRepository) git.GetRepository (); string branch = Constants.R_HEADS + "master"; string remoteName = "origin"; RefUpdate head = repo.UpdateRef (Constants.HEAD); head.DisableRefLog (); head.Link (branch); RemoteConfig remoteConfig = new RemoteConfig (repo.GetConfig (), remoteName); remoteConfig.AddURI (new URIish (url)); string dst = Constants.R_REMOTES + remoteConfig.Name; RefSpec wcrs = new RefSpec(); wcrs = wcrs.SetForceUpdate (true); wcrs = wcrs.SetSourceDestination (Constants.R_HEADS + "*", dst + "/*"); remoteConfig.AddFetchRefSpec (wcrs); // we're setting up for a clone with a checkout repo.GetConfig().SetBoolean ("core", null, "bare", false); remoteConfig.Update (repo.GetConfig()); repo.GetConfig().Save(); // Fetch Transport tn = Transport.Open (repo, remoteName); FetchResult r; try { r = tn.Fetch(new GitMonitor (monitor), null); } finally { tn.Close (); } // Create the master branch // branch is like 'Constants.R_HEADS + branchName', we need only // the 'branchName' part String branchName = branch.Substring (Constants.R_HEADS.Length); git.BranchCreate ().SetName (branchName).SetUpstreamMode (CreateBranchCommand.SetupUpstreamMode.TRACK).SetStartPoint ("origin/master").Call (); // Checkout DirCache dc = repo.LockDirCache (); try { RevWalk rw = new RevWalk (repo); ObjectId remCommitId = repo.Resolve (remoteName + "/" + branchName); RevCommit remCommit = rw.ParseCommit (remCommitId); DirCacheCheckout co = new DirCacheCheckout (repo, null, dc, remCommit.Tree); co.Checkout (); } catch { dc.Unlock (); throw; } return repo; }