Close() public method

public Close ( ) : void
return void
Ejemplo n.º 1
0
 public virtual void TestAddUnstagedChanges()
 {
     FilePath file = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("content");
     writer.Close();
     Git git = new Git(db);
     git.Add().AddFilepattern("a.txt").Call();
     RevCommit commit = git.Commit().SetMessage("initial commit").Call();
     TreeWalk tw = TreeWalk.ForPath(db, "a.txt", commit.Tree);
     NUnit.Framework.Assert.AreEqual("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", tw.GetObjectId
         (0).GetName());
     writer = new PrintWriter(file);
     writer.Write("content2");
     writer.Close();
     commit = git.Commit().SetMessage("second commit").Call();
     tw = TreeWalk.ForPath(db, "a.txt", commit.Tree);
     NUnit.Framework.Assert.AreEqual("6b584e8ece562ebffc15d38808cd6b98fc3d97ea", tw.GetObjectId
         (0).GetName());
     commit = git.Commit().SetAll(true).SetMessage("third commit").SetAll(true).Call();
     tw = TreeWalk.ForPath(db, "a.txt", commit.Tree);
     NUnit.Framework.Assert.AreEqual("db00fd65b218578127ea51f3dffac701f12f486a", tw.GetObjectId
         (0).GetName());
 }
Ejemplo n.º 2
0
 public virtual void TestAddExistingSingleBinaryFile()
 {
     FilePath file = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("row1\r\nrow2\u0000");
     writer.Close();
     Git git = new Git(db);
     ((FileBasedConfig)db.GetConfig()).SetString("core", null, "autocrlf", "false");
     git.Add().AddFilepattern("a.txt").Call();
     NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:row1\r\nrow2\u0000]"
         , IndexState(CONTENT));
     ((FileBasedConfig)db.GetConfig()).SetString("core", null, "autocrlf", "true");
     git.Add().AddFilepattern("a.txt").Call();
     NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:row1\r\nrow2\u0000]"
         , IndexState(CONTENT));
     ((FileBasedConfig)db.GetConfig()).SetString("core", null, "autocrlf", "input");
     git.Add().AddFilepattern("a.txt").Call();
     NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:row1\r\nrow2\u0000]"
         , IndexState(CONTENT));
 }
Ejemplo n.º 3
0
 public virtual void TestModeChange()
 {
     Git git = new Git(db);
     // create file
     FilePath file = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("content1");
     writer.Close();
     // First commit - a.txt file
     git.Add().AddFilepattern("a.txt").Call();
     git.Commit().SetMessage("commit1").SetCommitter(committer).Call();
     // pure mode change should be committable
     FS fs = db.FileSystem;
     fs.SetExecute(file, true);
     git.Add().AddFilepattern("a.txt").Call();
     git.Commit().SetMessage("mode change").SetCommitter(committer).Call();
     // pure mode change should be committable with -o option
     fs.SetExecute(file, false);
     git.Add().AddFilepattern("a.txt").Call();
     git.Commit().SetMessage("mode change").SetCommitter(committer).SetOnly("a.txt").Call
         ();
 }
Ejemplo n.º 4
0
 public virtual void TestLogWithFilter()
 {
     Git git = new Git(db);
     // create first file
     FilePath file = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("content1");
     writer.Close();
     // First commit - a.txt file
     git.Add().AddFilepattern("a.txt").Call();
     git.Commit().SetMessage("commit1").SetCommitter(committer).Call();
     // create second file
     file = new FilePath(db.WorkTree, "b.txt");
     FileUtils.CreateNewFile(file);
     writer = new PrintWriter(file);
     writer.Write("content2");
     writer.Close();
     // Second commit - b.txt file
     git.Add().AddFilepattern("b.txt").Call();
     git.Commit().SetMessage("commit2").SetCommitter(committer).Call();
     // First log - a.txt filter
     int count = 0;
     foreach (RevCommit c in git.Log().AddPath("a.txt").Call())
     {
         NUnit.Framework.Assert.AreEqual("commit1", c.GetFullMessage());
         count++;
     }
     NUnit.Framework.Assert.AreEqual(1, count);
     // Second log - b.txt filter
     count = 0;
     foreach (RevCommit c_1 in git.Log().AddPath("b.txt").Call())
     {
         NUnit.Framework.Assert.AreEqual("commit2", c_1.GetFullMessage());
         count++;
     }
     NUnit.Framework.Assert.AreEqual(1, count);
     // Third log - without filter
     count = 0;
     foreach (RevCommit c_2 in git.Log().Call())
     {
         NUnit.Framework.Assert.AreEqual(committer, c_2.GetCommitterIdent());
         count++;
     }
     NUnit.Framework.Assert.AreEqual(2, count);
 }
Ejemplo n.º 5
0
 public virtual void TestAddExistingSingleFile()
 {
     FilePath file = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("content");
     writer.Close();
     Git git = new Git(db);
     git.Add().AddFilepattern("a.txt").Call();
     NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:content]", IndexState
         (CONTENT));
 }
