本文整理汇总了C#中NGit.Transport.RemoteConfig.AddFetchRefSpec方法的典型用法代码示例。如果您正苦于以下问题:C# RemoteConfig.AddFetchRefSpec方法的具体用法?C# RemoteConfig.AddFetchRefSpec怎么用?C# RemoteConfig.AddFetchRefSpec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NGit.Transport.RemoteConfig
的用法示例。
在下文中一共展示了RemoteConfig.AddFetchRefSpec方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public static FileRepository Init (string targetLocalPath, string url, IProgressMonitor monitor)
{
InitCommand ci = new InitCommand ();
ci.SetDirectory (targetLocalPath);
var git = ci.Call ();
FileRepository repo = (FileRepository) git.GetRepository ();
string branch = Constants.R_HEADS + "master";
RefUpdate head = repo.UpdateRef (Constants.HEAD);
head.DisableRefLog ();
head.Link (branch);
RemoteConfig remoteConfig = new RemoteConfig (repo.GetConfig (), "origin");
remoteConfig.AddURI (new URIish (url));
string dst = Constants.R_REMOTES + remoteConfig.Name;
RefSpec wcrs = new RefSpec();
wcrs = wcrs.SetForceUpdate (true);
wcrs = wcrs.SetSourceDestination (Constants.R_HEADS + "*", dst + "/*");
remoteConfig.AddFetchRefSpec (wcrs);
// we're setting up for a clone with a checkout
repo.GetConfig().SetBoolean ("core", null, "bare", false);
remoteConfig.Update (repo.GetConfig());
repo.GetConfig().Save();
return repo;
}
示例2: TestSaveTimeout
public virtual void TestSaveTimeout()
{
RemoteConfig rc = new RemoteConfig(config, "origin");
rc.AddURI(new URIish("/some/dir"));
rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + rc.Name + "/*"));
rc.Timeout = 60;
rc.Update(config);
CheckConfig("[remote \"origin\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"
+ "\ttimeout = 60\n");
}
示例3: SetUp
public override void SetUp()
{
base.SetUp();
dbTarget = CreateWorkRepository();
source = new Git(db);
target = new Git(dbTarget);
// put some file in the source repo
sourceFile = new FilePath(db.WorkTree, "SomeFile.txt");
WriteToFile(sourceFile, "Hello world");
// and commit it
source.Add().AddFilepattern("SomeFile.txt").Call();
source.Commit().SetMessage("Initial commit for source").Call();
// configure the target repo to connect to the source via "origin"
StoredConfig targetConfig = ((FileBasedConfig)dbTarget.GetConfig());
targetConfig.SetString("branch", "master", "remote", "origin");
targetConfig.SetString("branch", "master", "merge", "refs/heads/master");
RemoteConfig config = new RemoteConfig(targetConfig, "origin");
config.AddURI(new URIish(source.GetRepository().WorkTree.GetPath()));
config.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
config.Update(targetConfig);
targetConfig.Save();
targetFile = new FilePath(dbTarget.WorkTree, "SomeFile.txt");
// make sure we have the same content
target.Pull().Call();
target.Checkout().SetStartPoint("refs/remotes/origin/master").SetName("master").Call
();
targetConfig.SetString("branch", "master", "merge", "refs/heads/master");
targetConfig.SetBoolean("branch", "master", "rebase", true);
targetConfig.Save();
AssertFileContentsEqual(targetFile, "Hello world");
}
示例4: TestSaveAllTags
public virtual void TestSaveAllTags()
{
RemoteConfig rc = new RemoteConfig(config, "origin");
rc.AddURI(new URIish("/some/dir"));
rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + rc.Name + "/*"));
rc.TagOpt = TagOpt.FETCH_TAGS;
rc.Update(config);
CheckConfig("[remote \"origin\"]\n" + "\turl = /some/dir\n" + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"
+ "\ttagopt = --tags\n");
}
示例5: TestTrackingUpdate
public virtual void TestTrackingUpdate()
{
Repository db2 = CreateBareRepository();
string remote = "origin";
string branch = "refs/heads/master";
string trackingBranch = "refs/remotes/" + remote + "/master";
Git git = new Git(db);
RevCommit commit1 = git.Commit().SetMessage("Initial commit").Call();
RefUpdate branchRefUpdate = db.UpdateRef(branch);
branchRefUpdate.SetNewObjectId(commit1.Id);
branchRefUpdate.Update();
RefUpdate trackingBranchRefUpdate = db.UpdateRef(trackingBranch);
trackingBranchRefUpdate.SetNewObjectId(commit1.Id);
trackingBranchRefUpdate.Update();
StoredConfig config = ((FileBasedConfig)db.GetConfig());
RemoteConfig remoteConfig = new RemoteConfig(config, remote);
URIish uri = new URIish(db2.Directory.ToURI().ToURL());
remoteConfig.AddURI(uri);
remoteConfig.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/" + remote +
"/*"));
remoteConfig.Update(config);
config.Save();
RevCommit commit2 = git.Commit().SetMessage("Commit to push").Call();
RefSpec spec = new RefSpec(branch + ":" + branch);
Iterable<PushResult> resultIterable = git.Push().SetRemote(remote).SetRefSpecs(spec
).Call();
PushResult result = resultIterable.Iterator().Next();
TrackingRefUpdate trackingRefUpdate = result.GetTrackingRefUpdate(trackingBranch);
NUnit.Framework.Assert.IsNotNull(trackingRefUpdate);
NUnit.Framework.Assert.AreEqual(trackingBranch, trackingRefUpdate.GetLocalName());
NUnit.Framework.Assert.AreEqual(branch, trackingRefUpdate.GetRemoteName());
NUnit.Framework.Assert.AreEqual(commit2.Id, trackingRefUpdate.GetNewObjectId());
NUnit.Framework.Assert.AreEqual(commit2.Id, db.Resolve(trackingBranch));
NUnit.Framework.Assert.AreEqual(commit2.Id, db2.Resolve(branch));
}
示例6: TestPushWithoutPushRefSpec
public virtual void TestPushWithoutPushRefSpec()
{
Git git = new Git(db);
Git git2 = new Git(CreateBareRepository());
StoredConfig config = git.GetRepository().GetConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
URIish uri = new URIish(git2.GetRepository().Directory.ToURI().ToURL());
remoteConfig.AddURI(uri);
remoteConfig.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
remoteConfig.Update(config);
config.Save();
WriteTrashFile("f", "content of f");
git.Add().AddFilepattern("f").Call();
RevCommit commit = git.Commit().SetMessage("adding f").Call();
git.Checkout().SetName("not-pushed").SetCreateBranch(true).Call();
git.Checkout().SetName("branchtopush").SetCreateBranch(true).Call();
NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/branchtopush"
));
NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/not-pushed"
));
NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/master"
));
git.Push().SetRemote("test").Call();
NUnit.Framework.Assert.AreEqual(commit.Id, git2.GetRepository().Resolve("refs/heads/branchtopush"
));
NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/not-pushed"
));
NUnit.Framework.Assert.AreEqual(null, git2.GetRepository().Resolve("refs/heads/master"
));
}
示例7: Clone
public static FileRepository Clone (string targetLocalPath, string url, IProgressMonitor monitor)
{
// Initialize
InitCommand ci = new InitCommand ();
ci.SetDirectory (targetLocalPath);
var git = ci.Call ();
FileRepository repo = (FileRepository) git.GetRepository ();
string branch = Constants.R_HEADS + "master";
string remoteName = "origin";
RefUpdate head = repo.UpdateRef (Constants.HEAD);
head.DisableRefLog ();
head.Link (branch);
RemoteConfig remoteConfig = new RemoteConfig (repo.GetConfig (), remoteName);
remoteConfig.AddURI (new URIish (url));
string dst = Constants.R_REMOTES + remoteConfig.Name;
RefSpec wcrs = new RefSpec();
wcrs = wcrs.SetForceUpdate (true);
wcrs = wcrs.SetSourceDestination (Constants.R_HEADS + "*", dst + "/*");
remoteConfig.AddFetchRefSpec (wcrs);
// we're setting up for a clone with a checkout
repo.GetConfig().SetBoolean ("core", null, "bare", false);
remoteConfig.Update (repo.GetConfig());
repo.GetConfig().Save();
// Fetch
Transport tn = Transport.Open (repo, remoteName);
FetchResult r;
try {
r = tn.Fetch(new GitMonitor (monitor), null);
}
finally {
tn.Close ();
}
// Create the master branch
// branch is like 'Constants.R_HEADS + branchName', we need only
// the 'branchName' part
String branchName = branch.Substring (Constants.R_HEADS.Length);
git.BranchCreate ().SetName (branchName).SetUpstreamMode (CreateBranchCommand.SetupUpstreamMode.TRACK).SetStartPoint ("origin/master").Call ();
// Checkout
DirCache dc = repo.LockDirCache ();
try {
RevWalk rw = new RevWalk (repo);
ObjectId remCommitId = repo.Resolve (remoteName + "/" + branchName);
RevCommit remCommit = rw.ParseCommit (remCommitId);
DirCacheCheckout co = new DirCacheCheckout (repo, null, dc, remCommit.Tree);
co.Checkout ();
} catch {
dc.Unlock ();
throw;
}
return repo;
}
示例8: SetUpRepoWithRemote
/// <exception cref="System.Exception"></exception>
private Git SetUpRepoWithRemote()
{
Repository remoteRepository = CreateWorkRepository();
Git remoteGit = new Git(remoteRepository);
// commit something
WriteTrashFile("Test.txt", "Hello world");
remoteGit.Add().AddFilepattern("Test.txt").Call();
initialCommit = remoteGit.Commit().SetMessage("Initial commit").Call();
WriteTrashFile("Test.txt", "Some change");
remoteGit.Add().AddFilepattern("Test.txt").Call();
secondCommit = remoteGit.Commit().SetMessage("Second commit").Call();
// create a master branch
RefUpdate rup = remoteRepository.UpdateRef("refs/heads/master");
rup.SetNewObjectId(initialCommit.Id);
rup.ForceUpdate();
Repository localRepository = CreateWorkRepository();
Git localGit = new Git(localRepository);
StoredConfig config = localRepository.GetConfig();
RemoteConfig rc = new RemoteConfig(config, "origin");
rc.AddURI(new URIish(remoteRepository.Directory.GetPath()));
rc.AddFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
rc.Update(config);
config.Save();
FetchResult res = localGit.Fetch().SetRemote("origin").Call();
NUnit.Framework.Assert.IsFalse(res.GetTrackingRefUpdates().IsEmpty());
rup = localRepository.UpdateRef("refs/heads/master");
rup.SetNewObjectId(initialCommit.Id);
rup.ForceUpdate();
rup = localRepository.UpdateRef(Constants.HEAD);
rup.Link("refs/heads/master");
rup.SetNewObjectId(initialCommit.Id);
rup.Update();
return localGit;
}