checkout() public method

Execute this checkout
public checkout ( ) : void
return void
Beispiel #1
0
        public void testCheckingOutWithConflicts()
        {
            var index = new GitIndex(db);
            index.add(trash, writeTrashFile("bar", "bar"));
            index.add(trash, writeTrashFile("foo/bar/baz/qux", "foo/bar"));
            recursiveDelete(new FileInfo(Path.Combine(trash.FullName, "bar")));
            recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "foo")));
            writeTrashFile("bar/baz/qux/foo", "another nasty one");
            writeTrashFile("foo", "troublesome little bugger");
            
            var workDirCheckout1 = new WorkDirCheckout(db, trash, index, index);

            AssertHelper.Throws<CheckoutConflictException>(workDirCheckout1.checkout);


            var workDirCheckout2 = new WorkDirCheckout(db, trash, index, index) { FailOnConflict = false };
            workDirCheckout2.checkout();

            Assert.IsTrue(new FileInfo(Path.Combine(trash.FullName, "bar")).IsFile());
            Assert.IsTrue(new FileInfo(Path.Combine(trash.FullName, "foo/bar/baz/qux")).IsFile());

            var index2 = new GitIndex(db);
            recursiveDelete(new FileInfo(Path.Combine(trash.FullName, "bar")));
            recursiveDelete(new DirectoryInfo(Path.Combine(trash.FullName, "foo")));
            index2.add(trash, writeTrashFile("bar/baz/qux/foo", "bar"));
            writeTrashFile("bar/baz/qux/bar", "evil? I thought it said WEEVIL!");
            index2.add(trash, writeTrashFile("foo", "lalala"));

            workDirCheckout2 = new WorkDirCheckout(db, trash, index2, index) { FailOnConflict = false };
            workDirCheckout2.checkout();

            Assert.IsTrue(new FileInfo(Path.Combine(trash.FullName, "bar")).IsFile());
            Assert.IsTrue(new FileInfo(Path.Combine(trash.FullName, "foo/bar/baz/qux")).IsFile());
            Assert.IsNotNull(index2.GetEntry("bar"));
            Assert.IsNotNull(index2.GetEntry("foo/bar/baz/qux"));
            Assert.IsNull(index2.GetEntry("bar/baz/qux/foo"));
            Assert.IsNull(index2.GetEntry("foo"));
        }
Beispiel #2
0
        private void Checkout(string working_directory)         // [henon] made this private to not confuse with Checkout( paths ). It seems to be not a common use case anyway and could be better exposed via the CheckoutCommand
        {
            if (InternalCommit == null)
            {
                throw new InvalidOperationException("Unable to checkout this commit. It was not initialized properly (i.e. the hash is not pointing to a commit object).");
            }
            if (working_directory == null)
            {
                throw new ArgumentException("Path to checkout directory must not be null");
            }
            if (new DirectoryInfo(working_directory).Exists == false)
            {
                throw new IOException("Cannot checkout into non-existent directory: " + working_directory);
            }
            var db    = _repo._internal_repo;
            var index = _repo.Index.GitIndex;

            index.RereadIfNecessary();
            CoreTree tree = InternalCommit.TreeEntry;
            var      co   = new GitSharp.Core.WorkDirCheckout(db, new DirectoryInfo(working_directory), index, tree);

            co.checkout();
        }
Beispiel #3
0
		private void Checkout(string working_directory) // [henon] made this private to not confuse with Checkout( paths ). It seems to be not a common use case anyway and could be better exposed via the CheckoutCommand
		{
			if (InternalCommit == null)
				throw new InvalidOperationException("Unable to checkout this commit. It was not initialized properly (i.e. the hash is not pointing to a commit object).");
			if (working_directory == null)
				throw new ArgumentException("Path to checkout directory must not be null");
			if (new DirectoryInfo(working_directory).Exists == false)
				throw new IOException("Cannot checkout into non-existent directory: " + working_directory);
			var db = _repo._internal_repo;
			var index = _repo.Index.GitIndex;
			index.RereadIfNecessary();
			CoreTree tree = InternalCommit.TreeEntry;
			var co = new GitSharp.Core.WorkDirCheckout(db, new DirectoryInfo(working_directory), index, tree);
			co.checkout();
		}
