コード例 #1
0
        public void Init(string path)
        {
            NGit.Api.InitCommand init = new NGit.Api.InitCommand();

            System.IO.Directory.CreateDirectory(path);

            System.IO.Directory.CreateDirectory(System.IO.Path.Combine(path, "saves"));
            System.IO.Directory.CreateDirectory(System.IO.Path.Combine(path, "builds"));
            System.IO.Directory.CreateDirectory(System.IO.Path.Combine(path, "days"));
            init.SetDirectory(new Sharpen.FilePath(path));
            m_git = init.Call();
        }
コード例 #2
0
        protected override void OnTestRepositoryDeployed()
        {
            base.OnTestRepositoryDeployed();

            EnsureUserHomePathForSystemUser();

            _git = NGit.Api.Git.CloneRepository()
                   .SetURI(LocalRepositoryPath)
                   .SetDirectory(ClonedRepoFolder).Call();

            BatchingProgressMonitor.ShutdownNow();
        }
コード例 #3
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        public virtual bool IsBare(string path)
        {
            bool retVal = false;

            NGit.Api.Git repository = NGit.Api.Git.Open(path);

            retVal = repository.GetRepository().IsBare;

            CloseRepository(repository);

            return(retVal);
        }
コード例 #4
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        } // End Function IsRepository

        public virtual string GetRepoPath(string path)
        {
            string retVal = null;

            NGit.Api.Git repository = NGit.Api.Git.Open(path);

            retVal = repository.GetRepository().Directory.GetPath();
            // string base = repository.GetRepository ().Directory.GetParent ();
            // System.Console.WriteLine (base);

            CloseRepository(repository);

            return(retVal);
        }
コード例 #5
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        } // End Sub SetGlobalCredentials

        public virtual void FetchWithCredentials(string path, string userName, string password)
        {
            NGit.Api.Git repository = NGit.Api.Git.Open(path);

            NGit.Transport.CredentialsProvider credentials =
                new NGit.Transport.UsernamePasswordCredentialsProvider(userName, password);

            // On a per-command basis
            NGit.Transport.FetchResult fetch = repository.Fetch()
                                               .SetCredentialsProvider(credentials)
                                               .Call();

            CloseRepository(repository);
        } // End Sub FetchWithCredentials
コード例 #6
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        // https://stackoverflow.com/questions/45793800/jgit-read-the-content-of-a-file-at-a-commit-in-a-branch
        private string GetFileContent(string repositoryPath, string path, NGit.Revwalk.RevCommit commit)
        {
            NGit.Api.Git repository = NGit.Api.Git.Open(repositoryPath);

            NGit.Treewalk.TreeWalk treeWalk = NGit.Treewalk.TreeWalk.ForPath(
                repository.GetRepository(), path, commit.Tree);

            NGit.ObjectId blobId = treeWalk.GetObjectId(0);

            NGit.ObjectReader objectReader = repository.GetRepository().NewObjectReader();
            NGit.ObjectLoader objectLoader = objectReader.Open(blobId);

            byte[] bytes = objectLoader.GetBytes();
            return(System.Text.Encoding.UTF8.GetString(bytes));
        }
コード例 #7
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        } // End Sub UnleashHeavokOnBareRepo

        public virtual void CreateBranch(string path, string branchName)
        {
            // Here is a snippet that corresponds to the --set-upstream option to git branch:
            NGit.Api.Git repository = NGit.Api.Git.Open(path);

            NGit.Api.CreateBranchCommand create = repository.BranchCreate();
            create.SetUpstreamMode(NGit.Api.CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM);
            create.SetName(branchName);
            create.SetStartPoint("origin/" + branchName);
            create.SetForce(true);
            // Beware that you also need to have .setForce(true)
            // if the branch already exists locally and you only need to track it remotely.
            create.Call();

            CloseRepository(repository);
        } // End Sub CreateBranch
コード例 #8
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        public virtual void ListCommits(string path)
        {
            NGit.Api.Git repository = NGit.Api.Git.Open(path);

            Sharpen.Iterable <NGit.Revwalk.RevCommit> la = repository.Log().All().Call();

            int count = 0;

            foreach (NGit.Revwalk.RevCommit commit in la)
            {
                System.Console.WriteLine("LogCommit: " + commit);
                count++;
            } // Next commit

            CloseRepository(repository);
        } // End Sub ListCommits
