Instances of this class represent a Commit object. It represents a snapshot in a Git repository, who created it and when.
Наследование: Treeish
Пример #1
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();
        }
Пример #2
0
        public static Commit Create(string message, IEnumerable <Commit> parents, Tree tree, Author author, Author committer, DateTimeOffset time)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentException("message must not be null or empty");
            }
            if (tree == null)
            {
                throw new ArgumentException("tree must not be null");
            }
            var repo       = tree.Repository;
            var corecommit = new Core.Commit(repo._internal_repo);

            if (parents != null)
            {
                corecommit.ParentIds = parents.Select(parent => parent._id).ToArray();
            }
            corecommit.Author    = new Core.PersonIdent(author.Name, author.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
            corecommit.Committer = new Core.PersonIdent(committer.Name, committer.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
            corecommit.Message   = message;
            corecommit.TreeEntry = tree.InternalTree;
            corecommit.Encoding  = GetCommitEncoding(repo);
            corecommit.Save();
            return(new Commit(repo, corecommit));
        }
Пример #3
0
        public void CanReadFromMsysGitJapaneseRepository()
        {
            //setup of .git directory
            var resource =
                 new DirectoryInfo(Path.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"),
                                                          "JapaneseRepo"));
            var tempRepository =
                 new DirectoryInfo(Path.Combine(trash.FullName, "JapaneseRepo" + Path.GetRandomFileName()));
            CopyDirectory(resource.FullName, tempRepository.FullName);

            var repositoryPath = new DirectoryInfo(Path.Combine(tempRepository.FullName, Constants.DOT_GIT));
            Directory.Move(repositoryPath.FullName + "ted", repositoryPath.FullName);
            using (Repository repo = new Repository(tempRepository.FullName))
            {
                string commitHash = "24ed0e20ceff5e2cdf768345b6853213f840ff8f";

                var commit = new Commit(repo, commitHash);
                Assert.AreEqual("コミットのメッセージも日本語でやてみました。\n", commit.Message);
            }
        }
Пример #4
0
		public void Chinese_UTF8()
		{
			var workingDirectory = Path.Combine(trash.FullName, "汉语repo"); // a chinese repository
			using (var repo = Repository.Init(workingDirectory))
			{
				var index = repo.Index;
				string filepath = Path.Combine(workingDirectory, "henon喜欢什么.txt"); // what henon likes.txt
				File.WriteAllText(filepath, "我爱写汉字。"); // i love writing chinese characters.
				string filepath1 = Path.Combine(workingDirectory, "nulltoken喜欢什么.txt"); // what nulltoken likes.txt
				File.WriteAllText(filepath1, "他爱法国红酒。"); // he loves french red wine.
				var dir = Directory.CreateDirectory(Path.Combine(workingDirectory, "啤酒")).FullName; // creating a folder called "beer" 
				string filepath2 = Path.Combine(dir, "好喝的啤酒.txt"); // creating a file called "good beer.txt" in folder "beer"
				File.WriteAllText(filepath2, "青岛啤酒"); // the file contains a chinese beer called QingDao beer 

				// adding the files and directories we created.
				index.Add(filepath, filepath1, dir);

				// checking index
				var status = repo.Status;
				Assert.IsTrue(status.Added.Contains("henon喜欢什么.txt"));
				Assert.IsTrue(status.Added.Contains("nulltoken喜欢什么.txt"));
				Assert.IsTrue(status.Added.Contains("啤酒/好喝的啤酒.txt"));

				// committing, with the message; "China is very large. The great wall is very long. Shanghai is very pretty.", Author: "a student of the chinese language"
				var c = repo.Commit("中国很大。长城很长。上海很漂亮。", new Author("汉语学生", "*****@*****.**"));

				// loading the commit from the repository and inspecting its contents
				var commit = new Commit(repo, c.Hash);
				Assert.AreEqual("中国很大。长城很长。上海很漂亮。", commit.Message);
				Assert.AreEqual("汉语学生", commit.Author.Name);
				var dict = commit.Tree.Leaves.ToDictionary(leaf => leaf.Name);
				Assert.AreEqual("我爱写汉字。", dict["henon喜欢什么.txt"].Data);
				Assert.AreEqual("他爱法国红酒。", dict["nulltoken喜欢什么.txt"].Data);
				Tree tree = commit.Tree.Trees.First();
				Assert.AreEqual("啤酒", tree.Name);
				Leaf good_beer = tree.Leaves.First();
				Assert.AreEqual("好喝的啤酒.txt", good_beer.Name);
				Assert.AreEqual(Encoding.UTF8.GetBytes("青岛啤酒"), good_beer.RawData);
			}
		}
