当前位置: 首页>>代码示例>>C#>>正文


C# Repository.Commit方法代码示例

本文整理汇总了C#中LibGit2Sharp.Repository.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Commit方法的具体用法?C# Repository.Commit怎么用?C# Repository.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LibGit2Sharp.Repository的用法示例。


在下文中一共展示了Repository.Commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateHomePageContent

 private static void UpdateHomePageContent(Repository repo, string homePath, Signature sig)
 {
     File.AppendAllText(homePath, "\nThis will be a bare bone user experience.\n");
     repo.Index.Stage(homePath);
     repo.Commit(sig, sig,
                 "Add warning to the Home page\n\nA very informational explicit message preventing the user from expecting too much.");
 }
开发者ID:nulltoken,项目名称:Witinyki,代码行数:7,代码来源:WikiRepoHelper.cs

示例2: SaveFile

        public void SaveFile(string fileName, string content, string username, string email)
        {
            using (var repo = new Repository(_basePath))
            {
                File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, fileName), content);

                // stage the file
                repo.Stage(fileName);

                // Create the committer's signature and commit
                //var user = repo.Config.Get<string>("user", "name", null);
                //var email = repo.Config.Get<string>("user", "email", null);

                var author = new Signature(username, email, DateTime.Now);
                var committer = author;

                // Commit to the repo
                var commitMessage = string.Format("Revision: {0}", GetRevisionCount(repo, fileName));
                try
                {
                    var commit = repo.Commit(commitMessage, author, committer);
                    foreach (var parent in commit.Parents)
                    {
                        Console.WriteLine("Id: {0}, Sha: {1}", parent.Id, parent.Sha);
                    }
                }
                catch (EmptyCommitException) { } // I don't care if the user didn't change anything at this time
            }
        }
开发者ID:kenwilcox,项目名称:PlayingWithLibGit2,代码行数:29,代码来源:FileSaver.cs

示例3: RenameMyWishListPage

 private static void RenameMyWishListPage(Repository repo, string myWishListPath, Signature sig)
 {
     repo.Index.Unstage(myWishListPath);
     File.Move(myWishListPath, myWishListPath + "List");
     repo.Index.Stage(myWishListPath + "List");
     repo.Commit(sig, sig, "Fix MyWishList page name");
 }
开发者ID:nulltoken,项目名称:Witinyki,代码行数:7,代码来源:WikiRepoHelper.cs

示例4: Commit

 /// <summary>
 ///     Commit changes to local repo. Use Github.Add first.
 ///     TODO: Possibly add ability for users to specify msg?
 /// </summary>
 public void Commit()
 {
     using (var repo = new Repository(_LocalRepo))
     {
         repo.Commit("Update via Chuck interface.");
     }
 }
开发者ID:ryanrousseau,项目名称:chuck,代码行数:11,代码来源:Github.cs

示例5: btnCommit_Click

        private void btnCommit_Click(object sender, RibbonControlEventArgs e)
        {
            //Get Active  Project
            var pj = Globals.ThisAddIn.Application.ActiveProject;

            //Get Project Filename.
            var projectFile = pj.FullName;

            //Get Directory from File Name
            var directory = Path.GetDirectoryName(projectFile);

            //Create a new Git Repository
            Repository.Init(directory);

            //Open the git repository in a using context so its automatically disposed of.
            using (var repo = new Repository(directory))
            {
                // Stage the file
                repo.Index.Stage(projectFile);

                // Create the committer's signature and commit
                var author = new Signature("Richard", "@ARM", DateTime.Now);
                var committer = author;

                // Commit to the repository
                var commit = repo.Commit("Initial commit", author, committer);
            }
        }
开发者ID:rcookerly,项目名称:ProjectVersionControl,代码行数:28,代码来源:GitRibbon.cs