コード例 #9
0
        public void Open(string path)
        {
            var p = new Sharpen.FilePath(path);

            try
            {
                m_git = NGit.Api.Git.Open(p);
            }
            catch (Exception ex)
            {
            }
            if (m_git == null)
            {
                Init(path);
            }
        }
コード例 #10
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        } // End Sub Status

        public virtual bool HasChanges(string path)
        {
            NGit.Api.Git repository = NGit.Api.Git.Open(path);

            // Get the current branch status
            NGit.Api.Status status = repository.Status().Call();


            // The IsClean() method is helpful to check if any changes
            // have been detected in the working copy. I recommend using it,
            // as NGit will happily make a commit with no actual file changes.
            bool isClean = status.IsClean();

            CloseRepository(repository);

            return(isClean);
        } // End Function HasChanges
コード例 #11
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        }     // End Class CustomConfigSessionFactory


        // http://stackoverflow.com/questions/13764435/ngit-making-a-connection-with-a-private-key-file/
        public virtual void CloneWithPrivateKey()
        {
            CustomConfigSessionFactory customConfigSessionFactory = new CustomConfigSessionFactory();

            customConfigSessionFactory.PrivateKey = "properties.PrivateKey"; // Enter own
            customConfigSessionFactory.PublicKey  = "properties.PublicKey";  // Enter own

            NGit.Transport.JschConfigSessionFactory.SetInstance(customConfigSessionFactory);

            NGit.Api.Git git = NGit.Api.Git.CloneRepository()
                               .SetDirectory("properties.OutputPath")
                               .SetURI("properties.SourceUrlPath")
                               .SetBranchesToClone(new System.Collections.ObjectModel.Collection <string>()
            {
                "master"
            })
                               .Call();
        } // End Sub CloneWithPrivateKey
コード例 #12
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        // http://stackoverflow.com/questions/3407575/retrieving-oldest-commit-with-jgit
        public virtual void GetOldestCommit(string path)
        {
            NGit.Revwalk.RevCommit c          = null;
            NGit.Api.Git           repository = NGit.Api.Git.Open(path);


            try
            {
                NGit.Revwalk.RevWalk rw = new NGit.Revwalk.RevWalk(repository.GetRepository());

                NGit.AnyObjectId       headid = repository.GetRepository().Resolve(NGit.Constants.HEAD);
                NGit.Revwalk.RevCommit root   = rw.ParseCommit(headid);

                string msg1 = root.GetFullMessage();


                rw.Sort(NGit.Revwalk.RevSort.REVERSE);

                rw.MarkStart(root);
                c = rw.Next();
                // repository.GetRepository().
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }

            string msg2 = c.GetFullMessage();

            // Get author
            NGit.PersonIdent    authorIdent    = c.GetAuthorIdent();
            System.DateTime     authorDate     = authorIdent.GetWhen();
            System.TimeZoneInfo authorTimeZone = authorIdent.GetTimeZone();

            NGit.PersonIdent committerIdent = c.GetCommitterIdent();
            // http://stackoverflow.com/questions/12608610/how-do-you-get-the-author-date-and-commit-date-from-a-jgit-revcommit

            System.Console.WriteLine(authorIdent);
            System.Console.WriteLine(authorDate);
            System.Console.WriteLine(authorTimeZone);
            System.Console.WriteLine(committerIdent);

            CloseRepository(repository);
        }
コード例 #13
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        } // End Sub UnleashHeavok

        // http://stackoverflow.com/questions/8234373/committing-and-pushing-to-github-using-jgit-bare-repo
        // http://programcreek.com/java-api-examples/index.php?api=org.eclipse.jgit.lib.RepositoryBuilder
        public virtual void UnleashHeavokOnBareRepo()
        {
            NGit.Storage.File.FileRepositoryBuilder builder = new NGit.Storage.File.FileRepositoryBuilder();

            var repository = builder.SetGitDir(new Sharpen.FilePath("path/to/my/repo"))
                             .ReadEnvironment() // scan environment GIT_* variables
                                                //.SetBare() // Create bare repo
                             .FindGitDir()      // scan up the file system tree
                             .Build();

            NGit.Api.Git        git = new NGit.Api.Git(repository);
            NGit.Api.AddCommand add = git.Add();
            try
            {
                add.AddFilepattern("PlayState.as").Call();
            }
            catch (System.Exception)
            { }
        } // End Sub UnleashHeavokOnBareRepo