Пример #5
0
        public void test022_createCommitTag()
        {
            ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
            var almostEmptyTree = new Tree(db);
            almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
            ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);

            var almostEmptyCommit = new Commit(db)
                                        {
                                            Author = new PersonIdent(jauthor, 1154236443000L, -2*60),
                                            Committer = new PersonIdent(jauthor, 1154236443000L, -2*60),
                                            Message = "test022\n",
                                            TreeId = almostEmptyTreeId
                                        };

            ObjectId almostEmptyCommitId = new ObjectWriter(db).WriteCommit(almostEmptyCommit);

            var t = new Tag(db)
                        {
                            Id = almostEmptyCommitId,
                            TagType = "commit",
                            TagName = "test022",
                            Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
                            Message = "test022 tagged\n"
                        };

            t.Save();
            Assert.AreEqual("0ce2ebdb36076ef0b38adbe077a07d43b43e3807", t.TagId.Name);

            Tag mapTag = db.MapTag("test022");
            Assert.AreEqual("commit", mapTag.TagType);
            Assert.AreEqual("test022 tagged\n", mapTag.Message);
            Assert.AreEqual(new PersonIdent(jauthor, 1154236443000L, -4 * 60), mapTag.Author);
            Assert.AreEqual("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag.Id.Name);
        }
Пример #6
0
        public void test009_CreateCommitOldFormat()
        {
            writeTrashFile(".git/config", "[core]\n" + "legacyHeaders=1\n");
            db.Config.load();
            Assert.AreEqual(true, db.Config.getBoolean("core", "legacyHeaders", false));

            var t = new Tree(db);
            FileTreeEntry f = t.AddFile("i-am-a-file");
            writeTrashFile(f.Name, "and this is the data in me\n");
            t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);

            Assert.AreEqual(ObjectId.FromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"), t.TreeId);

            var c = new Commit(db)
                        {
                            Author = (new PersonIdent(jauthor, 1154236443000L, -4*60)),
                            Committer = (new PersonIdent(jcommitter, 1154236443000L, -4*60)),
                            Message = ("A Commit\n"),
                            TreeEntry = t
                        };
            Assert.AreEqual(t.TreeId, c.TreeId);
            c.Save();

            ObjectId cmtid = ObjectId.FromString("803aec4aba175e8ab1d666873c984c0308179099");
            Assert.AreEqual(cmtid, c.CommitId);

            // Verify the commit we just wrote is in the correct format.
            var xis = new XInputStream(new FileStream(db.ToFile(cmtid).FullName, System.IO.FileMode.Open, FileAccess.Read));
            try
            {
                Assert.AreEqual(0x78, xis.ReadUInt8());
                Assert.AreEqual(0x9c, xis.ReadUInt8());
                Assert.IsTrue(0x789c % 31 == 0);
            }
            finally
            {
                xis.Close();
            }

            // Verify we can Read it.
            Commit c2 = db.MapCommit(cmtid);
            Assert.IsNotNull(c2);
            Assert.AreEqual(c.Message, c2.Message);
            Assert.AreEqual(c.TreeId, c2.TreeId);
            Assert.AreEqual(c.Author, c2.Author);
            Assert.AreEqual(c.Committer, c2.Committer);
        }
Пример #7
0
 private ObjectId Commit(ObjectWriter ow, DirCache treeB, ObjectId[] parentIds)
 {
     var c = new Commit(db) { TreeId = treeB.writeTree(ow), Author = new PersonIdent("A U Thor", "a.u.thor", 1L, 0) };
     c.Committer = c.Author;
     c.ParentIds = parentIds;
     c.Message = "Tree " + c.TreeId.Name;
     return ow.WriteCommit(c);
 }
