/// <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(); secondCommit = git.Commit().SetMessage("adding a.txt").Call(); prestage = DirCache.Read(db.GetIndexFile(), db.FileSystem).GetEntry(indexFile.GetName ()); // 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(); }
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()); }
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)); }
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)); }
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)); }
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)); }
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)); }
public override void PrintStackTrace(PrintWriter s) { if (interpreterStackInfo == null) { base.Sharpen.Runtime.PrintStackTrace(s); } else { s.Write(GenerateStackTrace()); } }
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 (); }
private static string GetStackTraceString(Exception tr) { if (tr == null) { return Environment.StackTrace; } StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); Runtime.PrintStackTrace(tr, printWriter); return stringWriter.ToString(); }
private static string ToString(Block[] blockList, Node[] statementNodes) { return null; StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.WriteLine(blockList.Length + " Blocks"); for (int i = 0; i < blockList.Length; i++) { Block b = blockList[i]; pw.WriteLine("#" + b.itsBlockID); pw.WriteLine("from " + b.itsStartNodeIndex + " " + statementNodes[b.itsStartNodeIndex].ToString()); pw.WriteLine("thru " + b.itsEndNodeIndex + " " + statementNodes[b.itsEndNodeIndex].ToString()); pw.Write("Predecessors "); if (b.itsPredecessors != null) { for (int j = 0; j < b.itsPredecessors.Length; j++) { pw.Write(b.itsPredecessors[j].itsBlockID + " "); } pw.WriteLine(); } else { pw.WriteLine("none"); } pw.Write("Successors "); if (b.itsSuccessors != null) { for (int j = 0; j < b.itsSuccessors.Length; j++) { pw.Write(b.itsSuccessors[j].itsBlockID + " "); } pw.WriteLine(); } else { pw.WriteLine("none"); } } return sw.ToString(); }
internal SideBandProgressMonitor(OutputStream os) { @out = new PrintWriter(new OutputStreamWriter(os, Constants.CHARSET)); }
private static string GetStackTraceString(Exception tr) { if (tr == null) { return string.Empty; } StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); Sharpen.Runtime.PrintStackTrace(tr, printWriter); return stringWriter.ToString(); }
public static void ReportWarning(string message, Exception t) { int[] linep = new int[] { 0 }; string filename = GetSourcePositionFromStack(linep); TextWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.WriteLine(message); Sharpen.Runtime.PrintStackTrace(t, pw); pw.Flush(); Rhino.Context.ReportWarning(sw.ToString(), filename, linep[0], null, 0); }
private static string GetStackTraceString(Exception tr) { if (tr == null) { #if PORTABLE return string.Empty; #else return Environment.StackTrace; #endif } StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); Runtime.PrintStackTrace(tr, printWriter); return stringWriter.ToString(); }
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)); }
public ConsoleTextArea(string[] argv) : base() { history = new List<string>(); console1 = new ConsoleWriter(this); console2 = new ConsoleWriter(this); @out = new TextWriter(console1, true); err = new TextWriter(console2, true); PipedOutputStream outPipe = new PipedOutputStream(); inPipe = new PrintWriter(outPipe); @in = new PipedInputStream(); try { outPipe.Connect(@in); } catch (IOException exc) { Sharpen.Runtime.PrintStackTrace(exc); } GetDocument().AddDocumentListener(this); AddKeyListener(this); SetLineWrap(true); SetFont(new Font("Monospaced", 0, 12)); }
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); }
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)); }
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)); }
internal SimpleShellConsole(Stream @in, TextWriter ps, Encoding cs) { this.@in = @in; this.@out = new PrintWriter(ps); this.reader = new BufferedReader(new StreamReader(@in, cs)); }