Exemple #1
0
 public void StaticGetLastFileCommit() {
     var dir = FileSystemHelper.ResetTemporaryDirectory();
     var gh = new GitHelper { DirectoryName = dir };
     Directory.CreateDirectory(Path.Combine(dir, "a"));
     var file = Path.Combine(dir, "a", "x");
     File.WriteAllText(file, "zzz");
     var file2 = Path.Combine(dir, "a", "y");
     File.WriteAllText(file2, "zzz2");
     gh.Init();
     gh.CommitAllChanges();
     var fstCommit = gh.GetCommitId();
     File.WriteAllText(file2, "zzz3");
     gh.CommitAllChanges();
     var secCommit = gh.GetCommitId();
     Assert.AreEqual(fstCommit, GitHelper.GetLastCommit(file).Hash);
     Assert.AreEqual(secCommit, GitHelper.GetLastCommit(file2).Hash);
 }
Exemple #2
0
		public void CanGetFileHistory(){
			var githelper = new GitHelper { DirectoryName = dirname, AuthorName = "test" }.Connect();
			githelper.WriteAndCommit("x", "a", "1");
			var first = githelper.GetCommitId();
			githelper.WriteAndCommit("x", "b", "2");
			var second = githelper.GetCommitId();
			var hist = githelper.GetHistory("x");
			Assert.AreEqual(2,hist.Length);
			Assert.AreEqual(second,hist[0].Hash);
			Assert.AreEqual(first,hist[1].Hash);
		}
Exemple #3
0
		public void CanGetCommitInfo(){
			var now = DateTime.Now;
			var githelper = new GitHelper { DirectoryName = dirname, AuthorName = "test" };
			githelper.Connect();
			githelper.WriteAndCommit("x","a","message");
			var info = githelper.GetCommitInfo();
			Assert.AreEqual(githelper.AuthorName,info.Author);
			Assert.AreEqual(githelper.AuthorName+"@auto."+Environment.MachineName+".com",info.AuthorEmail);
			Assert.AreEqual(githelper.GetCommitId(),info.Hash);
			Assert.AreEqual(githelper.GetCommitId().Substring(0,7),info.ShortHash);
			Assert.AreEqual(info.GlobalRevisionTime.ToLocalTime(),info.LocalRevisionTime);
			Assert.AreEqual("message",info.Comment);
			var now2 = DateTime.Now;
			Assert.True(info.LocalRevisionTime>=now.AddSeconds(-1) && info.LocalRevisionTime<=now2.AddSeconds(1));
		}
Exemple #4
0
		public void CanGetFileListUnicode()
		{
            
			var githelper = new GitHelper { DirectoryName = dirname, AuthorName = Applications.Application.Current.Principal.CurrentUser.Identity.Name };
			githelper.Connect();
			var initial = githelper.GetCommitId();
			var initialList = githelper.GetFileList();
			Assert.False(initialList.Any(_ => _ == "абв"));
			githelper.WriteAndCommit("абв", "a", "is a");
			var first = githelper.GetCommitId();
			Assert.True(githelper.GetFileList().Any(_ => _ == "абв"));
			Assert.AreEqual("a", githelper.GetContent("абв"));
		}
Exemple #5
0
		public void CanGetFileList()
		{
            Assert.NotNull(Applications.Application.Current);
		    if (null == Applications.Application.Current.Principal) {
		        var services = new StringBuilder();
		        foreach (var componentDefinition in Applications.Application.Current.Container.GetComponents()) {
		            services.AppendLine(string.Format("{0} {1}",componentDefinition.ServiceType.Name,componentDefinition.ImplementationType.Name));
		        }
                throw new Exception(services.ToString());
		    }
            Assert.NotNull(Applications.Application.Current.Principal);
            Assert.NotNull(Applications.Application.Current.Principal.CurrentUser);
            Assert.NotNull(Applications.Application.Current.Principal.CurrentUser.Identity);
			var githelper = new GitHelper { DirectoryName = dirname, AuthorName = Applications.Application.Current.Principal.CurrentUser.Identity.Name };
			githelper.Connect();
			var initial = githelper.GetCommitId();
			var initialList = githelper.GetFileList();
			Assert.False(initialList.Any(_=>_=="x"));
			githelper.WriteAndCommit("x", "a", "is a");
			var first = githelper.GetCommitId();
			Assert.True(githelper.GetFileList().Any(_ => _ == "x"));
			githelper.WriteAndCommit("x z", "b", "is b");
			Assert.True(githelper.GetFileList().Any(_ => _ == "x z"));
			Assert.False(githelper.GetFileList(first).Any(_ => _ == "x z"));
			Assert.True(githelper.GetFileList(first).Any(_ => _ == "x"));
			Assert.False(githelper.GetFileList(initial).Any(_ => _ == "x"));
		}
Exemple #6
0
		public void CanRestoreFile(){
			var githelper = new GitHelper{DirectoryName = dirname,AuthorName =Applications.Application.Current.Principal.CurrentUser.Identity.Name};
			githelper.Connect();
			var initial = githelper.GetCommitId();
			var currentFile = githelper.GetContent("x");
			Assert.Null(currentFile);
			githelper.WriteAndCommit("x","a","is a");
			var first = githelper.GetCommitId();
			Assert.AreNotEqual(initial,first);
			githelper.WriteAndCommit("x", "b", "is b");
			var second = githelper.GetCommitId();
			Assert.AreNotEqual(initial, second);
			var content = githelper.ReadFile("x");
			Assert.AreEqual("b",content);
			githelper.RestoreSingleFile("x",first);
			content = githelper.ReadFile("x");
			Assert.AreEqual("a",content);
		}
Exemple #7
0
		public void MergeCanUseCache()
		{
			var githelper = new GitHelper { DirectoryName = dirname }.Connect();
			var c1 = githelper.GetCommitId();
			githelper.ExecuteCommand("branch", "x");
			githelper.WriteAndCommit("x.txt", "xxx");
			ConsoleApplicationHandler.Calls = 0;
			Assert.True(githelper.IsMerged(c1, "HEAD"));
			Assert.True(githelper.IsMerged(c1, "HEAD"));
			Assert.AreEqual(4,ConsoleApplicationHandler.Calls);
			ConsoleApplicationHandler.Calls = 0;
			Assert.True(githelper.IsMerged(c1, "HEAD",true));
			Assert.True(githelper.IsMerged(c1, "HEAD", true));
			Assert.AreEqual(2, ConsoleApplicationHandler.Calls);
		}