示例6: CommitChanges

 public static void CommitChanges(string Message, string RepoPath)
 {
     using (var repo = new Repository(RepoPath))
     {
         logger.Debug("Git commit to " + RepoPath);
         Signature sig = new Signature("SantiagoDevelopment", "[email protected]", DateTimeOffset.Now );
         repo.Commit(Message, sig, sig);
     }
 }
开发者ID:jamessantiago,项目名称:jamescms,代码行数:9,代码来源:GitHelper.cs

示例7: Commit

        public string Commit()
        {
            if( string.IsNullOrEmpty( RepoPath ) )
                throw new ArgumentException("Must open first");

            using( Repository repo = new Repository(RepoPath) )
            {
                var author = new Signature(UserName, "nulltoken", DateTimeOffset.Now);
                var commit = repo.Commit("Ganji commit\n", author, author);
                return commit.Id.Sha;
            }
        }
开发者ID:chrisparnin,项目名称:ganji,代码行数:12,代码来源:GitProviderLibGit2Sharp.cs

示例8: AddModifiedFilesToVersioning

        public void AddModifiedFilesToVersioning(string commitMessage)
        {
            Repository.Init(repositoryPath, false);

            using (var repository = new Repository(repositoryPath))
            {

                var filesToAddToCommit = FilesToCommit(repository);

                if (!filesToAddToCommit.Any())
                {
                    return;
                }

                repository.Index.Stage(filesToAddToCommit);
                repository.Commit(commitMessage);
            }
        }
开发者ID:orjan,项目名称:DbStory,代码行数:18,代码来源:GitVersioning.cs

