示例#1
0
文件: Git.cs 项目: ststeiger/NancyHub
        } // End Function HasChanges

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

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

            // You can also access other collections related to the status
            System.Collections.Generic.ICollection <string> added   = status.GetAdded();
            System.Collections.Generic.ICollection <string> changed = status.GetChanged();
            System.Collections.Generic.ICollection <string> removed = status.GetRemoved();


            // Clean our working copy
            System.Collections.Generic.ICollection <string> clean = repository.Clean().Call();

            // Add all files to the stage (you could also be more specific)
            NGit.Dircache.DirCache add = repository.Add()
                                         .AddFilepattern(".")
                                         .Call();

            // Remove files from the stage
            NGit.Dircache.DirCache remove = repository.Rm()
                                            .AddFilepattern(".gitignore")
                                            .Call();

            CloseRepository(repository);
        } // End Sub UnleashHeavok
        public override string Commit(string filePath, string changedContent, string commitComment)
        {
            using (var file = File.OpenWrite(Path.Combine(ClonedRepoFolder, filePath)))
            {
                var changes = new UTF8Encoding(true).GetBytes(changedContent);
                file.Write(changes, 0, changes.Length);
            }

            _git.Add().AddFilepattern(filePath).Call();
            var commit = _git.Commit().SetMessage(commitComment).SetAuthor(Login, "*****@*****.**").Call();

            _git.Push().Call();

            BatchingProgressMonitor.ShutdownNow();

            return(commit.Id.Name);
        }
示例#3
0
        public void CopyFileToCache(string file)
        {
            try
            {
                var newPath = PrepareDocumentCache(file, ContextRepository);
                System.IO.File.Copy(file, newPath, true);
                //m_git.Add().AddFilepattern(tuple.Item1).Call();
                //m_git.Add().AddFilepattern(".").Call();

                var command = m_git.Add();
                var filter  = GetGitFriendlyName(file);

                command.AddFilepattern(filter).Call();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
示例#4
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