本文整理汇总了C#中NGit.Api.Git.Call方法的典型用法代码示例。如果您正苦于以下问题:C# Git.Call方法的具体用法?C# Git.Call怎么用?C# Git.Call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NGit.Api.Git
的用法示例。
在下文中一共展示了Git.Call方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SwitchToBranch
public void SwitchToBranch (IProgressMonitor monitor, string branch)
{
monitor.BeginTask (GettextCatalog.GetString ("Switching to branch {0}", branch), GitService.StashUnstashWhenSwitchingBranches ? 4 : 2);
// Get a list of files that are different in the target branch
IEnumerable<DiffEntry> statusList = GitUtil.GetChangedFiles (RootRepository, branch);
StashCollection stashes = null;
Stash stash = null;
if (GitService.StashUnstashWhenSwitchingBranches) {
stashes = GitUtil.GetStashes (RootRepository);
// Remove the stash for this branch, if exists
string currentBranch = GetCurrentBranch ();
stash = GetStashForBranch (stashes, currentBranch);
if (stash != null)
stashes.Remove (stash);
// Create a new stash for the branch. This allows switching branches
// without losing local changes
using (var gm = new GitMonitor (monitor))
stash = stashes.Create (gm, GetStashName (currentBranch));
monitor.Step (1);
}
// Replace with NGit.Api.Git ().Checkout ()
// Switch to the target branch
var checkout = new NGit.Api.Git (RootRepository).Checkout ();
checkout.SetName (branch);
try {
checkout.Call ();
} finally {
// Restore the branch stash
if (GitService.StashUnstashWhenSwitchingBranches) {
stash = GetStashForBranch (stashes, branch);
if (stash != null) {
using (var gm = new GitMonitor (monitor))
stash.Apply (gm);
stashes.Remove (stash);
}
monitor.Step (1);
}
}
// Notify file changes
NotifyFileChanges (monitor, statusList);
if (BranchSelectionChanged != null)
BranchSelectionChanged (this, EventArgs.Empty);
monitor.EndTask ();
}
示例2: Fetch
public void Fetch (IProgressMonitor monitor)
{
string remote = GetCurrentRemote ();
if (remote == null)
throw new InvalidOperationException ("No remotes defined");
monitor.Log.WriteLine (GettextCatalog.GetString ("Fetching from '{0}'", remote));
var fetch = new NGit.Api.Git (RootRepository).Fetch ();
using (var gm = new GitMonitor (monitor)) {
fetch.SetRemote (remote);
fetch.SetProgressMonitor (gm);
fetch.Call ();
}
monitor.Step (1);
}
示例3: AddTag
public void AddTag (string name, Revision rev, string message)
{
var addTag = new NGit.Api.Git (RootRepository).Tag ();
var gitRev = (GitRevision)rev;
addTag.SetName (name).SetMessage (message).SetObjectId (gitRev.Commit);
addTag.SetObjectId (gitRev.Commit).SetTagger (new PersonIdent (RootRepository));
addTag.Call ();
}
示例4: GetRemoteBranches
public IEnumerable<string> GetRemoteBranches (string remoteName)
{
var list = new NGit.Api.Git (RootRepository).BranchList ().SetListMode (ListBranchCommand.ListMode.REMOTE);
foreach (var item in list.Call ()) {
string name = NGit.Repository.ShortenRefName (item.GetName ());
if (name.StartsWith (remoteName + "/", StringComparison.Ordinal))
yield return name.Substring (remoteName.Length + 1);
}
}
示例5: GetBranches
public IEnumerable<Branch> GetBranches ()
{
var list = new NGit.Api.Git (RootRepository).BranchList ().SetListMode (ListBranchCommand.ListMode.HEAD);
foreach (var item in list.Call ()) {
string name = NGit.Repository.ShortenRefName (item.GetName ());
Branch br = new Branch ();
br.Name = name;
br.Tracking = GitUtil.GetUpstreamSource (RootRepository, name);
yield return br;
}
}
示例6: GetTags
public IEnumerable<string> GetTags ()
{
var list = new NGit.Api.Git (RootRepository).TagList ();
foreach (var item in list.Call ()) {
string name = NGit.Repository.ShortenRefName (item.GetName ());
yield return name;
}
}
示例7: CreateBranchFromCommit
public void CreateBranchFromCommit (string name, RevCommit id)
{
var create = new NGit.Api.Git (RootRepository).BranchCreate ();
if (id != null)
create.SetStartPoint (id);
create.SetName (name);
create.Call ();
}
示例8: CreateBranch
public void CreateBranch (string name, string trackSource)
{
var create = new NGit.Api.Git (RootRepository).BranchCreate ();
if (!String.IsNullOrEmpty (trackSource))
create.SetStartPoint (trackSource);
create.SetName (name);
create.Call ();
}
示例9: Push
public void Push (IProgressMonitor monitor, string remote, string remoteBranch)
{
string remoteRef = "refs/heads/" + remoteBranch;
IEnumerable<PushResult> res;
var push = new NGit.Api.Git (RootRepository).Push ();
// We only have one pushed branch.
push.SetRemote (remote).SetRefSpecs (new RefSpec (remoteRef));
using (var gm = new GitMonitor (monitor)) {
push.SetProgressMonitor (gm);
res = push.Call ();
}
foreach (var pr in res) {
var remoteUpdate = pr.GetRemoteUpdate (remoteRef);
switch (remoteUpdate.GetStatus ()) {
case RemoteRefUpdate.Status.UP_TO_DATE: monitor.ReportSuccess (GettextCatalog.GetString ("Remote branch is up to date.")); break;
case RemoteRefUpdate.Status.REJECTED_NODELETE: monitor.ReportError (GettextCatalog.GetString ("The server is configured to deny deletion of the branch"), null); break;
case RemoteRefUpdate.Status.REJECTED_NONFASTFORWARD: monitor.ReportError (GettextCatalog.GetString ("The update is a non-fast-forward update. Merge the remote changes before pushing again."), null); break;
case RemoteRefUpdate.Status.OK:
monitor.ReportSuccess (GettextCatalog.GetString ("Push operation successfully completed."));
// Update the remote branch
ObjectId headId = remoteUpdate.GetNewObjectId ();
RefUpdate updateRef = RootRepository.UpdateRef (Constants.R_REMOTES + remote + "/" + remoteBranch);
updateRef.SetNewObjectId(headId);
updateRef.Update();
break;
default:
string msg = remoteUpdate.GetMessage ();
msg = !string.IsNullOrEmpty (msg) ? msg : GettextCatalog.GetString ("Push operation failed");
monitor.ReportError (msg, null);
break;
}
}
}
示例10: UnStageFile
/// <summary>
/// Requires absolute path
/// </summary>
/// <param name="fileName"></param>
public void UnStageFile(string fileName)
{
if (!this.HasGitRepository) return;
var fileNameRel = GetRelativeFileName(fileName);
if (GitBash.Exists)
{
if (head == null)
{
GitBash.Run(string.Format("rm --cached -- \"{0}\"", fileNameRel), this.GitWorkingDirectory);
}
else
{
GitBash.Run(string.Format("reset -- \"{0}\"", fileNameRel), this.GitWorkingDirectory);
}
}
else
{
ResetCommand resetCommand = new Git(repository).Reset();
resetCommand.AddPath(GetRelativeFileNameForGit(fileName));
resetCommand.SetRef(Constants.HEAD);
resetCommand.Call();
}
this.cache.Remove(GetCacheKey(fileName));
this.changedFiles = null;
}
示例11: StageFile
/// <summary>
/// Requires absolute path
/// </summary>
/// <param name="fileName"></param>
public void StageFile(string fileName)
{
if (!this.HasGitRepository) return;
//var index = repository.GetIndex();
//index.RereadIfNecessary();
if (GitBash.Exists)
{
if (File.Exists(fileName))
{
GitBash.Run(string.Format("add \"{0}\"", GetRelativeFileName(fileName)), this.GitWorkingDirectory);
}
else
{
GitBash.Run(string.Format("rm --cached -- \"{0}\"", GetRelativeFileName(fileName)), this.GitWorkingDirectory);
}
}
else
{
if (File.Exists(fileName))
{
AddCommand addCommand = new Git(repository).Add();
addCommand.AddFilepattern(GetRelativeFileNameForGit(fileName));
addCommand.Call();
}
else
{
RmCommand rmCommand = new Git(repository).Rm();
rmCommand.AddFilepattern(GetRelativeFileNameForGit(fileName));
rmCommand.Call();
}
}
this.cache.Remove(GetCacheKey(fileName));
this.changedFiles = null;
}
示例12: CompareCommits
public static IEnumerable<DiffEntry> CompareCommits (NGit.Repository repo, AnyObjectId reference, ObjectId compared)
{
var diff = new NGit.Api.Git (repo).Diff ();
var firstTree = new CanonicalTreeParser ();
firstTree.Reset (repo.NewObjectReader (), new RevWalk (repo).ParseTree (reference));
diff.SetNewTree (firstTree);
if (compared != ObjectId.ZeroId) {
var secondTree = new CanonicalTreeParser ();
secondTree.Reset (repo.NewObjectReader (), new RevWalk (repo).ParseTree (compared));
if (compared != ObjectId.ZeroId)
diff.SetOldTree (secondTree);
}
return diff.Call ();
}
示例13: Rebase
public bool Rebase ()
{
NGit.Api.Git git = new NGit.Api.Git (repo);
if (aborted)
return false;
if (starting) {
ObjectId headId = repo.Resolve (Constants.HEAD + "^{commit}");
RevCommit headCommit = rw.ParseCommit (headId);
oldHead = headCommit;
ObjectId upstreamId = repo.Resolve (upstreamRef);
RevCommit upstreamCommit = rw.ParseCommit (upstreamId);
oldHead = headCommit;
lastGoodHead = upstreamId;
commitChain = new List<RevCommit> ();
LogCommand cmd = new NGit.Api.Git(repo).Log().AddRange(upstreamId, headCommit);
foreach (RevCommit commit in cmd.Call())
commitChain.Add(commit);
commitChain.Reverse ();
currentMergeIndex = 0;
// Checkout the upstream commit
// Reset head to upstream
GitUtil.HardReset (repo, upstreamRef);
string rebaseDir = Path.Combine (repo.Directory, "rebase-apply");
if (!Directory.Exists (rebaseDir))
Directory.CreateDirectory (rebaseDir);
string rebasingFile = Path.Combine (rebaseDir, "rebasing");
if (!File.Exists (rebasingFile))
File.WriteAllBytes (rebasingFile, new byte[0]);
starting = false;
monitor.BeginTask ("Applying local commits", commitChain.Count);
}
else {
// Conflicts resolved. Continue.
NGit.Api.AddCommand cmd = git.Add ();
var conflicts = LastMergeResult.GetConflicts ();
foreach (string conflictFile in conflicts.Keys) {
cmd.AddFilepattern (conflictFile);
}
cmd.Call ();
NGit.Api.CommitCommand commit = git.Commit ();
commit.SetMessage (currentMergeCommit.GetFullMessage ());
commit.SetAuthor (currentMergeCommit.GetAuthorIdent ());
commit.SetCommitter (currentMergeCommit.GetCommitterIdent ());
commit.Call();
}
// Merge commit by commit until the current head
while (currentMergeIndex < commitChain.Count) {
currentMergeCommit = commitChain[currentMergeIndex++];
mergeResult = GitUtil.CherryPick (repo, currentMergeCommit);
monitor.Log.WriteLine ("Applied '{0}'", currentMergeCommit.GetShortMessage ());
monitor.Step (1);
if (mergeResult.GetMergeStatus () == MergeStatus.CONFLICTING || mergeResult.GetMergeStatus () == MergeStatus.FAILED)
return false;
lastGoodHead = mergeResult.GetNewHead ();
}
monitor.EndTask ();
CleanRebaseFile ();
return true;
}