Пример #8
0
 internal Commit(Repository repo, Core.Commit internal_commit)
     : base(repo, internal_commit.CommitId)
 {
     _internal_commit = internal_commit;
 }
        public void Commit(string message)
        {
            if (!this.HasGitRepository) return;
            if (string.IsNullOrEmpty(message))
                throw new ArgumentException("Commit message must not be null or empty!", "message");

            this.index.RereadIfNecessary();
            var tree_id = this.index.writeTree();

            var parent = repository.MapCommit(repository.Resolve("HEAD"));

            if ((parent == null && this.index.Members.Count == 0) || (parent != null && parent.TreeId == tree_id))
                throw new InvalidOperationException("There are no changes to commit");

            var corecommit = new Commit(this.repository);
            corecommit.ParentIds = parent == null ? new ObjectId[0] : new ObjectId[] { parent.TreeId };
            var time = DateTimeOffset.Now;
            corecommit.Author =
            corecommit.Committer = new PersonIdent(this["user.name"], this["user.email"], time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
            corecommit.Message = message;
            corecommit.TreeEntry = this.repository.MapTree(tree_id);
            corecommit.Encoding = Charset.forName(this["i18n.commitencoding"] ?? "utf-8");
            corecommit.Save();

            var updateRef = this.repository.UpdateRef("HEAD");
            updateRef.NewObjectId = corecommit.CommitId;
            updateRef.IsForceUpdate = true;
            updateRef.update();

            Refresh();
        }
Пример #10
0
        public void Write_Simple_Commit()
        {
            var t = new Tree(db);
            FileTreeEntry f = t.AddFile("i-am-a-file");
            writeTrashFile(f.Name, "and this is the data in me\r\n\r\n");
            t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
            //new ObjectChecker().checkBlob(Constants.CHARSET.GetString(db.OpenObject(t.TreeId).getBytes()).ToCharArray());

            string s = new Inspector(db).Inspect(t.Id);
            string s1 = Inspector.Inspect("Resources/single_file_commit", "16c0beaf7523eb3ef5df45bd42dd4fc6343de864");
            string s2 = Inspector.Inspect("Resources/single_file_commit", "917c130bd4fa5bf2df0c399dc1b03401860aa448");
            string s3 = Inspector.Inspect("Resources/single_file_commit", "95ea6a6859af6791464bd8b6de76ad5a6f9fad81");

            //tree 917c130bd4fa5bf2df0c399dc1b03401860aa448\nauthor henon <*****@*****.**> 1245946742 +0200\ncommitter henon <*****@*****.**> 1245946742 +0200\n\nA Commit\n"

            Assert.AreEqual(ObjectId.FromString("917c130bd4fa5bf2df0c399dc1b03401860aa448"), t.Id);

            var c = new Commit(db)
                        {
                            Author = (new PersonIdent("henon", "*****@*****.**", 1245946742000L, 2*60)),
                            Committer = (new PersonIdent("henon", "*****@*****.**", 1245946742000L, 2*60)),
                            Message = ("A Commit\n"),
                            TreeEntry = (t)
                        };
            Assert.AreEqual(t.TreeId, c.TreeId);
            c.Save();

            string s_c = new Inspector(db).Inspect(c.CommitId);
            ObjectId cmtid = ObjectId.FromString("16c0beaf7523eb3ef5df45bd42dd4fc6343de864");
            Assert.AreEqual(cmtid, c.CommitId);

            // Verify the commit we just wrote is in the correct format.
            //using (var xis = new XInputStream(new FileStream(db.ToFile(cmtid).FullName, System.IO.FileMode.Open, FileAccess.Read)))
            //{
            //    Assert.AreEqual(0x78, xis.ReadUInt8());
            //    Assert.AreEqual(0x9c, xis.ReadUInt8());
            //    Assert.IsTrue(0x789c % 31 == 0);
            //}

            // Verify we can Read it.
            Commit c2 = db.MapCommit(cmtid.ToString());
            Assert.IsNotNull(c2);
            Assert.AreEqual(c.Message, c2.Message);
            Assert.AreEqual(c.TreeId, c2.TreeId);
            Assert.AreEqual(c.Author, c2.Author);
            Assert.AreEqual(c.Committer, c2.Committer);
        }
Пример #11
0
        public void test026_CreateCommitMultipleparents()
        {
            db.Config.load();

            var t = new Tree(db);
            FileTreeEntry f = t.AddFile("i-am-a-file");
            writeTrashFile(f.Name, "and this is the data in me\n");
            t.Accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
            Assert.AreEqual(ObjectId.FromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"),
                    t.TreeId);

            var c1 = new Commit(db)
                     	{
                     		Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
                     		Committer = new PersonIdent(jcommitter, 1154236443000L, -4*60),
                     		Message = "A Commit\n",
                     		TreeEntry = t
                     	};

            Assert.AreEqual(t.TreeId, c1.TreeId);
            c1.Save();
            ObjectId cmtid1 = ObjectId.FromString("803aec4aba175e8ab1d666873c984c0308179099");
            Assert.AreEqual(cmtid1, c1.CommitId);

            var c2 = new Commit(db)
                     	{
                     		Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
                     		Committer = new PersonIdent(jcommitter, 1154236443000L, -4*60),
                     		Message = "A Commit 2\n",
                     		TreeEntry = t
                     	};

            Assert.AreEqual(t.TreeId, c2.TreeId);
            c2.ParentIds = new[] { c1.CommitId };
            c2.Save();
            ObjectId cmtid2 = ObjectId.FromString("95d068687c91c5c044fb8c77c5154d5247901553");
            Assert.AreEqual(cmtid2, c2.CommitId);

            Commit rm2 = db.MapCommit(cmtid2);
            Assert.AreNotSame(c2, rm2); // assert the parsed objects is not from the cache
            Assert.AreEqual(c2.Author, rm2.Author);
            Assert.AreEqual(c2.CommitId, rm2.CommitId);
            Assert.AreEqual(c2.Message, rm2.Message);
            Assert.AreEqual(c2.TreeEntry.TreeId, rm2.TreeEntry.TreeId);
            Assert.AreEqual(1, rm2.ParentIds.Length);
            Assert.AreEqual(c1.CommitId, rm2.ParentIds[0]);

            var c3 = new Commit(db)
                     	{
                     		Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
                     		Committer = new PersonIdent(jcommitter, 1154236443000L, -4*60),
                     		Message = "A Commit 3\n",
                     		TreeEntry = t
                     	};

            Assert.AreEqual(t.TreeId, c3.TreeId);
            c3.ParentIds = new[] { c1.CommitId, c2.CommitId };
            c3.Save();
            ObjectId cmtid3 = ObjectId.FromString("ce6e1ce48fbeeb15a83f628dc8dc2debefa066f4");
            Assert.AreEqual(cmtid3, c3.CommitId);

            Commit rm3 = db.MapCommit(cmtid3);
            Assert.AreNotSame(c3, rm3); // assert the parsed objects is not from the cache
            Assert.AreEqual(c3.Author, rm3.Author);
            Assert.AreEqual(c3.CommitId, rm3.CommitId);
            Assert.AreEqual(c3.Message, rm3.Message);
            Assert.AreEqual(c3.TreeEntry.TreeId, rm3.TreeEntry.TreeId);
            Assert.AreEqual(2, rm3.ParentIds.Length);
            Assert.AreEqual(c1.CommitId, rm3.ParentIds[0]);
            Assert.AreEqual(c2.CommitId, rm3.ParentIds[1]);

            var c4 = new Commit(db)
                     	{
                     		Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
                     		Committer = new PersonIdent(jcommitter, 1154236443000L, -4*60),
                     		Message = "A Commit 4\n",
                     		TreeEntry = t
                     	};

            Assert.AreEqual(t.TreeId, c3.TreeId);
            c4.ParentIds = new[] { c1.CommitId, c2.CommitId, c3.CommitId };
            c4.Save();
            ObjectId cmtid4 = ObjectId.FromString("d1fca9fe3fef54e5212eb67902c8ed3e79736e27");
            Assert.AreEqual(cmtid4, c4.CommitId);

            Commit rm4 = db.MapCommit(cmtid4);
            Assert.AreNotSame(c4, rm3); // assert the parsed objects is not from the cache
            Assert.AreEqual(c4.Author, rm4.Author);
            Assert.AreEqual(c4.CommitId, rm4.CommitId);
            Assert.AreEqual(c4.Message, rm4.Message);
            Assert.AreEqual(c4.TreeEntry.TreeId, rm4.TreeEntry.TreeId);
            Assert.AreEqual(3, rm4.ParentIds.Length);
            Assert.AreEqual(c1.CommitId, rm4.ParentIds[0]);
            Assert.AreEqual(c2.CommitId, rm4.ParentIds[1]);
            Assert.AreEqual(c3.CommitId, rm4.ParentIds[2]);
        }
Пример #12
0
        public void French_UTF8()
        {
            var workingDirectory = Path.Combine(trash.FullName, "repo français"); // a french repository
            using (var repo = Repository.Init(workingDirectory))
            {
                var index = repo.Index;
                string filepath = Path.Combine(workingDirectory, "Émeric.txt"); // Emeric.txt
                File.WriteAllText(filepath, "était ici..."); // was here.
                var dir = Directory.CreateDirectory(Path.Combine(workingDirectory, "À moins")).FullName; // unless...
                string filepath2 = Path.Combine(dir, "qu'il ne fût là.txt"); // he's been there.txt
                File.WriteAllText(filepath2, "éèçàù"); // the file contains a some random letters with accents

                // adding the files and directories we created.
                index.Add(filepath, dir);

                // checking index
                var status = repo.Status;
                Assert.IsTrue(status.Added.Contains("Émeric.txt"));
                Assert.IsTrue(status.Added.Contains("À moins/qu'il ne fût là.txt"));

                // committing, with the message; "A little french touch.", Author: "Emeric"
                var c = repo.Commit("Une petite note française.", new Author("Émeric", "*****@*****.**"));

                // loading the commit from the repository and inspecting its contents
                var commit = new Commit(repo, c.Hash);
                Assert.AreEqual("Une petite note française.", commit.Message);
                Assert.AreEqual("Émeric", commit.Author.Name);
                var dict = commit.Tree.Leaves.ToDictionary(leaf => leaf.Name);
                Assert.AreEqual("était ici...", dict["Émeric.txt"].Data);
                Tree tree = commit.Tree.Trees.First();
                Assert.AreEqual("À moins", tree.Name);
                Leaf file3 = tree.Leaves.First();
                Assert.AreEqual("qu'il ne fût là.txt", file3.Name);
                Assert.AreEqual(Encoding.UTF8.GetBytes("éèçàù"), file3.RawData);
            }
        }
Пример #13
0
        public void CommitHonorsConfigCommitEncoding()
        {
            string workingDirectory = Path.Combine(trash.FullName, Path.GetRandomFileName());

            // Creating a new repo
            using (var repo = Repository.Init(workingDirectory))
            {
                // Setting the in-memory commitencoding configuration entry
                repo.Config["i18n.commitencoding"] = "ISO-8859-2";

                // Adding a new file to the filesystem
                string filepath = Path.Combine(workingDirectory, "a file.txt");
                File.WriteAllText(filepath, "content");

                // Adding the new file to index
                repo.Index.Add(filepath);

                // Committing
                string message = "Jak se máš?\n\nMám se dobře.";
                Commit c = repo.Commit(message, new Author("nulltoken", "*****@*****.**")); //How are you? I'm fine.

                // Loading the commit
                var commit = new Commit(repo, c.Hash);

                Assert.AreEqual("ISO-8859-2", commit.Encoding.WebName.ToUpperInvariant());

                var blob = new Blob(repo, c.Hash);
                var messageBytes = new byte[message.Length];
                Array.Copy(blob.RawData, 190, messageBytes, 0, message.Length);

                Assert.IsTrue(Encoding.GetEncoding("ISO-8859-2").GetBytes(message).SequenceEqual(messageBytes));
            }
        }
Пример #14
0
 public static Commit Create(string message, Commit parent, Tree tree, Author author, Author committer, DateTimeOffset time)
 {
     if (string.IsNullOrEmpty(message))
         throw new ArgumentException("message must not be null or empty");
     if (tree == null)
         throw new ArgumentException("tree must not be null");
     var repo = tree.Repository;
     var corecommit = new CoreCommit(repo._internal_repo);
     if (parent != null)
         corecommit.ParentIds = new GitSharp.Core.ObjectId[] { parent._id };
     corecommit.Author = new GitSharp.Core.PersonIdent(author.Name, author.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
     corecommit.Committer = new GitSharp.Core.PersonIdent(committer.Name, committer.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
     corecommit.Message = message;
     corecommit.TreeEntry = tree.InternalTree;
     corecommit.Encoding = ExtractOverridenEncodingCommitFromConfig(repo);
     corecommit.Save();
     return new Commit(repo, corecommit);
 }
Пример #15
0
        private static CommitDetail ConvertToCommitDetail(Commit commit)
        {
            var commitId = commit.CommitId;

            var author = commit.Author;
            var committer = commit.Committer;
            return new CommitDetail
            {
                CommitId = commitId.Name,
                Author = new UserInfo
                {
                    Name = author.Name,
                    Email = author.EmailAddress,
                    Date = Epoch.AddMilliseconds(author.When)
                },
                Committer = new UserInfo
                {
                    Name = committer.Name,
                    Email = committer.EmailAddress,
                    Date = Epoch.AddMilliseconds(committer.When)
                },
                ShortMessage = commit.Message,
            };
        }
Пример #16
0
        public void test023_createCommitNonAnullii()
        {
            ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
            var almostEmptyTree = new Tree(db);
            almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
            ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);

            var commit = new Commit(db)
                         	{
                         		TreeId = almostEmptyTreeId,
                         		Author = new PersonIdent("Joe H\u00e4cker", "*****@*****.**", 4294967295000L, 60),
                         		Committer = new PersonIdent("Joe Hacker", "*****@*****.**", 4294967295000L, 60),
                                Encoding = Constants.CHARSET,
                         		Message = "\u00dcbergeeks"
                         	};

            ObjectId cid = new ObjectWriter(db).WriteCommit(commit);
            Assert.AreEqual("4680908112778718f37e686cbebcc912730b3154", cid.Name);
        }
Пример #17
0
 public void test024_createCommitNonAscii()
 {
     ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
     var almostEmptyTree = new Tree(db);
     almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
     ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);
     var commit = new Commit(db)
                  	{
                  		TreeId = almostEmptyTreeId,
                  		Author = new PersonIdent("Joe H\u00e4cker", "*****@*****.**", 4294967295000L, 60),
                  		Committer = new PersonIdent("Joe Hacker", "*****@*****.**", 4294967295000L, 60),
                  		Encoding = Encoding.GetEncoding("ISO-8859-1"),
                  		Message = "\u00dcbergeeks"
                  	};
     ObjectId cid = new ObjectWriter(db).WriteCommit(commit);
     var s = new Inspector(db).Inspect(cid);
     Assert.AreEqual("2979b39d385014b33287054b87f77bcb3ecb5ebf", cid.ToString());
 }
Пример #18
0
 internal Commit(Repository repo, Core.Commit internal_commit)
     : base(repo, internal_commit.CommitId)
 {
     _internal_commit = internal_commit;
 }
Пример #19
0
        public void testTwoSuccessiveCommitsLinkedToHead()
        {
            var repo = createNewEmptyRepo();
            var workingDirectory = repo.WorkingDirectory;
            repo.Create();

            var objectWriter = new ObjectWriter(repo);

            FileInfo project1_a_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/A.txt"), "A.txt - first version\n");
            FileInfo project1_b_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/B.txt"), "B.txt - first version\n");

            var tree = new Tree(repo);
            Tree projectTree = tree.AddTree("Project-1");
            addFile(projectTree, project1_a_txt, objectWriter);
            projectTree.Id = (objectWriter.WriteTree(projectTree));
            addFile(projectTree, project1_b_txt, objectWriter);
            projectTree.Id = (objectWriter.WriteTree(projectTree));
            tree.Id = (objectWriter.WriteTree(tree));

            var commit = new Commit(repo)
            {
                Author = new PersonIdent(jauthor, (0L), 60),
                Committer = new PersonIdent(jcommitter, (0L), 60),
                Message = "Foo\n\nMessage",
                TreeEntry = tree
            };
            commit.Save();
            var commitId = commit.CommitId;

            FileInfo project1_b_v2_txt = writeTrashFile(Path.Combine(workingDirectory.FullName, "Project-1/B.txt"), "B.txt - second version\n");

            tree = new Tree(repo);
            projectTree = tree.AddTree("Project-1");
            addFile(projectTree, project1_a_txt, objectWriter);
            projectTree.Id = (objectWriter.WriteTree(projectTree));
            addFile(projectTree, project1_b_v2_txt, objectWriter);
            projectTree.Id = (objectWriter.WriteTree(projectTree));
            tree.Id = (objectWriter.WriteTree(tree));

            commit = new Commit(repo)
            {
                Author = new PersonIdent(jauthor, (0L), 60),
                Committer = new PersonIdent(jcommitter, (0L), 60),
                Message = "Modified",
                ParentIds = new[] { commitId },
                TreeEntry = tree
            };
            commit.Save();
            commitId = commit.CommitId;

            RefUpdate lck = repo.UpdateRef("refs/heads/master");
            Assert.IsNotNull(lck, "obtained lock");
            lck.NewObjectId = commitId;
            Assert.AreEqual(RefUpdate.RefUpdateResult.New, lck.ForceUpdate());
        }
Пример #20
0
 public BlobBasedSubmoduleConfig(Config cfg, Commit commit)
     : base(cfg, commit, ".gitmodules")
 {
 }
Пример #21
0
		public static Commit Create(string message, IEnumerable<Commit> parents, Tree tree, Author author, Author committer, DateTimeOffset time)
		{
			if (string.IsNullOrEmpty(message))
				throw new ArgumentException("message must not be null or empty");
			if (tree == null)
				throw new ArgumentException("tree must not be null");
			var repo = tree.Repository;
			var corecommit = new Core.Commit(repo._internal_repo);
			if (parents != null)
				corecommit.ParentIds = parents.Select(parent => parent._id).ToArray();
			corecommit.Author = new Core.PersonIdent(author.Name, author.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
			corecommit.Committer = new Core.PersonIdent(committer.Name, committer.EmailAddress, time.ToMillisecondsSinceEpoch(), (int)time.Offset.TotalMinutes);
			corecommit.Message = message;
			corecommit.TreeEntry = tree.InternalTree;
			corecommit.Encoding = GetCommitEncoding(repo);
			corecommit.Save();
			return new Commit(repo, corecommit);
		}
Пример #22
0
 public BlobBasedSubmoduleConfig(Commit commit)
     : this(null, commit)
 {
 }
Пример #23
0
        ///	<summary>
        /// Write a Commit to the object database
        ///	</summary>
        ///	<param name="c">Commit to store.</param>
        ///	<returns>SHA-1 of the commit.</returns>
        ///	<exception cref="IOException"></exception>
        public ObjectId WriteCommit(Commit c)
        {
            Encoding encoding = c.Encoding ?? Constants.CHARSET;
            var output = new MemoryStream();
            var s = new BinaryWriter(output, encoding);
            s.Write(HTree);
            s.Write(' ');
            c.TreeId.CopyTo(s);
            s.Write('\n');
            ObjectId[] parentIds = c.ParentIds;
            for (int i = 0; i < parentIds.Length; i++)
            {
                s.Write(HParent);
                s.Write(' ');
                parentIds[i].CopyTo(s);
                s.Write('\n');
            }
            s.Write(HAuthor);
            s.Write(' ');
            s.Write(c.Author.ToExternalString().ToCharArray());
            s.Write('\n');
            s.Write(HCommitter);
            s.Write(' ');
            s.Write(c.Committer.ToExternalString().ToCharArray());
            s.Write('\n');

            if (encoding != Constants.CHARSET)
            {
                s.Write(HEncoding);
                s.Write(' ');
                s.Write(Constants.encodeASCII(encoding.HeaderName.ToUpperInvariant()));
                s.Write('\n');
            }

            s.Write('\n');
            s.Write(c.Message.ToCharArray());

            return WriteCommit(output.ToArray());
        }
Пример #24
0
		///	<summary>
		/// The constructor from commit and path
		///	</summary>
		///	<param name="base">The base configuration file</param>
		///	<param name="commit">The commit that contains the object</param>
		///	<param name="path">The path within the tree of the commit</param>
		/// <exception cref="FileNotFoundException">
		/// the path does not exist in the commit's tree.
		/// </exception>
		/// <exception cref="IOException">
		/// the tree and/or blob cannot be accessed.
		/// </exception>
		/// <exception cref="ConfigInvalidException">
		/// the blob is not a valid configuration format.
		/// </exception>
		public BlobBasedConfig(Config @base, Commit commit, string path)
			: base(@base)
		{
			if (commit == null)
			{
				throw new System.ArgumentNullException("commit");
			}
			
			ObjectId treeId = commit.TreeId;
			Repository r = commit.Repository;
			TreeWalk.TreeWalk tree = TreeWalk.TreeWalk.ForPath(r, path, treeId);
			if (tree == null)
			{
				throw new FileNotFoundException("Entry not found by path: " + path);
			}
			ObjectId blobId = tree.getObjectId(0);
			ObjectLoader loader = tree.Repository.OpenBlob(blobId);
			
			if (loader == null)
			{
				throw new IOException("Blob not found: " + blobId + " for path: " + path);
			}

			fromText(RawParseUtils.decode(loader.Bytes));
		}