コード例 #14
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        public virtual System.DateTime GetOldestCommitDate(string path)
        {
            System.DateTime retVal = default(System.DateTime);

            NGit.Revwalk.RevCommit c          = null;
            NGit.Api.Git           repository = NGit.Api.Git.Open(path);


            try
            {
                NGit.Revwalk.RevWalk rw = new NGit.Revwalk.RevWalk(repository.GetRepository());

                NGit.AnyObjectId       headid = repository.GetRepository().Resolve(NGit.Constants.HEAD);
                NGit.Revwalk.RevCommit root   = rw.ParseCommit(headid);

                string msg1 = root.GetFullMessage();


                rw.Sort(NGit.Revwalk.RevSort.REVERSE);

                rw.MarkStart(root);
                c = rw.Next();
                // repository.GetRepository().
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }

            string msg2 = c.GetFullMessage();

            // Get author
            NGit.PersonIdent authorIdent = c.GetAuthorIdent();
            System.DateTime  authorDate  = authorIdent.GetWhen();

            retVal = authorDate.ToUniversalTime();

            CloseRepository(repository);

            return(retVal);
        }
コード例 #15
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        } // End Sub ListTags

        public virtual void ListBranches(string path)
        {
            NGit.Api.Git repository = NGit.Api.Git.Open(path);

            // Local only
            System.Collections.Generic.IList <NGit.Ref> refs = repository.BranchList().Call();

            foreach (NGit.Ref refa in refs)
            {
                //System.out.println("Branch: " + refa + " " + refa.GetName() + " " + ref.GetObjectId().Name);
                System.Console.WriteLine("Branch: " + refa + " " + refa.GetName() + " " + refa.GetObjectId().Name);
            } // Next refa


            System.Collections.Generic.IList <NGit.Ref> refsR = repository.BranchList().SetListMode(NGit.Api.ListBranchCommand.ListMode.ALL).Call();

            foreach (NGit.Ref refa in refsR)
            {
                //System.out.println("Branch: " + refa + " " + refa.GetName() + " " + ref.GetObjectId().Name);
                System.Console.WriteLine("Branch: " + refa + " " + refa.GetName() + " " + refa.GetObjectId().Name);
            } // Next refa

            CloseRepository(repository);
        } // End Sub ListBranches
コード例 #16
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        } // End Sub ListBranches

        // https://stackoverflow.com/questions/40590039/how-to-get-the-file-list-for-a-commit-with-jgit
        // https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/api/GetRevCommitFromObjectId.java
        public virtual void ListFilesIncmt(string path, NGit.Revwalk.RevCommit commit)
        {
            NGit.Api.Git  repository = NGit.Api.Git.Open(path);
            NGit.ObjectId treeId     = commit.Tree.Id;

            NGit.Treewalk.TreeWalk treeWalk = new NGit.Treewalk.TreeWalk(repository.GetRepository());

            treeWalk.Reset(treeId);

            while (treeWalk.Next())
            {
                string filePath = treeWalk.PathString;
                System.Console.WriteLine(filePath);
            }

            NGit.Ref      @ref = repository.GetRepository().GetRef("refs/heads/master");
            NGit.ObjectId head = @ref.GetObjectId();
            using (NGit.Revwalk.RevWalk walk = new NGit.Revwalk.RevWalk(repository.GetRepository()))
            {
                NGit.Revwalk.RevCommit headCommit = walk.ParseCommit(head);
            }

            NGit.ObjectId commitIdFromHash = repository.GetRepository().Resolve("revstr");
        }
