本文整理汇总了C#中LibGit2Sharp.Repository.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Remove方法的具体用法?C# Repository.Remove怎么用?C# Repository.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LibGit2Sharp.Repository
的用法示例。
在下文中一共展示了Repository.Remove方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: DeleteToolStripMenuItemClick
/// <summary>
/// Delete an entry
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DeleteToolStripMenuItemClick(object sender, EventArgs e)
{
// remove from git
using (var repo = new Repository(Cfg["PassDirectory"]))
{
// remove the file
repo.Remove(dirTreeView.SelectedNode.Tag + "\\" + listFileView.SelectedItem + ".gpg");
// Commit
repo.Commit("password removed", 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();
}
示例3: deleteToolStripMenuItem_Click
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
// remove from git
using (var repo = new Repository(Properties.Settings.Default.PassDirectory))
{
// remove the file
repo.Remove(dataPass.Rows[dataPass.CurrentCell.RowIndex].Cells[0].Value.ToString());
// Commit
repo.Commit("password removed", 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();
}
示例4: 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();
}
}
示例5: TryCommit
private static bool TryCommit(string gitRepoPath, string message)
{
try
{
using (var r = new Repository(gitRepoPath))
{
var status = r.RetrieveStatus();
var toStage =
status.Where(s =>
(s.State & FileStatus.Untracked) != 0
|| (s.State & FileStatus.Modified) != 0
|| (s.State & FileStatus.RenamedInWorkDir) != 0);
var toRemove =
status.Where(s =>
(s.State & FileStatus.Missing) != 0);
foreach (var item in toStage)
{
r.Stage(item.FilePath);
}
foreach (var item in toRemove)
{
r.Remove(item.FilePath);
}
r.Commit(message);
}
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex);
return false;
}
}
示例6: Execute
//.........这里部分代码省略.........
}
if (TreeEntryTargetType.Tree != latestHistory.TargetType)
{
this.Log.LogError("The project's history folder must be a directory.");
return false;
}
foreach (TreeEntry childHistoryEntry in ((Tree)latestHistory.Target))
{
// Only consider files and skip the special file.
if (TreeEntryTargetType.Blob != childHistoryEntry.TargetType ||
childHistoryEntry.Name == SpecialHistoryFileName)
{
continue;
}
// Assume that missing files were processed in a previous run.
if (!File.Exists(Path.Combine(ProjectFolder, childHistoryEntry.Path)))
{
Log.LogMessage("Skipping deleted history entry: {0}", childHistoryEntry.Path);
continue;
}
HistoryFileEntry historyFile = new HistoryFileEntry
{
// Store the contents of the file so it can be added to the StringBuilder once we know how to sort them.
CurrentBlob = (Blob)childHistoryEntry.Target,
// Store the path so that the file can be deleted from git and the filesystem once we're done.
Path = childHistoryEntry.Path,
};
historyFiles.Add(childHistoryEntry.Path, historyFile);
}
if (historyFiles.Count == 0)
{
Log.LogMessage("No history entries found");
return true;
}
// Walk through history, looking for added/renamed files.
// Only look at each commit's first parent to try to stick to the merge commits.
// Keep track of the number of files that were found to try to avoid going back to the beginning of time.
int foundFiles = 0;
Commit commit = repo.Head.Tip;
Commit previousCommit = commit.Parents.FirstOrDefault();
string[] targetPaths = new string[] { HistoryFolderRelativePath };
HistoryFileEntry value;
while (previousCommit != null && foundFiles < historyFiles.Count)
{
TreeChanges treeChanges = repo.Diff.Compare<TreeChanges>(previousCommit.Tree, commit.Tree, targetPaths);
foreach (TreeEntryChanges treeEntryChange in treeChanges.Added)
{
if (historyFiles.TryGetValue(treeEntryChange.Path, out value) && !value.CreationTime.HasValue)
{
value.CreationTime = commit.Committer.When.LocalDateTime;
++foundFiles;
}
}
foreach (TreeEntryChanges treeEntryChange in treeChanges.Renamed)
{
if (historyFiles.TryGetValue(treeEntryChange.Path, out value) && !value.CreationTime.HasValue)
{
value.CreationTime = commit.Committer.When.LocalDateTime;
++foundFiles;
}
}
commit = previousCommit;
previousCommit = commit.Parents.FirstOrDefault();
}
// Sort in descending order based on CreationTime.
List<HistoryFileEntry> sortedHistoryFiles = historyFiles.Values.ToList();
sortedHistoryFiles.Sort((x, y) =>
{
return DateTime.Compare(y.CreationTime.HasValue ? y.CreationTime.Value : DateTime.Now, x.CreationTime.HasValue ? x.CreationTime.Value : DateTime.Now);
});
// Add the contents of each history entry, then delete it.
foreach (HistoryFileEntry historyFile in sortedHistoryFiles)
{
newHistory.AppendLine(historyFile.CurrentBlob.GetContentText().Trim());
newHistory.AppendLine();
Log.LogMessage("Processed history entry: {0}", historyFile.Path);
repo.Remove(historyFile.Path, true);
}
}
// Add the new entries to the top.
newHistory.Append(File.ReadAllText(HistoryFile));
File.WriteAllText(HistoryFile, newHistory.ToString());
// A different part of the build process stages History.md and does the commit and push.
return true;
}
示例7: deleteToolStripMenuItem_Click
/// <summary>
/// Delete an entry
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
// remove from git
using (var repo = new Repository(Cfg["PassDirectory"]))
{
// remove the file
repo.Remove(dataPass.Rows[dataPass.CurrentCell.RowIndex].Cells[0].Value.ToString());
// Commit
repo.Commit("password removed", new Signature("pass4win", "pass4win", DateTimeOffset.Now),
new Signature("pass4win", "pass4win", DateTimeOffset.Now));
if (Cfg["UseGitRemote"] == true && _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);
}
}
ResetDatagrid();
}
示例8: renameToolStripMenuItem_Click
/// <summary>
/// rename the entry with all the hassle that accompanies it.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void renameToolStripMenuItem_Click(object sender, EventArgs e)
{
// rename the entry
InputBoxValidation validation = delegate(string val)
{
if (val == "")
return Strings.Error_not_empty;
if (new Regex(@"[a-zA-Z0-9-\\_]+/g").IsMatch(val))
return Strings.Error_valid_filename;
if (File.Exists(Cfg["PassDirectory"] + "\\" + @val + ".gpg"))
return Strings.Error_already_exists;
return "";
};
var value = dataPass.Rows[dataPass.CurrentCell.RowIndex].Cells[1].Value.ToString();
if (InputBox.Show(Strings.Input_new_name, Strings.Input_new_name_label, ref value, validation) ==
DialogResult.OK)
{
// parse path
string tmpPath = Cfg["PassDirectory"] + "\\" + @value + ".gpg";
// ReSharper disable once AssignNullToNotNullAttribute
Directory.CreateDirectory(Path.GetDirectoryName(tmpPath));
File.Copy(dataPass.Rows[dataPass.CurrentCell.RowIndex].Cells[0].Value.ToString(), tmpPath);
using (var repo = new Repository(Cfg["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", DateTimeOffset.Now),
new Signature("pass4win", "pass4win", DateTimeOffset.Now));
if (Cfg["UseGitRemote"] == true && _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);
}
}
ResetDatagrid();
}
}
示例9: ProcessDirectory
public void ProcessDirectory(RepositoryConfigurationInfo config)
{
if (!Repository.IsValid(config.BaseDir))
{
Repository.Init(config.BaseDir);
}
using (var repo = new Repository(config.BaseDir))
{
// todo, if user.name or user.email are not set in config, set them now!
if (string.IsNullOrEmpty(repo.Config.Get<string>("user.name").Value))
repo.Config.Set("user.name", "gitpusher");
if (string.IsNullOrEmpty(repo.Config.Get<string>("user.email").Value))
repo.Config.Set("user.email", "[email protected]");
repo.Config.Set("diff.renames", "copies");
repo.Config.Set("http.postBuffer", 524288000);
var retrievalOptions = new StatusOptions {DetectRenamesInWorkDir = true, DetectRenamesInIndex = true};
RepositoryStatus status = repo.RetrieveStatus(retrievalOptions);
if (status.IsDirty)
{
bool toCommit = false;
foreach (var renamed in status.RenamedInWorkDir)
{
var oldFileName = renamed.IndexToWorkDirRenameDetails.OldFilePath;
repo.Stage(renamed.FilePath);
repo.Stage(oldFileName);
toCommit = true;
}
foreach (var untracked in status.Untracked)
{
repo.Stage(untracked.FilePath);
toCommit = true;
}
foreach (var modified in status.Modified)
{
repo.Stage(modified.FilePath);
toCommit = true;
}
foreach (var added in status.Added)
{
repo.Stage(added.FilePath);
toCommit = true;
}
foreach (var missing in status.Missing)
{
repo.Remove(missing.FilePath);
toCommit = true;
}
if (toCommit || status.Staged.Any())
{
repo.Commit("GitPusher commit.");
foreach (var rmt in config.Remotes)
{
if (!repo.Network.Remotes.Any(r => r.Name == rmt))
{
FormatLoggerAccessor.Instance().Error($"Remote '{rmt}' not found in git repository. Please check the name with 'git remote -v' and try again.");
continue;
}
var remote = repo.Network.Remotes[rmt];
var options = new PushOptions();
//options.CredentialsProvider = new CredentialsHandler((url, usernameFromUrl, types) =>
// new DefaultCredentials());
//new UsernamePasswordCredentials()
//{
// Username = "myusername",
// Password = "mypassword"
//});
var pushRefSpec = @"refs/heads/master";
repo.Network.Push(remote, pushRefSpec, options, null, "GitPusher push");
}
}
}
}
}