Exemple #1
0
		public void CanGetUnicodeCommitInfo()
		{
			var githelper = new GitHelper { DirectoryName = dirname, AuthorName = "test" };
			githelper.Connect();
			githelper.WriteAndCommit("x", "a", "it is сообщение");
			var info = githelper.GetCommitInfo();
			Assert.AreEqual("it is сообщение", info.Comment);
			
		}
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 CanGetDistance(){
			var githelper = new GitHelper { DirectoryName = dirname, AuthorName = "test" };
			githelper.Connect();
			var c1 = githelper.WriteAndCommit("x", "a", "message");
			var c2 = githelper.WriteAndCommit("x", "b", "message");
			var dist1 = githelper.GetDistance(c1, c2);
			Assert.AreEqual(0,dist1.Behind);
			Assert.AreEqual(1,dist1.Forward);
			Assert.True(dist1.IsForwardable);
			var dist2 = githelper.GetDistance(c2, c1);
			Assert.AreEqual(1, dist2.Behind);
			Assert.AreEqual(0, dist2.Forward);
			Assert.True(dist2.IsUpdateable);
			githelper.Checkout(c1);
			var c3 = githelper.WriteAndCommit("x", "c", "message");
			var dist3 = githelper.GetDistance(c2, c3);
			Assert.AreEqual(1, dist3.Behind);
			Assert.AreEqual(1, dist3.Forward);
			Assert.False(dist3.IsUpdateable);
			Assert.False(dist3.IsForwardable);
		}
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 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 #7
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 #8
0
		public void CanGetChangedList()
		{
			var githelper = new GitHelper { DirectoryName = dirname };
			githelper.Connect();
			githelper.WriteFile("x","1");
			githelper.WriteFile("y","1");
			var changed = githelper.GetChangedFilesList();
			Assert.AreEqual(2,changed.Length);
			Assert.True(changed.Any(_=>_.FileName=="x"));
			Assert.True(changed.Any(_=>_.FileName=="y"));
			var ver1 = githelper.CommitAllChanges("1");
			changed = githelper.GetChangedFilesList();
			Assert.AreEqual(0, changed.Length);
			changed = githelper.GetChangedFilesList(toref:"HEAD");
			Assert.AreEqual(2, changed.Length);
			var ver2 = githelper.WriteAndCommit("x", "2", "2");
			changed = githelper.GetChangedFilesList(toref: "HEAD");
			Assert.AreEqual(1, changed.Length);
			var ver3 = githelper.WriteAndCommit("y", "2", "3");
			changed = githelper.GetChangedFilesList(toref: "HEAD");
			Assert.AreEqual(1, changed.Length);
			changed = githelper.GetChangedFilesList(fromref:ver1,toref: "HEAD");
			Assert.AreEqual(2, changed.Length);
		}
Exemple #9
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);
		}
Exemple #10
0
	    public void MergeCanBeTested(){
			var githelper = new GitHelper { DirectoryName = dirname }.Connect();
		    githelper.ExecuteCommand("branch", "x");
		    githelper.WriteAndCommit("x.txt", "xxx");
		    Assert.True(githelper.IsMerged("x", "HEAD"));
		    githelper.Checkout("x");
			githelper.WriteAndCommit("y.txt", "yyy");
		    githelper.Checkout(githelper.Branch);
			Assert.False(githelper.IsMerged("x", "HEAD"));
	    }
Exemple #11
0
		public void CanReadTags(){
			var githelper = new GitHelper { DirectoryName = dirname }.Connect();
			githelper.WriteAndCommit("a", "b");
			githelper.SetTag("a");
			githelper.WriteAndCommit("c", "d");
			githelper.SetTag("b");
			githelper.WriteAndCommit("e", "f");
			githelper.SetTag("c");
			var tags = githelper.GetTags();
			Assert.AreEqual(3,tags.Length);
			CollectionAssert.AreEquivalent(tags.Select(_=>_.Name),new[]{"a","b","c"});
		}