コード例 #17
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        } // End Function RemoveAttribute

        // https://code.google.com/p/egit/wiki/JGitTutorialRepository
        // http://www.codeaffine.com/2014/09/22/access-git-repository-with-jgit/
        // Git is lazy. An empty, just initialized repository does not have an object database
        // Therefore the test will return false for an empty repository even though it is a perfectly valid repository.
        // What has proven a better approach so far is to test if the HEAD reference exists:
        // Even an empty repository has a HEAD and getRef() returns only null if there is actually no repository.
        public virtual bool IsRepository(string path)
        {
            // Git git = Git.open( new F‌ile( "/path/to/repo/.git" ) );

            // The method expects a File parameter that denotes the directory in which the repository is located.
            // The directory can either point to the work directory or the git directory.
            // Again, I recommend to use the git directory here.

            try
            {
                NGit.Api.Git repository = NGit.Api.Git.Open(path);
                bool         b          = repository.GetRepository().ObjectDatabase.Exists();
                if (repository.GetRepository().GetRef("HEAD") != null)
                {
                    b = true;
                }

                // string name = repository.GetRepository().GetRef("HEAD").GetName();
                // System.Console.WriteLine(name);

                CloseRepository(repository);

                return(b);
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);

                if (ex is System.TypeInitializationException)
                {
                    throw;
                }
            }

            return(false);
        } // End Function IsRepository
コード例 #18
0
		public GitClient(ISourceControlConnectionSettingsSource settings, IStorage<GitRepositoryFolder> folder)
		{
			_settings = settings;
			_folder = folder;
			_git = GetClient(_settings);
		}
コード例 #19
0
 public GitClient(ISourceControlConnectionSettingsSource settings, IStorage <GitRepositoryFolder> folder)
 {
     _settings = settings;
     _folder   = folder;
     _git      = GetClient(_settings);
 }
コード例 #20
0
		RevCommit[] GetBlameForFile (string revision, string filePath)
		{
			RevCommit[] blame = null;
			string path = PROJECT_ROOT + filePath;
			string key = path + revision;
			blames.TryGetValue(key, out blame);
			
			if (blame == null)
			{
				var git = new NGit.Api.Git (repo);
				var commit = git.GetRepository ().Resolve (revision);
				var result = git.Blame ().SetFilePath (filePath).SetStartCommit (commit).Call ();
				if (result == null)
					return null;

				blame = new RevCommit [result.GetResultContents ().Size ()];
				for (int i = 0; i < result.GetResultContents ().Size (); i ++)
					blame [i] = result.GetSourceCommit (i);
				blames.Add(key, blame);
			}
			
			return blame;
		}
