Beispiel #1
0
        public virtual void TestSetSourceDestination()
        {
            RefSpec a = new RefSpec();
            RefSpec b;

            b = a.SetSourceDestination("refs/heads/*", "refs/remotes/origin/*");
            NUnit.Framework.Assert.AreNotSame(a, b);
            NUnit.Framework.Assert.AreEqual("HEAD", a.ToString());
            NUnit.Framework.Assert.AreEqual("refs/heads/*:refs/remotes/origin/*", b.ToString(
                                                ));
        }
Beispiel #2
0
		public virtual void TestSetSourceDestination()
		{
			RefSpec a = new RefSpec();
			RefSpec b;
			b = a.SetSourceDestination("refs/heads/*", "refs/remotes/origin/*");
			NUnit.Framework.Assert.AreNotSame(a, b);
			NUnit.Framework.Assert.AreEqual("HEAD", a.ToString());
			NUnit.Framework.Assert.AreEqual("refs/heads/*:refs/remotes/origin/*", b.ToString(
				));
		}
Beispiel #3
0
		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;
		}
Beispiel #4
0
		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;
		}