Esempio n. 1
0
        /// <summary>
        /// Инициализирует репозиторий в указанной папке
        /// </summary>
        /// <param name="dir"></param>
        public static void Init(string dir)
        {
            var gh = new GitHelper {
                DirectoryName = dir
            };

            gh.Init();
        }
Esempio n. 2
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);
 }
Esempio n. 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));
		}
Esempio n. 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("абв"));
		}
Esempio n. 5
0
		public void CanInitDir(){
			var githelper = new GitHelper{DirectoryName = dirname};
			githelper.Connect();
			Assert.True(Directory.Exists(dirname));
			Assert.True(Directory.Exists(dirname+"\\.git"));
		}
Esempio n. 6
0
        /// <summary>
        /// Инициализирует репозиторий в указанной папке
        /// </summary>
        /// <param name="dir"></param>
	    public static void Init(string dir) {
            var gh = new GitHelper {DirectoryName = dir};
            gh.Init();
        }
Esempio n. 7
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);
			
		}
Esempio n. 8
0
		public void CanGetNonExistedCommitAsNull()
		{
			var githelper = new GitHelper { DirectoryName = dirname, AuthorName = "test" };
			githelper.Connect();
			var info = githelper.GetCommitInfo("nonexisted");
			Assert.Null(info);
		}
Esempio n. 9
0
		public void CanCheckRemoteConnection()
		{
			var githelper = new GitHelper { RemoteUrl = "https://assoi-git.ugmk.com:8601/qorpent.kernel.git" };
			Assert.True(githelper.IsRemoteAccessible());
			githelper.RemoteUrl = "https://non-existed:9899/qorpent.kernel.git";
			Assert.False(githelper.IsRemoteAccessible());
		}
Esempio n. 10
0
		public void CanInitDirWithQorpentSysClone()
		{
			var githelper = new GitHelper { DirectoryName = dirname, AuthorName="comdiv",Password = "******",RemoteUrl = "https://assoi-git.ugmk.com:8601/qorpent.kernel.git" };
			githelper.Connect();
			Assert.True(Directory.Exists(dirname + "\\default-content"));

		}
Esempio n. 11
0
		public void CanInitDirWithQorpentSys()
		{
			var githelper = new GitHelper { DirectoryName = dirname,RemoteUrl = "g:/repos/qorpent.kernel"};
			githelper.Connect();
			Assert.True(Directory.Exists(dirname+"\\default-content"));
			
		}
Esempio n. 12
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);
		}
Esempio n. 13
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"));
	    }
Esempio n. 14
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"});
		}
Esempio n. 15
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);
		}
Esempio n. 16
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);
		}
Esempio n. 17
0
		public void CanGetNullDistanceOnUnknown()
		{
			var githelper = new GitHelper { DirectoryName = dirname, AuthorName = "test" };
			githelper.Connect();
			
			var dist1 = githelper.GetDistance("x","y");
			Assert.Null(dist1);
		}
Esempio n. 18
0
		public void CanGetContent() {
			var githelper = new GitHelper { DirectoryName = dirname, RemoteUrl = "g:/repos/qorpent.kernel" };
			githelper.Connect();
			var content = githelper.GetContent("LICENSE");
			StringAssert.StartsWith("Copyright 2007-2014",content);
			content = githelper.GetContent("LICENSE", "fd4f64e");
			StringAssert.StartsWith("Copyright 2007-2012", content);
		}
Esempio n. 19
0
		public void InvalidCommitMessage(){
			var gh = new GitHelper{DirectoryName = @"C:\z3projects\assoi\comdiv\work\local"}.Connect();
			var inf = gh.GetCommitInfo();
			Assert.AreEqual("Привет!",inf.Comment);
		}
Esempio n. 20
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);
		}
Esempio n. 21
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);
		}
Esempio n. 22
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"));
		}
Esempio n. 23
0
 public void StaticGetCommit() {
     var dir = FileSystemHelper.ResetTemporaryDirectory();
     Directory.CreateDirectory(Path.Combine(dir, "a"));
     var file = Path.Combine(dir, "a", "x");
     File.WriteAllText(file,"zzz");
     Assert.Null(GitHelper.GetCommit(file));
     var gh = new GitHelper {DirectoryName = dir};
     gh.Init();
     var hash = gh.CommitAllChanges();
     Assert.AreEqual(hash, GitHelper.GetCommit(file).Hash);
 }
Esempio n. 24
0
	    private void PrepareGitRepository(){
			this._githelper = new GitHelper{RemoteUrl = _context.GitUrl, DirectoryName = _context.RootDirectory, Branch = _context.GitBranch,NoAutoPush = true}.Connect();
			try{
				_githelper.FixBranchState();
			}
			catch{
				
			}

		}