Ejemplo n.º 6
0
 public virtual void TestAddWithParameterUpdate()
 {
     FileUtils.Mkdir(new FilePath(db.WorkTree, "sub"));
     FilePath file = new FilePath(db.WorkTree, "sub/a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("content");
     writer.Close();
     FilePath file2 = new FilePath(db.WorkTree, "sub/b.txt");
     FileUtils.CreateNewFile(file2);
     writer = new PrintWriter(file2);
     writer.Write("content b");
     writer.Close();
     Git git = new Git(db);
     git.Add().AddFilepattern("sub").Call();
     NUnit.Framework.Assert.AreEqual("[sub/a.txt, mode:100644, content:content]" + "[sub/b.txt, mode:100644, content:content b]"
         , IndexState(CONTENT));
     git.Commit().SetMessage("commit").Call();
     // new unstaged file sub/c.txt
     FilePath file3 = new FilePath(db.WorkTree, "sub/c.txt");
     FileUtils.CreateNewFile(file3);
     writer = new PrintWriter(file3);
     writer.Write("content c");
     writer.Close();
     // file sub/a.txt is modified
     writer = new PrintWriter(file);
     writer.Write("modified content");
     writer.Close();
     FileUtils.Delete(file2);
     // change in sub/a.txt is staged
     // deletion of sub/b.txt is staged
     // sub/c.txt is not staged
     git.Add().AddFilepattern("sub").SetUpdate(true).Call();
     // change in sub/a.txt is staged
     NUnit.Framework.Assert.AreEqual("[sub/a.txt, mode:100644, content:modified content]"
         , IndexState(CONTENT));
 }
Ejemplo n.º 7
0
 public virtual void TestAddWholeRepo()
 {
     FileUtils.Mkdir(new FilePath(db.WorkTree, "sub"));
     FilePath file = new FilePath(db.WorkTree, "sub/a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("content");
     writer.Close();
     FilePath file2 = new FilePath(db.WorkTree, "sub/b.txt");
     FileUtils.CreateNewFile(file2);
     writer = new PrintWriter(file2);
     writer.Write("content b");
     writer.Close();
     Git git = new Git(db);
     git.Add().AddFilepattern(".").Call();
     NUnit.Framework.Assert.AreEqual("[sub/a.txt, mode:100644, content:content]" + "[sub/b.txt, mode:100644, content:content b]"
         , IndexState(CONTENT));
 }
Ejemplo n.º 8
0
 public virtual void TestAddWithConflicts()
 {
     // prepare conflict
     FilePath file = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("content");
     writer.Close();
     FilePath file2 = new FilePath(db.WorkTree, "b.txt");
     FileUtils.CreateNewFile(file2);
     writer = new PrintWriter(file2);
     writer.Write("content b");
     writer.Close();
     ObjectInserter newObjectInserter = db.NewObjectInserter();
     DirCache dc = db.LockDirCache();
     DirCacheBuilder builder = dc.Builder();
     AddEntryToBuilder("b.txt", file2, newObjectInserter, builder, 0);
     AddEntryToBuilder("a.txt", file, newObjectInserter, builder, 1);
     writer = new PrintWriter(file);
     writer.Write("other content");
     writer.Close();
     AddEntryToBuilder("a.txt", file, newObjectInserter, builder, 3);
     writer = new PrintWriter(file);
     writer.Write("our content");
     writer.Close();
     AddEntryToBuilder("a.txt", file, newObjectInserter, builder, 2).GetObjectId();
     builder.Commit();
     NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, stage:1, content:content]"
         + "[a.txt, mode:100644, stage:2, content:our content]" + "[a.txt, mode:100644, stage:3, content:other content]"
          + "[b.txt, mode:100644, content:content b]", IndexState(CONTENT));
     // now the test begins
     Git git = new Git(db);
     dc = git.Add().AddFilepattern("a.txt").Call();
     NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:our content]" + "[b.txt, mode:100644, content:content b]"
         , IndexState(CONTENT));
 }
Ejemplo n.º 9
0
 public virtual void TestAddRemovedFile()
 {
     FilePath file = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("content");
     writer.Close();
     Git git = new Git(db);
     DirCache dc = git.Add().AddFilepattern("a.txt").Call();
     dc.GetEntry(0).GetObjectId();
     FileUtils.Delete(file);
     // is supposed to do nothing
     dc = git.Add().AddFilepattern("a.txt").Call();
     NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:content]", IndexState
         (CONTENT));
 }
