本文整理汇总了C#中Repository.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Reset方法的具体用法?C# Repository.Reset怎么用?C# Repository.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repository
的用法示例。
在下文中一共展示了Repository.Reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResettingWithBadParamsThrows
public void ResettingWithBadParamsThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetOptions.Soft, null));
Assert.Throws<ArgumentException>(() => repo.Reset(ResetOptions.Soft, ""));
Assert.Throws<LibGit2Exception>(() => repo.Reset(ResetOptions.Soft, Constants.UnknownSha));
}
}
示例2: ResettingWithBadParamsThrows
public void ResettingWithBadParamsThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetMode.Soft, (string)null));
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetMode.Soft, (Commit)null));
Assert.Throws<ArgumentException>(() => repo.Reset(ResetMode.Soft, ""));
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetMode.Soft, Constants.UnknownSha));
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetMode.Soft, repo.Head.Tip.Tree.Sha));
}
}
示例3: ResettingWithBadParamsThrows
public void ResettingWithBadParamsThrows()
{
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetMode.Soft, (string)null));
Assert.Throws<ArgumentNullException>(() => repo.Reset(ResetMode.Soft, (Commit)null));
Assert.Throws<ArgumentException>(() => repo.Reset(ResetMode.Soft, ""));
Assert.Throws<NotFoundException>(() => repo.Reset(ResetMode.Soft, Constants.UnknownSha));
Assert.Throws<InvalidSpecificationException>(() => repo.Reset(ResetMode.Soft, repo.Head.Tip.Tree.Sha));
}
}
示例4: MixedResetRefreshesTheIndex
public void MixedResetRefreshesTheIndex()
{
string repoPath = InitNewRepository();
using (var repo = new Repository(repoPath, new RepositoryOptions { Identity = Constants.Identity }))
{
FeedTheRepository(repo);
var oldHeadId = repo.Head.Tip.Id;
Tag tag = repo.Tags["mytag"];
var before = DateTimeOffset.Now.TruncateMilliseconds();
repo.Reset(ResetMode.Mixed, tag.CanonicalName);
Assert.Equal(FileStatus.ModifiedInWorkdir, repo.RetrieveStatus("a.txt"));
AssertRefLogEntry(repo, "HEAD",
string.Format("reset: moving to {0}", tag.Target.Sha),
oldHeadId,
tag.Target.Id,
Constants.Identity, before);
AssertRefLogEntry(repo, "refs/heads/mybranch",
string.Format("reset: moving to {0}", tag.Target.Sha),
oldHeadId,
tag.Target.Id,
Constants.Identity, before);
}
}
示例5: HardResetUpdatesTheContentOfTheWorkingDirectory
public void HardResetUpdatesTheContentOfTheWorkingDirectory()
{
bool progressCalled = false;
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
var names = new DirectoryInfo(repo.Info.WorkingDirectory).GetFileSystemInfos().Select(fsi => fsi.Name).ToList();
File.Delete(Path.Combine(repo.Info.WorkingDirectory, "README"));
Touch(repo.Info.WorkingDirectory, "WillNotBeRemoved.txt", "content\n");
Assert.True(names.Count > 4);
var commit = repo.Lookup<Commit>("HEAD~3");
repo.Reset(ResetMode.Hard, commit, new CheckoutOptions()
{
OnCheckoutProgress = (_path, _completed, _total) => { progressCalled = true; },
});
names = new DirectoryInfo(repo.Info.WorkingDirectory).GetFileSystemInfos().Select(fsi => fsi.Name).ToList();
names.Sort(StringComparer.Ordinal);
Assert.Equal(true, progressCalled);
Assert.Equal(new[] { ".git", "README", "WillNotBeRemoved.txt", "branch_file.txt", "new.txt", "new_untracked_file.txt" }, names);
}
}
示例6: MixedResetRefreshesTheIndex
public void MixedResetRefreshesTheIndex()
{
string repoPath = InitNewRepository();
using (var repo = new Repository(repoPath))
{
FeedTheRepository(repo);
var oldHeadId = repo.Head.Tip.Id;
Tag tag = repo.Tags["mytag"];
repo.Reset(ResetMode.Mixed, tag.CanonicalName);
Assert.Equal(FileStatus.Modified, repo.RetrieveStatus("a.txt"));
AssertRefLogEntry(repo, "HEAD",
tag.Target.Id,
string.Format("reset: moving to {0}", tag.Target.Sha),
oldHeadId);
AssertRefLogEntry(repo, "refs/heads/mybranch",
tag.Target.Id,
string.Format("reset: moving to {0}", tag.Target.Sha),
oldHeadId);
}
}
示例7: MixedResetInABareRepositoryThrows
public void MixedResetInABareRepositoryThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<BareRepositoryException>(() => repo.Reset(ResetOptions.Mixed));
}
}
示例8: ResettingInABareRepositoryThrows
public void ResettingInABareRepositoryThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<BareRepositoryException>(() => repo.Reset());
}
}
示例9: CanAmendACommitWithMoreThanOneParent
public void CanAmendACommitWithMoreThanOneParent()
{
string path = CloneStandardTestRepo();
using (var repo = new Repository(path))
{
var mergedCommit = repo.Lookup<Commit>("be3563a");
Assert.NotNull(mergedCommit);
Assert.Equal(2, mergedCommit.Parents.Count());
repo.Reset(ResetOptions.Soft, mergedCommit.Sha);
CreateAndStageANewFile(repo);
const string commitMessage = "I'm rewriting the history!";
Commit amendedCommit = repo.Commit(commitMessage, DummySignature, DummySignature, true);
AssertCommitHasBeenAmended(repo, amendedCommit, mergedCommit);
// Assert a reflog entry is created
var reflogEntry = repo.Refs.Log("HEAD").First();
Assert.Equal(amendedCommit.Committer, reflogEntry.Commiter);
Assert.Equal(amendedCommit.Id, reflogEntry.To);
Assert.Equal(string.Format("commit (amend): {0}", commitMessage), reflogEntry.Message);
}
}
示例10: MixedResetInABareRepositoryThrows
public void MixedResetInABareRepositoryThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<LibGit2Exception>(() => repo.Reset(ResetOptions.Mixed, repo.Head.Tip.Sha));
}
}
示例11: CanAmendACommitWithMoreThanOneParent
public void CanAmendACommitWithMoreThanOneParent()
{
string path = CloneStandardTestRepo();
using (var repo = new Repository(path))
{
var mergedCommit = repo.Lookup<Commit>("be3563a");
Assert.NotNull(mergedCommit);
Assert.Equal(2, mergedCommit.Parents.Count());
repo.Reset(ResetMode.Soft, mergedCommit.Sha);
CreateAndStageANewFile(repo);
const string commitMessage = "I'm rewriting the history!";
Commit amendedCommit = repo.Commit(commitMessage, Constants.Signature, Constants.Signature,
new CommitOptions { AmendPreviousCommit = true });
AssertCommitHasBeenAmended(repo, amendedCommit, mergedCommit);
AssertRefLogEntry(repo, "HEAD",
amendedCommit.Id,
string.Format("commit (amend): {0}", commitMessage),
mergedCommit.Id,
amendedCommit.Committer);
}
}
示例12: ResettingInABareRepositoryThrows
public void ResettingInABareRepositoryThrows()
{
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Assert.Throws<BareRepositoryException>(() => repo.Reset());
}
}
示例13: ResetANewlyInitializedRepositoryThrows
public void ResetANewlyInitializedRepositoryThrows(bool isBare)
{
string repoPath = InitNewRepository(isBare);
using (var repo = new Repository(repoPath))
{
Assert.Throws<UnbornBranchException>(() => repo.Reset(ResetMode.Soft));
}
}
示例14: ResetANewlyInitializedRepositoryThrows
public void ResetANewlyInitializedRepositoryThrows(bool isBare)
{
string repoPath = InitNewRepository(isBare);
using (var repo = new Repository(repoPath))
{
Assert.Throws<LibGit2SharpException>(() => repo.Reset(ResetOptions.Soft));
}
}
示例15: ResetANewlyInitializedNonBareRepositoryThrows
public void ResetANewlyInitializedNonBareRepositoryThrows()
{
string repoPath = InitNewRepository(false);
using (var repo = new Repository(repoPath))
{
Assert.Throws<UnbornBranchException>(() => repo.Reset());
}
}