本文整理汇总了C#中Repository.Move方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Move方法的具体用法?C# Repository.Move怎么用?C# Repository.Move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repository
的用法示例。
在下文中一共展示了Repository.Move方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanUnstageBothSidesOfARename
public void CanUnstageBothSidesOfARename()
{
using (var repo = new Repository(CloneStandardTestRepo()))
{
repo.Move("branch_file.txt", "renamed_branch_file.txt");
repo.Unstage(new string[] { "branch_file.txt", "renamed_branch_file.txt" });
RepositoryStatus status = repo.RetrieveStatus();
Assert.Equal(FileStatus.Missing, status["branch_file.txt"].State);
Assert.Equal(FileStatus.Untracked, status["renamed_branch_file.txt"].State);
}
}
示例2: CanResetTargetOfARenameInIndex
public void CanResetTargetOfARenameInIndex()
{
using (var repo = new Repository(CloneStandardTestRepo()))
{
repo.Move("branch_file.txt", "renamed_branch_file.txt");
RepositoryStatus oldStatus = repo.RetrieveStatus();
Assert.Equal(1, oldStatus.RenamedInIndex.Count());
Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State);
repo.Reset(repo.Lookup<Commit>("32eab9c"), new string[] { "renamed_branch_file.txt" });
RepositoryStatus newStatus = repo.RetrieveStatus();
Assert.Equal(0, newStatus.RenamedInIndex.Count());
Assert.Equal(FileStatus.Untracked, newStatus["renamed_branch_file.txt"].State);
Assert.Equal(FileStatus.Removed, newStatus["branch_file.txt"].State);
}
}
示例3: CanUnstageSourceOfARename
public void CanUnstageSourceOfARename()
{
using (var repo = new Repository(CloneStandardTestRepo()))
{
repo.Move("branch_file.txt", "renamed_branch_file.txt");
RepositoryStatus oldStatus = repo.RetrieveStatus();
Assert.Equal(1, oldStatus.RenamedInIndex.Count());
Assert.Equal(FileStatus.Nonexistent, oldStatus["branch_file.txt"].State);
Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State);
repo.Unstage(new string[] { "branch_file.txt" });
RepositoryStatus newStatus = repo.RetrieveStatus();
Assert.Equal(0, newStatus.RenamedInIndex.Count());
Assert.Equal(FileStatus.Missing, newStatus["branch_file.txt"].State);
Assert.Equal(FileStatus.Added, newStatus["renamed_branch_file.txt"].State);
}
}
示例4: CanResetTheIndexWhenARenameExists
public void CanResetTheIndexWhenARenameExists()
{
using (var repo = new Repository(CloneStandardTestRepo()))
{
repo.Move("branch_file.txt", "renamed_branch_file.txt");
repo.Reset(repo.Lookup<Commit>("32eab9c"));
RepositoryStatus status = repo.RetrieveStatus();
Assert.Equal(0, status.Where(IsStaged).Count());
}
}
示例5: CanDetectTheExactRenamingExactCopyingOfNonModifiedAndModifiedFilesWhenEnabled
public void CanDetectTheExactRenamingExactCopyingOfNonModifiedAndModifiedFilesWhenEnabled()
{
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
var path = Repository.Init(scd.DirectoryPath);
using (var repo = new Repository(path))
{
const string originalPath = "original.txt";
const string renamedPath = "renamed.txt";
const string originalPath2 = "original2.txt";
const string copiedPath1 = "copied.txt";
const string originalPath3 = "original3.txt";
const string copiedPath2 = "copied2.txt";
Touch(repo.Info.WorkingDirectory, originalPath, "a\nb\nc\nd\n");
Touch(repo.Info.WorkingDirectory, originalPath2, "1\n2\n3\n4\n");
Touch(repo.Info.WorkingDirectory, originalPath3, "5\n6\n7\n8\n");
repo.Stage(originalPath);
repo.Stage(originalPath2);
repo.Stage(originalPath3);
Commit old = repo.Commit("Initial", Constants.Signature, Constants.Signature);
var originalFullPath2 = Path.Combine(repo.Info.WorkingDirectory, originalPath2);
var originalFullPath3 = Path.Combine(repo.Info.WorkingDirectory, originalPath3);
var copiedFullPath1 = Path.Combine(repo.Info.WorkingDirectory, copiedPath1);
var copiedFullPath2 = Path.Combine(repo.Info.WorkingDirectory, copiedPath2);
File.Copy(originalFullPath2, copiedFullPath1);
File.Copy(originalFullPath3, copiedFullPath2);
File.AppendAllText(originalFullPath3, "9\n");
repo.Stage(originalPath3);
repo.Stage(copiedPath1);
repo.Stage(copiedPath2);
repo.Move(originalPath, renamedPath);
Commit @new = repo.Commit("Updated", Constants.Signature, Constants.Signature);
var changes = repo.Diff.Compare<TreeChanges>(old.Tree, @new.Tree,
compareOptions:
new CompareOptions
{
Similarity = SimilarityOptions.CopiesHarder,
});
Assert.Equal(4, changes.Count());
Assert.Equal(1, changes.Modified.Count());
Assert.Equal(1, changes.Renamed.Count());
Assert.Equal(originalPath, changes.Renamed.Single().OldPath);
Assert.Equal(renamedPath, changes.Renamed.Single().Path);
Assert.Equal(2, changes.Copied.Count());
Assert.Equal(originalPath2, changes.Copied.ElementAt(0).OldPath);
Assert.Equal(copiedPath1, changes.Copied.ElementAt(0).Path);
Assert.Equal(originalPath3, changes.Copied.ElementAt(1).OldPath);
Assert.Equal(copiedPath2, changes.Copied.ElementAt(1).Path);
}
}
示例6: CanNotDetectTheExactRenamingFilesWhenNotEnabled
public void CanNotDetectTheExactRenamingFilesWhenNotEnabled()
{
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
var path = Repository.Init(scd.DirectoryPath);
using (var repo = new Repository(path))
{
const string originalPath = "original.txt";
const string renamedPath = "renamed.txt";
Touch(repo.Info.WorkingDirectory, originalPath, "a\nb\nc\nd\n");
repo.Stage(originalPath);
Commit old = repo.Commit("Initial", Constants.Signature, Constants.Signature);
repo.Move(originalPath, renamedPath);
Commit @new = repo.Commit("Updated", Constants.Signature, Constants.Signature);
var changes = repo.Diff.Compare<TreeChanges>(old.Tree, @new.Tree,
compareOptions:
new CompareOptions
{
Similarity = SimilarityOptions.None,
});
Assert.Equal(2, changes.Count());
Assert.Equal(0, changes.Renamed.Count());
}
}
示例7: ExactModeDoesntDetectRenamesWithEdits
public void ExactModeDoesntDetectRenamesWithEdits()
{
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
var path = Repository.Init(scd.DirectoryPath);
using (var repo = new Repository(path))
{
const string originalPath = "original.txt";
const string renamedPath = "renamed.txt";
Touch(repo.Info.WorkingDirectory, originalPath, "a\nb\nc\nd\n");
repo.Stage(originalPath);
Commit old = repo.Commit("Initial", Constants.Signature, Constants.Signature);
repo.Move(originalPath, renamedPath);
File.AppendAllText(Path.Combine(repo.Info.WorkingDirectory, renamedPath), "e\nf\n");
repo.Stage(renamedPath);
Commit @new = repo.Commit("Updated", Constants.Signature, Constants.Signature);
var changes = repo.Diff.Compare<TreeChanges>(old.Tree, @new.Tree,
compareOptions: new CompareOptions
{
Similarity = SimilarityOptions.Exact,
});
Assert.Equal(2, changes.Count());
Assert.Equal(0, changes.Renamed.Count());
Assert.Equal(1, changes.Added.Count());
Assert.Equal(1, changes.Deleted.Count());
}
}
示例8: RenameThresholdsAreObeyed
public void RenameThresholdsAreObeyed()
{
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
var path = Repository.Init(scd.DirectoryPath);
using (var repo = new Repository(path))
{
const string originalPath = "original.txt";
const string renamedPath = "renamed.txt";
// 4 lines
Touch(repo.Info.WorkingDirectory, originalPath, "a\nb\nc\nd\n");
repo.Stage(originalPath);
Commit old = repo.Commit("Initial", Constants.Signature, Constants.Signature);
// 8 lines, 50% are from original file
Touch(repo.Info.WorkingDirectory, originalPath, "a\nb\nc\nd\ne\nf\ng\nh\n");
repo.Stage(originalPath);
repo.Move(originalPath, renamedPath);
Commit @new = repo.Commit("Updated", Constants.Signature, Constants.Signature);
var compareOptions = new CompareOptions
{
Similarity = new SimilarityOptions
{
RenameDetectionMode = RenameDetectionMode.Renames,
},
};
compareOptions.Similarity.RenameThreshold = 30;
var changes = repo.Diff.Compare<TreeChanges>(old.Tree, @new.Tree, compareOptions: compareOptions);
Assert.True(changes.All(x => x.Status == ChangeKind.Renamed));
compareOptions.Similarity.RenameThreshold = 90;
changes = repo.Diff.Compare<TreeChanges>(old.Tree, @new.Tree, compareOptions: compareOptions);
Assert.False(changes.Any(x => x.Status == ChangeKind.Renamed));
}
}
示例9: DetectsTheExactRenamingOfFilesByDefault
public void DetectsTheExactRenamingOfFilesByDefault()
{
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
var path = Repository.Init(scd.DirectoryPath);
using (var repo = new Repository(path))
{
const string originalPath = "original.txt";
const string renamedPath = "renamed.txt";
Touch(repo.Info.WorkingDirectory, originalPath, "a\nb\nc\nd\n");
repo.Stage(originalPath);
Commit old = repo.Commit("Initial", Constants.Signature, Constants.Signature);
repo.Move(originalPath, renamedPath);
Commit @new = repo.Commit("Updated", Constants.Signature, Constants.Signature);
var changes = repo.Diff.Compare<TreeChanges>(old.Tree, @new.Tree);
Assert.Equal(1, changes.Count());
Assert.Equal(1, changes.Renamed.Count());
Assert.Equal(originalPath, changes.Renamed.Single().OldPath);
Assert.Equal(renamedPath, changes.Renamed.Single().Path);
}
}
示例10: CanRenameAFile
public void CanRenameAFile()
{
string repoPath = InitNewRepository();
using (var repo = new Repository(repoPath))
{
Assert.Equal(0, repo.Index.Count);
const string oldName = "polite.txt";
Assert.Equal(FileStatus.Nonexistent, repo.RetrieveStatus(oldName));
Touch(repo.Info.WorkingDirectory, oldName, "hello test file\n");
Assert.Equal(FileStatus.Untracked, repo.RetrieveStatus(oldName));
repo.Stage(oldName);
Assert.Equal(FileStatus.Added, repo.RetrieveStatus(oldName));
// Generated through
// $ echo "hello test file" | git hash-object --stdin
const string expectedHash = "88df547706c30fa19f02f43cb2396e8129acfd9b";
Assert.Equal(expectedHash, repo.Index[oldName].Id.Sha);
Assert.Equal(1, repo.Index.Count);
Signature who = Constants.Signature;
repo.Commit("Initial commit", who, who);
Assert.Equal(FileStatus.Unaltered, repo.RetrieveStatus(oldName));
const string newName = "being.frakking.polite.txt";
repo.Move(oldName, newName);
Assert.Equal(FileStatus.Removed, repo.RetrieveStatus(oldName));
Assert.Equal(FileStatus.Added, repo.RetrieveStatus(newName));
Assert.Equal(1, repo.Index.Count);
Assert.Equal(expectedHash, repo.Index[newName].Id.Sha);
who = who.TimeShift(TimeSpan.FromMinutes(5));
Commit commit = repo.Commit("Fix file name", who, who);
Assert.Equal(FileStatus.Nonexistent, repo.RetrieveStatus(oldName));
Assert.Equal(FileStatus.Unaltered, repo.RetrieveStatus(newName));
Assert.Equal(expectedHash, commit.Tree[newName].Target.Id.Sha);
}
}
示例11: InvalidMoveUseCases
private void InvalidMoveUseCases(string sourcePath, FileStatus sourceStatus, IEnumerable<string> destPaths)
{
var repoPath = SandboxStandardTestRepoGitDir();
using (var repo = new Repository(repoPath))
{
Assert.Equal(sourceStatus, repo.RetrieveStatus(sourcePath));
foreach (var destPath in destPaths)
{
string path = destPath;
Assert.Throws<LibGit2SharpException>(() => repo.Move(sourcePath, path));
}
}
}
示例12: CanMoveAnExistingFileOverANonExistingFile
public void CanMoveAnExistingFileOverANonExistingFile(string sourcePath, FileStatus sourceStatus, string destPath, FileStatus destStatus, FileStatus sourcePostStatus, FileStatus destPostStatus)
{
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Assert.Equal(sourceStatus, repo.RetrieveStatus(sourcePath));
Assert.Equal(destStatus, repo.RetrieveStatus(destPath));
repo.Move(sourcePath, destPath);
Assert.Equal(sourcePostStatus, repo.RetrieveStatus(sourcePath));
Assert.Equal(destPostStatus, repo.RetrieveStatus(destPath));
}
}
示例13: CanResetSourceOfARenameInIndex
public void CanResetSourceOfARenameInIndex()
{
using (var repo = new Repository(SandboxStandardTestRepo()))
{
repo.Move("branch_file.txt", "renamed_branch_file.txt");
RepositoryStatus oldStatus = repo.RetrieveStatus();
Assert.Equal(1, oldStatus.RenamedInIndex.Count());
Assert.Equal(FileStatus.Nonexistent, oldStatus["branch_file.txt"].State);
Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State);
repo.Reset(repo.Lookup<Commit>("32eab9c"), new string[] { "branch_file.txt" });
RepositoryStatus newStatus = repo.RetrieveStatus();
Assert.Equal(0, newStatus.RenamedInIndex.Count());
Assert.Equal(FileStatus.Missing, newStatus["branch_file.txt"].State);
Assert.Equal(FileStatus.Added, newStatus["renamed_branch_file.txt"].State);
}
}
示例14: CanUnstageTargetOfARename
public void CanUnstageTargetOfARename()
{
using (var repo = new Repository(SandboxStandardTestRepo()))
{
repo.Move("branch_file.txt", "renamed_branch_file.txt");
RepositoryStatus oldStatus = repo.RetrieveStatus();
Assert.Equal(1, oldStatus.RenamedInIndex.Count());
Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State);
repo.Unstage(new string[] { "renamed_branch_file.txt" });
RepositoryStatus newStatus = repo.RetrieveStatus();
Assert.Equal(0, newStatus.RenamedInIndex.Count());
Assert.Equal(FileStatus.Untracked, newStatus["renamed_branch_file.txt"].State);
Assert.Equal(FileStatus.Removed, newStatus["branch_file.txt"].State);
}
}