コード例 #1
0
        private static Commit AddCommitToRepo(IRepository repo)
        {
            string relativeFilepath = "test.txt";

            Touch(repo.Info.WorkingDirectory, relativeFilepath, content);
            repo.Stage(relativeFilepath);

            var ie = repo.Index[relativeFilepath];

            Assert.NotNull(ie);
            Assert.Equal("9daeafb9864cf43055ae93beb0afd6c7d144bfa4", ie.Id.Sha);

            var author = new Signature("nulltoken", "*****@*****.**", DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100"));
            var commit = repo.Commit("Initial commit", author, author);

            relativeFilepath = "big.txt";
            var zeros = new string('0', 32 * 1024 + 3);

            Touch(repo.Info.WorkingDirectory, relativeFilepath, zeros);
            repo.Stage(relativeFilepath);

            ie = repo.Index[relativeFilepath];
            Assert.NotNull(ie);
            Assert.Equal("6518215c4274845a759cb498998fe696c42e3e0f", ie.Id.Sha);

            return(commit);
        }
コード例 #2
0
 public void Stage(string filePath)
 {
     try
     {
         _repo.Stage(filePath);
     }
     catch (LibGit2SharpException ex)
     {
         throw  new GitException("Failed to stage file.", ex);
     }
 }
コード例 #3
0
        private static void SetUpSimpleDiffContext(IRepository repo)
        {
            var fullpath = Touch(repo.Info.WorkingDirectory, "file.txt", "hello\n");

            repo.Stage(fullpath);
            repo.Commit("Initial commit", Constants.Signature, Constants.Signature);

            File.AppendAllText(fullpath, "world\n");

            repo.Stage(fullpath);

            File.AppendAllText(fullpath, "!!!\n");
        }
コード例 #4
0
        private static void SetUpSimpleDiffContext(IRepository repo)
        {
            var fullpath = Touch(repo.Info.WorkingDirectory, "file.txt", "hello\n");

            repo.Stage(fullpath);
            repo.Commit("Initial commit", Constants.Signature, Constants.Signature);

            File.AppendAllText(fullpath, "world\n");

            repo.Stage(fullpath);

            File.AppendAllText(fullpath, "!!!\n");
        }
コード例 #5
0
        /// <summary>
        /// Helper method to populate a simple repository with
        /// a single file and two branches.
        /// </summary>
        /// <param name="repo">Repository to populate</param>
        private void PopulateBasicRepository(IRepository repo)
        {
            // Generate a .gitignore file.
            string gitIgnoreFilePath = Touch(repo.Info.WorkingDirectory, ".gitignore", "bin");

            repo.Stage(gitIgnoreFilePath);

            string fullPathFileA = Touch(repo.Info.WorkingDirectory, originalFilePath, originalFileContent);

            repo.Stage(fullPathFileA);

            repo.Commit("Initial commit", Constants.Signature, Constants.Signature);

            repo.CreateBranch(otherBranchName);
        }
コード例 #6
0
        private static void CreateAndStageANewFile(IRepository repo)
        {
            string relativeFilepath = string.Format("new-file-{0}.txt", Path.GetRandomFileName());

            Touch(repo.Info.WorkingDirectory, relativeFilepath, "brand new content\n");
            repo.Stage(relativeFilepath);
        }
コード例 #7
0
        private static void AssertNormalization(IRepository repo, string filename, bool shouldHaveBeenNormalized, string expectedSha)
        {
            var sb = new StringBuilder();

            sb.Append("I'm going to be dynamically processed\r\n");
            sb.Append("And my line endings...\r\n");
            sb.Append("...are going to be\n");
            sb.Append("normalized!\r\n");

            Touch(repo.Info.WorkingDirectory, filename, sb.ToString());

            repo.Stage(filename);

            IndexEntry entry = repo.Index[filename];

            Assert.NotNull(entry);

            Assert.Equal(expectedSha, entry.Id.Sha);

            var blob = repo.Lookup <Blob>(entry.Id);

            Assert.NotNull(blob);

            Assert.Equal(!shouldHaveBeenNormalized, blob.GetContentText().Contains("\r"));
        }
コード例 #8
0
        private Commit AddFileCommitToRepo(IRepository repository, string filename, string content = null)
        {
            Touch(repository.Info.WorkingDirectory, filename, content);

            repository.Stage(filename);

            return(repository.Commit("New commit", Constants.Signature, Constants.Signature));
        }
コード例 #9
0
        private static FileInfo StageNewFile(IRepository repo, string contents = "null")
        {
            string newFilePath  = Touch(repo.Info.WorkingDirectory, Guid.NewGuid() + ".txt", contents);
            var    stageNewFile = new FileInfo(newFilePath);

            repo.Stage(newFilePath);
            return(stageNewFile);
        }
コード例 #10
0
        public void AddFile(string path, string contents)
        {
            var signature = new Signature("user", "user@user", DateTimeOffset.Now);

            File.WriteAllText(Path.Combine(repository.Info.WorkingDirectory, path), contents);
            repository.Stage(path);
            repository.Commit("Added " + path, signature, signature);

            var tip = repository.Head.Tip.Sha;
        }
コード例 #11
0
        private Commit AddCommitToRepo(IRepository repository)
        {
            string random   = Guid.NewGuid().ToString();
            string filename = random + ".txt";

            Touch(repository.Info.WorkingDirectory, filename, random);

            repository.Stage(filename);

            return(repository.Commit("New commit", Constants.Signature, Constants.Signature));
        }
コード例 #12
0
        private static void FeedTheRepository(IRepository repo)
        {
            string fullPath = Touch(repo.Info.WorkingDirectory, "a.txt", "Hello\n");

            repo.Stage(fullPath);
            repo.Commit("Initial commit", Constants.Signature, Constants.Signature);
            repo.ApplyTag("mytag");

            File.AppendAllText(fullPath, "World\n");
            repo.Stage(fullPath);

            Signature shiftedSignature = Constants.Signature.TimeShift(TimeSpan.FromMinutes(1));

            repo.Commit("Update file", shiftedSignature, shiftedSignature);
            repo.CreateBranch("mybranch");

            repo.Checkout("mybranch");

            Assert.False(repo.RetrieveStatus().IsDirty);
        }
コード例 #13
0
        public string AddFile(string path, string contents)
        {
            var signature = new Signature("user", "user@user", DateTimeOffset.Now);
            var fullPath  = Path.Combine(repository.Info.WorkingDirectory, path);
            var directory = Path.GetDirectoryName(fullPath);

            Directory.CreateDirectory(directory);
            File.WriteAllText(fullPath, contents);
            repository.Stage(path);
            repository.Commit("Added " + path, signature, signature);
            return(repository.Head.Tip.Sha);
        }
コード例 #14
0
 private static void AssertStage(bool?ignorecase, IRepository repo, string path)
 {
     try
     {
         repo.Stage(path);
         Assert.Equal(FileStatus.Added, repo.RetrieveStatus(path));
         repo.Reset();
         Assert.Equal(FileStatus.Untracked, repo.RetrieveStatus(path));
     }
     catch (ArgumentException)
     {
         Assert.False(ignorecase ?? true);
     }
 }
コード例 #15
0
 private static void AssertStage(bool?ignorecase, IRepository repo, string path)
 {
     try
     {
         repo.Stage(path);
         Assert.Equal(FileStatus.NewInIndex, repo.RetrieveStatus(path));
         repo.Index.Replace(repo.Head.Tip);
         Assert.Equal(FileStatus.NewInWorkdir, repo.RetrieveStatus(path));
     }
     catch (ArgumentException)
     {
         Assert.False(ignorecase ?? true);
     }
 }
コード例 #16
0
        private static Commit AddCommitToRepo(IRepository repo)
        {
            string relativeFilepath = "test.txt";
            Touch(repo.Info.WorkingDirectory, relativeFilepath, content);
            repo.Stage(relativeFilepath);

            var ie = repo.Index[relativeFilepath];
            Assert.NotNull(ie);
            Assert.Equal("9daeafb9864cf43055ae93beb0afd6c7d144bfa4", ie.Id.Sha);

            var author = new Signature("nulltoken", "*****@*****.**", DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100"));
            var commit = repo.Commit("Initial commit", author, author);

            relativeFilepath = "big.txt";
            var zeros = new string('0', 32*1024 + 3);
            Touch(repo.Info.WorkingDirectory, relativeFilepath, zeros);
            repo.Stage(relativeFilepath);

            ie = repo.Index[relativeFilepath];
            Assert.NotNull(ie);
            Assert.Equal("6518215c4274845a759cb498998fe696c42e3e0f", ie.Id.Sha);

            return commit;
        }
コード例 #17
0
        internal static Commit AddCommitToRepo(IRepository repository, Signature author = null)
        {
            if (author == null)
            {
                author = new Signature("Test", "*****@*****.**", DateTime.Now);
            }

            string random   = Path.GetRandomFileName();
            string filename = random + ".txt";

            Touch(repository.Info.WorkingDirectory, filename, random);

            repository.Stage(filename);

            return(repository.Commit("New commit", author, author));
        }
コード例 #18
0
    public static Commit CreateFileAndCommit(this IRepository repository, string relativeFileName)
    {
        var randomFile = Path.Combine(repository.Info.WorkingDirectory, relativeFileName);

        if (File.Exists(randomFile))
        {
            File.Delete(randomFile);
        }

        var totalWidth = 36 + (pad++ % 10);
        var contents   = Guid.NewGuid().ToString().PadRight(totalWidth, '.');

        File.WriteAllText(randomFile, contents);

        repository.Stage(randomFile);

        return(repository.Commit(string.Format("Test Commit for file '{0}'", relativeFileName),
                                 Constants.SignatureNow(), Constants.SignatureNow()));
    }
コード例 #19
0
        private static void AssertNormalization(IRepository repo, string filename, bool shouldHaveBeenNormalized, string expectedSha)
        {
            var sb = new StringBuilder();
            sb.Append("I'm going to be dynamically processed\r\n");
            sb.Append("And my line endings...\r\n");
            sb.Append("...are going to be\n");
            sb.Append("normalized!\r\n");

            Touch(repo.Info.WorkingDirectory, filename, sb.ToString());

            repo.Stage(filename);

            IndexEntry entry = repo.Index[filename];
            Assert.NotNull(entry);

            Assert.Equal(expectedSha, entry.Id.Sha);

            var blob = repo.Lookup<Blob>(entry.Id);
            Assert.NotNull(blob);

            Assert.Equal(!shouldHaveBeenNormalized, blob.GetContentText().Contains("\r"));
        }
コード例 #20
0
ファイル: CommitCommand.cs プロジェクト: gitter-badger/guit
        void Commit(IRepository repository, IEnumerable <StatusEntry> entries, string title = "Commit", bool reportProgress = false)
        {
            if (entries.Any() || Amend)
            {
                var dialog = new CommitDialog(title);

                if (Amend)
                {
                    dialog.Message = repository.Commits.FirstOrDefault()?.Message;
                }

                if (mainThread.Invoke(() => dialog.ShowDialog()) == true)
                {
                    if (!string.IsNullOrEmpty(dialog.NewBranchName))
                    {
                        repository.Checkout(repository.CreateBranch(dialog.NewBranchName));
                    }

                    foreach (var entry in entries)
                    {
                        repository.Stage(entry.FilePath);
                    }

                    var signature = repository.Config.BuildSignature(DateTimeOffset.Now);

                    var options = new CommitOptions
                    {
                        AmendPreviousCommit = Amend
                    };

                    eventStream.Push <Status>(0.5f);

                    repository.Commit(dialog.Message, signature, signature, options);
                }
            }
        }
コード例 #21
0
 private static void CreateAndStageANewFile(IRepository repo)
 {
     string relativeFilepath = string.Format("new-file-{0}.txt", Guid.NewGuid());
     Touch(repo.Info.WorkingDirectory, relativeFilepath, "brand new content\n");
     repo.Stage(relativeFilepath);
 }
コード例 #22
0
 public static Commit CommitFile(IRepository repo, string filePath, string comment)
 {
     repo.Stage(filePath);
     return(repo.Commit(comment, SignatureNow(), SignatureNow()));
 }
コード例 #23
0
        /// <summary>
        /// Helper method to populate a simple repository with
        /// a single file and two branches.
        /// </summary>
        /// <param name="repo">Repository to populate</param>
        private void PopulateBasicRepository(IRepository repo)
        {
            // Generate a .gitignore file.
            string gitIgnoreFilePath = Touch(repo.Info.WorkingDirectory, ".gitignore", "bin");
            repo.Stage(gitIgnoreFilePath);

            string fullPathFileA = Touch(repo.Info.WorkingDirectory, originalFilePath, originalFileContent);
            repo.Stage(fullPathFileA);

            repo.Commit("Initial commit", Constants.Signature, Constants.Signature);

            repo.CreateBranch(otherBranchName);
        }
コード例 #24
0
 public static Commit CommitFile(IRepository repo, string filePath, string comment)
 {
     repo.Stage(filePath);
     return repo.Commit(comment, SignatureNow(), SignatureNow());
 }
コード例 #25
0
 private static void AssertStage(bool? ignorecase, IRepository repo, string path)
 {
     try
     {
         repo.Stage(path);
         Assert.Equal(FileStatus.Added, repo.RetrieveStatus(path));
         repo.Reset();
         Assert.Equal(FileStatus.Untracked, repo.RetrieveStatus(path));
     }
     catch (ArgumentException)
     {
         Assert.False(ignorecase ?? true);
     }
 }
コード例 #26
0
ファイル: PushFixture.cs プロジェクト: beulah444/libgit2sharp
        private Commit AddCommitToRepo(IRepository repository)
        {

            string random = Path.GetRandomFileName();
            string filename = random + ".txt";

            Touch(repository.Info.WorkingDirectory, filename, random);

            repository.Stage(filename);

            return repository.Commit("New commit", Constants.Signature, Constants.Signature);
        }
コード例 #27
0
        private static void FeedTheRepository(IRepository repo)
        {
            string fullPath = Touch(repo.Info.WorkingDirectory, "a.txt", "Hello\n");
            repo.Stage(fullPath);
            repo.Commit("Initial commit", Constants.Signature, Constants.Signature);
            repo.ApplyTag("mytag");

            File.AppendAllText(fullPath, "World\n");
            repo.Stage(fullPath);

            Signature shiftedSignature = Constants.Signature.TimeShift(TimeSpan.FromMinutes(1));
            repo.Commit("Update file", shiftedSignature, shiftedSignature);
            repo.CreateBranch("mybranch");

            repo.Checkout("mybranch");

            Assert.False(repo.RetrieveStatus().IsDirty);
        }
コード例 #28
0
        private Commit AddFileCommitToRepo(IRepository repository, string filename, string content = null)
        {
            Touch(repository.Info.WorkingDirectory, filename, content);

            repository.Stage(filename);

            return repository.Commit("New commit", Constants.Signature, Constants.Signature);
        }
コード例 #29
0
 /// <summary>
 /// Promotes to the staging area the latest modifications of a file in the working directory (addition, updation or removal).
 /// </summary>
 /// <param name="repository">The <see cref="IRepository"/> being worked with.</param>
 /// <param name="path">The path of the file within the working directory.</param>
 public static void Stage(this IRepository repository, string path)
 {
     repository.Stage(path, null);
 }
コード例 #30
0
 /// <summary>
 /// Promotes to the staging area the latest modifications of a collection of files in the working directory (addition, updation or removal).
 /// </summary>
 /// <param name="repository">The <see cref="IRepository"/> being worked with.</param>
 /// <param name="paths">The collection of paths of the files within the working directory.</param>
 public static void Stage(this IRepository repository, IEnumerable <string> paths)
 {
     repository.Stage(paths, null);
 }