示例9: Commit

        public static void Commit(FileInfo file)
        {
            using (var repository = new LibGit2Sharp.Repository(file.DirectoryName))
            {
                try
                {
                    var status = repository.RetrieveStatus(file.FullName);

                    switch (status)
                    {
                        case FileStatus.Unaltered:
                            Log.Add($"Commit, FileStatus: {status}");
                            return;
                        case FileStatus.Nonexistent:
                        case FileStatus.Added:
                        case FileStatus.Staged:
                        case FileStatus.Removed:
                        case FileStatus.RenamedInIndex:
                        case FileStatus.StagedTypeChange:
                        case FileStatus.Untracked:
                        case FileStatus.Modified:
                        case FileStatus.Missing:
                        case FileStatus.TypeChanged:
                        case FileStatus.RenamedInWorkDir:
                            {
                                var commit = repository.Commit("Update", CommitOptions);
                                Log.Add($"Commit: {commit.Message}");
                                break;
                            }
                        case FileStatus.Unreadable:
                        case FileStatus.Ignored:
                            throw new InvalidOperationException($"FileStatus: {status}");
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }
                catch (Exception e)
                {
                    Log.Add(e.Message);
                }
            }
        }
开发者ID:JohanLarsson,项目名称:LibGit2Box,代码行数:42,代码来源:Git.cs

示例10: InitializeRepository

        /// <summary>
        /// Initializes a new bare repository at the specified location, adds a repository info file to the root directory
        /// and tags the initial commit with he value of <see cref="InitialCommitTagName"/>
        /// </summary>
        public static void InitializeRepository(string location)
        {            
            // initialize a bare repository
            Repository.Init(location, true);

            var directoryCreator = new LocalItemCreator();

            // clone the repository, add initial commit and push the changes back to the actual repository
            using (var tempDirectory = directoryCreator.CreateTemporaryDirectory())
            {
                var clonedRepoPath = Repository.Clone(location, tempDirectory.Directory.Location);

                var repositoryInfoFile = new RepositoryInfoFile(tempDirectory.Directory);

                // add a empty file to the repository
                directoryCreator.CreateFile(repositoryInfoFile, tempDirectory.Directory.Location);

                // commit and push the file to the bare repository we created
                using (var clonedRepo = new Repository(clonedRepoPath))
                {
                    var signature = SignatureHelper.NewSignature();

                    clonedRepo.Stage(repositoryInfoFile.Name);
                    clonedRepo.Commit("Initial Commit", signature, signature, new CommitOptions());                    

                    clonedRepo.Network.Push(clonedRepo.Network.Remotes["origin"], @"refs/heads/master");                    
                }
            }

            //create the configuration branch pointing to the initial commit
            using (var repository = new Repository(location))
            {
                repository.CreateBranch(ConfigurationBranchName.ToString(), repository.GetAllCommits().Single());
                repository.Tags.Add(InitialCommitTagName, repository.GetAllCommits().Single());
            }
        }
开发者ID:ap0llo,项目名称:SyncTool,代码行数:40,代码来源:RepositoryInitHelper.cs

示例11: RenameToolStripMenuItemClick

        /// <summary>
        ///     rename the entry with all the hassle that accompanies it.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RenameToolStripMenuItemClick(object sender, EventArgs e)
        {
            SaveFileDialog newFileDialog = new SaveFileDialog
                                               {
                                                   AddExtension = true,
                                                   AutoUpgradeEnabled = true,
                                                   CreatePrompt = false,
                                                   DefaultExt = "gpg",
                                                   InitialDirectory = Cfg["PassDirectory"],
                                                   Title = Strings.FrmMain_RenameToolStripMenuItemClick_Rename
                                               };
            if (newFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            string tmpFileName = newFileDialog.FileName;
            newFileDialog.Dispose();

            // ReSharper disable once AssignNullToNotNullAttribute
            Directory.CreateDirectory(path: Path.GetDirectoryName(tmpFileName));
            File.Copy(dirTreeView.SelectedNode.Tag + "\\" + listFileView.SelectedItem + ".gpg", tmpFileName);
            using (var repo = new Repository(Cfg["PassDirectory"]))
                {
                    // add the file
                    repo.Remove(listFileView.SelectedItem.ToString());
                    repo.Stage(tmpFileName);
                    // Commit
                    repo.Commit("password moved", new Signature("pass4win", "pass4win", DateTimeOffset.Now),
                        new Signature("pass4win", "pass4win", DateTimeOffset.Now));

                    if (Cfg["UseGitRemote"] == true && this.gitRepoOffline == false)
                    {
                        //push
                        toolStripOffline.Visible = false;
                        var remote = repo.Network.Remotes["origin"];
                        var options = new PushOptions
                        {
                            CredentialsProvider = (url, user, cred) => new UsernamePasswordCredentials
                            {
                                Username = Cfg["GitUser"],
                                Password = DecryptConfig(Cfg["GitPass"], "pass4win")
                            }
                        };
                        var pushRefSpec = @"refs/heads/master";
                        repo.Network.Push(remote, pushRefSpec, options);
                    }
            }
            this.CreateNodes();
        }
开发者ID:bazmecode,项目名称:Pass4Win,代码行数:55,代码来源:Main.cs

示例12: EncryptCallback

 /// <summary>
 ///     Callback for the encrypt thread
 /// </summary>
 /// <param name="result"></param>
 /// <param name="tmpFile"></param>
 /// <param name="tmpFile2"></param>
 /// <param name="path"></param>
 public void EncryptCallback(GpgInterfaceResult result, string tmpFile, string tmpFile2, string path)
 {
     if (result.Status == GpgInterfaceStatus.Success)
     {
         File.Delete(tmpFile);
         File.Delete(path);
         File.Move(tmpFile2, path);
         // add to git
         using (var repo = new Repository(Cfg["PassDirectory"]))
         {
             // Stage the file
             repo.Stage(path);
             // Commit
             repo.Commit("password changes", new Signature("pass4win", "pass4win", DateTimeOffset.Now),
                 new Signature("pass4win", "pass4win", DateTimeOffset.Now));
             if (Cfg["UseGitRemote"] == true && this.gitRepoOffline == false)
             {
                 toolStripOffline.Visible = false;
                 var remote = repo.Network.Remotes["origin"];
                 var options = new PushOptions
                 {
                     CredentialsProvider = (url, user, cred) => new UsernamePasswordCredentials
                     {
                         Username = Cfg["GitUser"],
                         Password = DecryptConfig(Cfg["GitPass"], "pass4win")
                     }
                 };
                 var pushRefSpec = @"refs/heads/master";
                 repo.Network.Push(remote, pushRefSpec, options);
             }
         }
     }
     else
     {
         MessageBox.Show(Strings.Error_weird_shit_happened_encryption, Strings.Error, MessageBoxButtons.OK,
             MessageBoxIcon.Error);
     }
 }
开发者ID:bazmecode,项目名称:Pass4Win,代码行数:45,代码来源:Main.cs

示例13: GetAQuoteViaGit

        public IActionResult GetAQuoteViaGit(QuoteViewModel model)
        {
            var watch = Stopwatch.StartNew();

            string rootedPath = Repository.Init("C:\\temp\\rooted\\path");
            string jsondata = new JavaScriptSerializer().Serialize(model);

            using (var repo = new Repository("C:\\temp\\rooted\\path"))
            {
                // Write content to file system
                System.IO.File.WriteAllText(System.IO.Path.Combine(repo.Info.WorkingDirectory, "output.json"), jsondata);

                // Stage the file
                repo.Stage("output.json");

                // Create the committer's signature and commit
                Signature author = new Signature(model.FirstName, model.Email, DateTime.Now);
                Signature committer = author;

                // Commit to the repository
                try {
                    Commit commit = repo.Commit("Quote committed", author, committer);
                    watch.Stop();
                    var elapsedMs = watch.ElapsedMilliseconds;

                    if (ModelState.IsValid)
                    {
                        ViewBag.Message = "Quote number is: " + commit.Id + " Time taken: " + elapsedMs + "ms";
                    }
                }
                catch(Exception ex)
                {
                    ViewBag.Message = "Nothing to commit";
                }
            }
            return View();
        }
开发者ID:ashwini5891,项目名称:TestForStash,代码行数:37,代码来源:AppController.cs

示例14: renameToolStripMenuItem_Click

        private void renameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // rename the entry
            InputBoxValidation validation = delegate(string val)
            {
                if (val == "")
                    return "Value cannot be empty.";
                if (new Regex(@"[a-zA-Z0-9-\\_]+/g").IsMatch(val))
                    return "Not a valid name, can only use characters or numbers and - \\.";
                if (File.Exists(Properties.Settings.Default.PassDirectory + "\\" + @val + ".gpg"))
                    return "Entry already exists.";
                return "";
            };

            string value = dataPass.Rows[dataPass.CurrentCell.RowIndex].Cells[1].Value.ToString();
            if (InputBox.Show("Enter a new name", "Name:", ref value, validation) == DialogResult.OK)
            {
                // parse path
                string tmpPath = Properties.Settings.Default.PassDirectory + "\\" + @value + ".gpg";
                Directory.CreateDirectory(Path.GetDirectoryName(tmpPath));
                File.Copy(dataPass.Rows[dataPass.CurrentCell.RowIndex].Cells[0].Value.ToString(), tmpPath);
                using (var repo = new Repository(Properties.Settings.Default.PassDirectory))
                {
                    // add the file
                    repo.Remove(dataPass.Rows[dataPass.CurrentCell.RowIndex].Cells[0].Value.ToString());
                    repo.Stage(tmpPath);
                    // Commit
                    repo.Commit("password moved", new Signature("pass4win", "pass4win", System.DateTimeOffset.Now), new Signature("pass4win", "pass4win", System.DateTimeOffset.Now));
                    //push
                    var remote = repo.Network.Remotes["origin"];
                    var options = new PushOptions();
                    options.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials
                    {
                        Username = GitUsername,
                        Password = GitPassword
                    };
                    var pushRefSpec = @"refs/heads/master";
                    repo.Network.Push(remote, pushRefSpec, options, new Signature("pass4win", "[email protected]", DateTimeOffset.Now),
                        "pushed changes");
                }
                ResetDatagrid();

            }
        }
开发者ID:kageurufu,项目名称:Pass4Win,代码行数:44,代码来源:Main.cs

示例15: frmMain


//.........这里部分代码省略.........
                    // creating new Git
                    Repository.Init(Properties.Settings.Default.PassDirectory);
                    Properties.Settings.Default.GitUser = EncryptConfig("RandomGarbage", "pass4win");
                    Properties.Settings.Default.GitPass = EncryptConfig("RandomGarbage", "pass4win");
                }
            }
            else
            {
                // so we have a repository let's load the user/pass
                if (Properties.Settings.Default.GitUser != "")
                {
                    GitUsername = DecryptConfig(Properties.Settings.Default.GitUser, "pass4win");
                    GitPassword = DecryptConfig(Properties.Settings.Default.GitPass, "pass4win");
                }
                else
                {
                    string value = "";
                    if (InputBox.Show("Username", "Remote Username:", ref value) == DialogResult.OK)
                    {
                        GitUsername = value;
                        value = "";
                        if (InputBox.Show("Password", "Remote Password:", ref value) == DialogResult.OK)
                        {
                            GitPassword = value;
                        }
                    }
                    if (GitUsername == null)
                    {
                        MessageBox.Show("We really need a username. Restart the program and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        System.Environment.Exit(1);
                    }
                    if (GitPassword == null)
                    {
                        MessageBox.Show("We really need a password. Restart the program and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        System.Environment.Exit(1);
                    }
                    Properties.Settings.Default.GitUser = EncryptConfig(GitUsername, "pass4win");
                    Properties.Settings.Default.GitPass = EncryptConfig(GitPassword, "pass4win");
                }

                // Check if we have the latest
                using (var repo = new Repository(Properties.Settings.Default.PassDirectory))
                {
                    Signature Signature = new Signature("pass4win","[email protected]", new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
                    FetchOptions fetchOptions = new FetchOptions();
                    fetchOptions.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials
                                        {
                                            Username = GitUsername,
                                            Password = GitPassword
                                        };
                    MergeOptions mergeOptions = new MergeOptions();
                    PullOptions pullOptions = new PullOptions();
                    pullOptions.FetchOptions = fetchOptions;
                    pullOptions.MergeOptions = mergeOptions;
                    MergeResult mergeResult = repo.Network.Pull(Signature, pullOptions);
                }

            }

            // Init GPG if needed
            string gpgfile = Properties.Settings.Default.PassDirectory;
            gpgfile += "\\.gpg-id";
            // Check if we need to init the directory
            if (!File.Exists(gpgfile))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(gpgfile));
                KeySelect newKeySelect = new KeySelect();
                if (newKeySelect.ShowDialog() == DialogResult.OK)
                {
                    using (StreamWriter w = new StreamWriter(gpgfile))
                    {
                        w.Write(newKeySelect.gpgkey);
                    }
                    using (var repo = new Repository(Properties.Settings.Default.PassDirectory))
                    {
                        repo.Stage(gpgfile);
                        repo.Commit("gpgid added", new Signature("pass4win", "pass4win", System.DateTimeOffset.Now), new Signature("pass4win", "pass4win", System.DateTimeOffset.Now));
                    }
                }
                else
                {
                    MessageBox.Show("Need key...... Restart the program and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    System.Environment.Exit(1);
                }
            }
            // Setting the exe location for the GPG Dll
            GpgInterface.ExePath = Properties.Settings.Default.GPGEXE;

            // saving settings
            Properties.Settings.Default.Save();

            // Setting up datagrid
            dt.Columns.Add("colPath", typeof(string));
            dt.Columns.Add("colText", typeof(string));

            ListDirectory(new DirectoryInfo(Properties.Settings.Default.PassDirectory), "");

            dataPass.DataSource = dt.DefaultView;
            dataPass.Columns[0].Visible=false;
        }
开发者ID:kageurufu,项目名称:Pass4Win,代码行数:101,代码来源:Main.cs


注:本文中的LibGit2Sharp.Repository.Commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。