Ejemplo n.º 10
0
 public virtual void TestAddExistingSingleMediumSizeFileWithNewLine()
 {
     FilePath file = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(file);
     StringBuilder data = new StringBuilder();
     for (int i = 0; i < 1000; ++i)
     {
         data.Append("row1\r\nrow2");
     }
     string crData = data.ToString();
     PrintWriter writer = new PrintWriter(file);
     writer.Write(crData);
     writer.Close();
     string lfData = data.ToString().ReplaceAll("\r", string.Empty);
     Git git = new Git(db);
     ((FileBasedConfig)db.GetConfig()).SetString("core", null, "autocrlf", "false");
     git.Add().AddFilepattern("a.txt").Call();
     NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:" + data + "]", IndexState
         (CONTENT));
     ((FileBasedConfig)db.GetConfig()).SetString("core", null, "autocrlf", "true");
     git.Add().AddFilepattern("a.txt").Call();
     NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:" + lfData + "]", IndexState
         (CONTENT));
     ((FileBasedConfig)db.GetConfig()).SetString("core", null, "autocrlf", "input");
     git.Add().AddFilepattern("a.txt").Call();
     NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:" + lfData + "]", IndexState
         (CONTENT));
 }
Ejemplo n.º 11
0
 public virtual void TestAddExistingSingleFileTwiceWithCommit()
 {
     FilePath file = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(file);
     PrintWriter writer = new PrintWriter(file);
     writer.Write("content");
     writer.Close();
     Git git = new Git(db);
     DirCache dc = git.Add().AddFilepattern("a.txt").Call();
     dc.GetEntry(0).GetObjectId();
     git.Commit().SetMessage("commit a.txt").Call();
     writer = new PrintWriter(file);
     writer.Write("other content");
     writer.Close();
     dc = git.Add().AddFilepattern("a.txt").Call();
     NUnit.Framework.Assert.AreEqual("[a.txt, mode:100644, content:other content]", IndexState
         (CONTENT));
 }
Ejemplo n.º 12
0
 /// <exception cref="System.IO.IOException"></exception>
 /// <exception cref="NGit.Api.Errors.JGitInternalException"></exception>
 /// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
 public virtual void SetupRepository()
 {
     // create initial commit
     git = new Git(db);
     initialCommit = git.Commit().SetMessage("initial commit").Call();
     // create nested file
     FilePath dir = new FilePath(db.WorkTree, "dir");
     FileUtils.Mkdir(dir);
     FilePath nestedFile = new FilePath(dir, "b.txt");
     FileUtils.CreateNewFile(nestedFile);
     PrintWriter nesterFileWriter = new PrintWriter(nestedFile);
     nesterFileWriter.Write("content");
     nesterFileWriter.Flush();
     // create file
     indexFile = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(indexFile);
     PrintWriter writer = new PrintWriter(indexFile);
     writer.Write("content");
     writer.Flush();
     // add file and commit it
     git.Add().AddFilepattern("dir").AddFilepattern("a.txt").Call();
     secondCommit = git.Commit().SetMessage("adding a.txt and dir/b.txt").Call();
     prestage = DirCache.Read(db.GetIndexFile(), db.FileSystem).GetEntry(indexFile.GetName
         ());
     // modify file and add to index
     writer.Write("new content");
     writer.Close();
     nesterFileWriter.Write("new content");
     nesterFileWriter.Close();
     git.Add().AddFilepattern("a.txt").AddFilepattern("dir").Call();
     // create a file not added to the index
     untrackedFile = new FilePath(db.WorkTree, "notAddedToIndex.txt");
     FileUtils.CreateNewFile(untrackedFile);
     PrintWriter writer2 = new PrintWriter(untrackedFile);
     writer2.Write("content");
     writer2.Close();
 }
Ejemplo n.º 13
0
 /// <exception cref="System.IO.IOException"></exception>
 /// <exception cref="NGit.Api.Errors.NoFilepatternException"></exception>
 /// <exception cref="NGit.Api.Errors.NoHeadException"></exception>
 /// <exception cref="NGit.Api.Errors.NoMessageException"></exception>
 /// <exception cref="NGit.Api.Errors.ConcurrentRefUpdateException"></exception>
 /// <exception cref="NGit.Api.Errors.JGitInternalException"></exception>
 /// <exception cref="NGit.Api.Errors.WrongRepositoryStateException"></exception>
 public virtual void SetupRepository()
 {
     // create initial commit
     git = new Git(db);
     initialCommit = git.Commit().SetMessage("initial commit").Call();
     // create file
     indexFile = new FilePath(db.WorkTree, "a.txt");
     FileUtils.CreateNewFile(indexFile);
     PrintWriter writer = new PrintWriter(indexFile);
     writer.Write("content");
     writer.Flush();
     // add file and commit it
     git.Add().AddFilepattern("a.txt").Call();
     git.Commit().SetMessage("adding a.txt").Call();
     // modify file and add to index
     writer.Write("new content");
     writer.Close();
     git.Add().AddFilepattern("a.txt").Call();
     // create a file not added to the index
     untrackedFile = new FilePath(db.WorkTree, "notAddedToIndex.txt");
     FileUtils.CreateNewFile(untrackedFile);
     PrintWriter writer2 = new PrintWriter(untrackedFile);
     writer2.Write("content");
     writer2.Close();
 }