コード例 #21
0
ファイル: App.xaml.cs プロジェクト: wirmachenbunt/tooll
        private void SetupOperatorGitRepository()
        {
            const string NewtonSoftDllFilename = "Newtonsoft.Json.dll";

            if (File.Exists(NewtonSoftDllFilename))
            {
                throw new ShutDownException("Please remove " + NewtonSoftDllFilename + " from Tooll's directory because it will break compilation of Operators.",
                                            "Incorrect Settings");
            }

            var          operatorRepository       = new OperatorGitRepository(MetaManager.OPERATOR_PATH);
            const string operatorRepositoryUrl    = "Git.OperatorRepositoryURL";
            const string operatorRepositoryBranch = "Git.OperatorRepositoryBranch";

            if (ProjectSettings.Contains(operatorRepositoryUrl))
            {
                if (!ProjectSettings.Contains("Git.OperatorRepositoryBranch"))
                {
                    // https://streber.framefield.com/1636#5__operatorrepositoryremoteurl_definiert_aber_gitbranch_undefiniert_oder_fehlerhaft
                    throw new ShutDownException("Your project settings misses a definition for GitBranch.\n\nPlease fix this before restarting Tooll.",
                                                "Incorrect Settings");
                }

                var repositoryUrl = ProjectSettings[operatorRepositoryUrl] as string;
                var branchToUse   = ProjectSettings[operatorRepositoryBranch] as string;
                OperatorRepository            = operatorRepository;
                OperatorRepository.RemotePath = repositoryUrl;
                if (!Directory.Exists(MetaManager.OPERATOR_PATH))
                {
                    ShutdownMode = ShutdownMode.OnExplicitShutdown;

                    // https://streber.framefield.com/1636#1__operatorrepositoryremoteurl_definiert_aber_operators_fehlt
                    // fetch operators from url
                    var progressDialog = new CloneRepositoryProgressDialog(OperatorRepository)
                    {
                        LocalPath  = OperatorRepository.LocalPath,
                        RemotePath = OperatorRepository.RemotePath
                    };
                    progressDialog.ShowDialog();

                    ShutdownMode = ShutdownMode.OnMainWindowClose;
                }
                else if (!operatorRepository.IsValid)
                {
                    // https://streber.framefield.com/1636#2__operatorrepositoryremoteurl_definiert_aber_operators__git_fehlt
                    throw new ShutDownException(String.Format("git-repository is set to '{0}' in project settings, but 'Operators/.git' is missing or broken.\n\nPlease fix this or remove the Operators directory. Tooll will then fetch the Operators from the server.", repositoryUrl),
                                                "Missing Operator");
                }

                if (operatorRepository.LocalRepo.GetBranch() != branchToUse)
                {
                    // https://streber.framefield.com/1636#4__operatorrepositoryremoteurl_existiert_aber_operators__git__gt_branch____projectsettings_gitbranch
                    throw new ShutDownException(String.Format("Error: Your 'Operators/.git' branch '{0}' doesn't match the project settings '{1}'.\n\nPlease fix this before restarting Tooll.", operatorRepository.LocalRepo.GetBranch(), branchToUse),
                                                "Incorrect Settings");
                }

                var developerGit = new NGit.Api.Git(new FileRepository("./.git"));
                if (developerGit.GetRepository().GetAllRefs().Any())
                {
                    // valid developer git repository available, so check if branch of developer git repos matches operators repos branch
                    var developerGitBranch = developerGit.GetRepository().GetBranch();
                    if (developerGitBranch != branchToUse)
                    {
                        throw new ShutDownException(String.Format("Error: You starting Tooll as developer but your 'Operators/.git' branch '{0}' doesn't match the Tooll/.git branch '{1}'.\n\nPlease fix this before restarting Tooll.", branchToUse, developerGitBranch),
                                                    "Incorrect Settings");
                    }
                }

                OperatorRepository.Branch = branchToUse;
            }
            else
            {
                if (!Directory.Exists(MetaManager.OPERATOR_PATH) || !Directory.GetFiles(MetaManager.OPERATOR_PATH, "*.mop").Any())
                {
                    // https://streber.framefield.com/1636#6__operatorsrepositoryremoteurl_nicht_definiert_aber_operators__existiert_nicht
                    throw new ShutDownException("Your Operator directory is missing or empty.\n\nYou can define Git.OperatorsRepositoryURL and Git.OperatorRepositoryBranch in your projects settings to fetch a fresh copy.",
                                                "Incorrect Settings");
                }

                if (operatorRepository.IsValid)
                {
                    // https://streber.framefield.com/1636#3__operatorrepositoryremoteurl_nicht_definiert_aber_operators__git_existiert
                    throw new ShutDownException("Although you didn't specify a git repository in your project settings, the directory 'Operators/.git' exists.\n\nPlease fix this.",
                                                "Incorrect Settings");
                }
            }
        }
コード例 #22
0
ファイル: GitProvider.cs プロジェクト: chrisparnin/ganji
 public void Open(string path)
 {
     var p = new Sharpen.FilePath(path);
     try
     {
         m_git = NGit.Api.Git.Open(p);
     }
     catch (Exception ex)
     {
     }
     if (m_git == null)
     {
         Init(path);
     }
 }
コード例 #23
0
ファイル: GitProvider.cs プロジェクト: chrisparnin/ganji
        public void Init(string path)
        {
            NGit.Api.InitCommand init = new NGit.Api.InitCommand();

            System.IO.Directory.CreateDirectory(path);

            System.IO.Directory.CreateDirectory(System.IO.Path.Combine(path, "saves"));
            System.IO.Directory.CreateDirectory(System.IO.Path.Combine(path, "builds"));
            System.IO.Directory.CreateDirectory(System.IO.Path.Combine(path, "days"));
            init.SetDirectory(new Sharpen.FilePath(path));
            m_git = init.Call();
        }
コード例 #24
0
 public GitClient(ISourceControlConnectionSettingsSource settings)
 {
     _settings = settings;
     _git = GetClient(settings);
 }
コード例 #25
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
 // Creates directory if not exists
 public virtual void Clone(string path, string url)
 {
     NGit.Api.CloneCommand clone      = NGit.Api.Git.CloneRepository().SetDirectory(path).SetURI(url);
     NGit.Api.Git          repository = clone.Call();
     CloseRepository(repository);
 } // End Sub Clone
コード例 #26
0
ファイル: Git.cs プロジェクト: ststeiger/NancyHub
        } // End Function Open

        public virtual bool CloseRepository(NGit.Api.Git repository)
        {
            return(CloseRepository(repository, false));
        } // End Function CloseRepository