Beispiel #4
0
        private void doCheckout(GitSharp.Core.Ref branch)
        {
            if (branch == null)
                throw new ArgumentNullException("branch", "Cannot checkout; no HEAD advertised by remote");
            var repo = Repository._internal_repo;

            if (!Constants.HEAD.Equals(branch.getName()))
            {
                RefUpdate u1 = repo.UpdateRef(Constants.HEAD);
                u1.disableRefLog();
                u1.link(branch.getName());
            }

            GitSharp.Core.Commit commit = repo.MapCommit(branch.ObjectId);
            RefUpdate u = repo.UpdateRef(Constants.HEAD);
            u.NewObjectId = commit.CommitId;
            u.forceUpdate();
            GitIndex index = new GitIndex(repo);
            GitSharp.Core.Tree tree = commit.TreeEntry;
            WorkDirCheckout co = new WorkDirCheckout(repo, repo.WorkingDirectory, index, tree);
            co.checkout();
            index.write();
        }
Beispiel #5
0
 private void Checkout()
 {
     _theReadTree = new WorkDirCheckout(db, trash, _theHead, _theIndex, _theMerge);
     _theReadTree.checkout();
 }
Beispiel #6
0
        private void doCheckout(GitSharp.Core.Ref branch)
        {
            if (branch == null)
                throw new ArgumentNullException("branch", "Cannot checkout; no HEAD advertised by remote");

            if (!Constants.HEAD.Equals(branch.Name))
                GitRepository.WriteSymref(Constants.HEAD, branch.Name);
            GitSharp.Core.Commit commit = GitRepository.MapCommit(branch.ObjectId);
            RefUpdate u = GitRepository.UpdateRef(Constants.HEAD);
            u.NewObjectId = commit.CommitId;
            u.ForceUpdate();
            GitIndex index = new GitIndex(GitRepository);
            GitSharp.Core.Tree tree = commit.TreeEntry;
            WorkDirCheckout co = new WorkDirCheckout(GitRepository, GitRepository.WorkingDirectory, index, tree);
            co.checkout();
            index.write();
        }
		protected override void Run ()
		{
			var cloneDialog = new CloneRepositoryDialog ();
			cloneDialog.Run ();
			cloneDialog.Destroy ();
			
			var repositoryPath = cloneDialog.RepositoryPath;
			URIish source = new URIish (repositoryPath);
			var originName = cloneDialog.OriginName;
			var destination = cloneDialog.WorkingDirectory;
			var workingDirectory = Path.Combine (destination, Constants.DOT_GIT);
			
			if (string.IsNullOrEmpty (originName))
				originName = Constants.DEFAULT_REMOTE_NAME;
			
			var rep = new GitSharp.Core.Repository (new DirectoryInfo (workingDirectory));
			rep.Create ();
			rep.Config.setBoolean ("core", null, "bare", false);
			rep.Config.save ();
			
			var rc = new RemoteConfig (rep.Config, originName);
			rc.AddURI (source);
			rc.AddFetchRefSpec (new RefSpec ().SetForce (true).SetSourceDestination (
					Constants.R_HEADS + "*", 
					Constants.R_REMOTES + originName + "/*"));
			rc.Update (rep.Config);
			rep.Config.save ();
			
			Transport tn = Transport.open (rep, originName);
			FetchResult fetchResult = null;
			try 
			{
				fetchResult = tn.fetch (new NullProgressMonitor (), null);
			} 
			catch 
			{
				tn.Dispose ();
			}
			
			GitSharp.Core.Ref branch = null;
			if (fetchResult != null) 
			{
				var headId = fetchResult.GetAdvertisedRef (Constants.HEAD);
				var availableRefs = new List<GitSharp.Core.Ref> ();
				
				foreach (GitSharp.Core.Ref r in fetchResult.AdvertisedRefs) 
				{
					var n = r.Name;
					if (!n.StartsWith (Constants.R_HEADS))
						continue;
					
					availableRefs.Add (r);
					if (headId == null || branch != null)
						continue;
					
					if (r.ObjectId.Equals (headId.ObjectId))
						branch = r;
				}
				
				availableRefs.Sort (RefComparator.INSTANCE);
				
				if (headId != null && branch == null)
					branch = headId;
			}
			
			if (branch != null) 
			{
				if (!Constants.HEAD.Equals (branch.Name)) 
				{
					//rep. (Constants.HEAD, branch.Name);
					GitSharp.Core.Commit commit = rep.MapCommit (branch.ObjectId);
					RefUpdate update = rep.UpdateRef (Constants.HEAD);
					update.NewObjectId = commit.CommitId;
					update.forceUpdate ();
					
					var index = new GitIndex (rep);
					var tree = commit.TreeEntry;
					WorkDirCheckout co = new WorkDirCheckout (rep, rep.WorkingDirectory, index, tree);
					co.checkout ();
					index.write ();
				}
			} 
			else 
			{
				MessageService.ShowError ("Cannot clone: no HEAD advertised by remote.");
			}
			
			MessageService.ShowMessage(string.Format("Finished cloning {0} to {1}", 
					repositoryPath, 
					destination));
		}