本文整理汇总了C#中GitSharp.Core.Repository.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.Create方法的具体用法?C# Repository.Create怎么用?C# Repository.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GitSharp.Core.Repository
的用法示例。
在下文中一共展示了Repository.Create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public static void Init(string folderName)
{
var gitFolder = Path.Combine(folderName, Constants.DOT_GIT);
var repo = new Repository(new DirectoryInfo(gitFolder));
repo.Create(false);
}
示例2: Execute
public override void Execute()
{
if (Source.Length <= 0)
throw new ArgumentNullException("Repository","fatal: You must specify a repository to clone.");
URIish source = new URIish(Source);
if (Mirror)
Bare = true;
if (Bare)
{
if (OriginName != null)
throw new ArgumentException("Bare+Origin", "--bare and --origin " + OriginName + " options are incompatible.");
NoCheckout = true;
}
if (OriginName == null)
OriginName = "origin";
var repo = new GitSharp.Core.Repository(new DirectoryInfo(ActualDirectory));
repo.Create(Bare);
repo.Config.setBoolean("core", null, "bare", Bare);
repo.Config.save();
Repository = new Repository(repo);
if (!Quiet)
{
OutputStream.WriteLine("Initialized empty Git repository in " + repo.Directory.FullName);
OutputStream.Flush();
}
saveRemote(source);
FetchResult r = runFetch();
GitSharp.Core.Ref branch = guessHEAD(r);
if (!NoCheckout)
doCheckout(branch);
}
示例3: Execute
public override void Execute()
{
if (Path.Length <= 0)
throw new ArgumentNullException("Repository","fatal: You must specify a repository to clone.");
URIish source = new URIish(Path);
if (Mirror)
Bare = true;
if (Bare)
{
if (OriginName != null)
throw new ArgumentException("Bare+Origin", "--bare and --origin " + OriginName + " options are incompatible.");
NoCheckout = true;
}
if (OriginName == null)
OriginName = "origin";
// guess a name
string p = source.Path;
while (p.EndsWith("/"))
p = p.Substring(0, p.Length - 1);
int s = p.LastIndexOf('/');
if (s < 0)
throw new ArgumentException("Cannot guess local name from " + source);
string localName = p.Substring(s + 1);
if (!Bare)
{
if (localName.EndsWith(".git"))
localName = localName.Substring(0, localName.Length - 4);
if (GitDirectory == null)
{
GitDirectory = new DirectoryInfo(System.IO.Path.Combine(localName, ".git"));
}
}
else
{
Directory = localName;
}
GitRepository = new GitSharp.Core.Repository(new DirectoryInfo(Directory));
GitRepository.Create(Bare);
GitRepository.Config.setBoolean("core", null, "bare", Bare);
GitRepository.Config.save();
if (!Quiet)
{
OutputStream.WriteLine("Initialized empty Git repository in " + (new DirectoryInfo(Directory)).FullName);
OutputStream.Flush();
}
if (!Bare)
{
saveRemote(source);
FetchResult r = runFetch();
GitSharp.Core.Ref branch = guessHEAD(r);
if (!NoCheckout)
doCheckout(branch);
}
else
{
//Add description directory
OutputStream.WriteLine("Description directory still needs to be implemented.");
//Add hooks directory
OutputStream.WriteLine("Hooks directory still needs to be implemented.");
//Add info directory
OutputStream.WriteLine("Info directory still needs to be implemented.");
//Add packed_refs directory
OutputStream.WriteLine("Packed_refs directory still needs to be implemented.");
}
}
示例4: Run
protected override void Run ()
{
var cloneDialog = new CloneRepositoryDialog ();
cloneDialog.Run ();
cloneDialog.Destroy ();
var repositoryPath = cloneDialog.RepositoryPath;
URIish source = new URIish (repositoryPath);
var originName = cloneDialog.OriginName;
var destination = cloneDialog.WorkingDirectory;
var workingDirectory = Path.Combine (destination, Constants.DOT_GIT);
if (string.IsNullOrEmpty (originName))
originName = Constants.DEFAULT_REMOTE_NAME;
var rep = new GitSharp.Core.Repository (new DirectoryInfo (workingDirectory));
rep.Create ();
rep.Config.setBoolean ("core", null, "bare", false);
rep.Config.save ();
var rc = new RemoteConfig (rep.Config, originName);
rc.AddURI (source);
rc.AddFetchRefSpec (new RefSpec ().SetForce (true).SetSourceDestination (
Constants.R_HEADS + "*",
Constants.R_REMOTES + originName + "/*"));
rc.Update (rep.Config);
rep.Config.save ();
Transport tn = Transport.open (rep, originName);
FetchResult fetchResult = null;
try
{
fetchResult = tn.fetch (new NullProgressMonitor (), null);
}
catch
{
tn.Dispose ();
}
GitSharp.Core.Ref branch = null;
if (fetchResult != null)
{
var headId = fetchResult.GetAdvertisedRef (Constants.HEAD);
var availableRefs = new List<GitSharp.Core.Ref> ();
foreach (GitSharp.Core.Ref r in fetchResult.AdvertisedRefs)
{
var n = r.Name;
if (!n.StartsWith (Constants.R_HEADS))
continue;
availableRefs.Add (r);
if (headId == null || branch != null)
continue;
if (r.ObjectId.Equals (headId.ObjectId))
branch = r;
}
availableRefs.Sort (RefComparator.INSTANCE);
if (headId != null && branch == null)
branch = headId;
}
if (branch != null)
{
if (!Constants.HEAD.Equals (branch.Name))
{
//rep. (Constants.HEAD, branch.Name);
GitSharp.Core.Commit commit = rep.MapCommit (branch.ObjectId);
RefUpdate update = rep.UpdateRef (Constants.HEAD);
update.NewObjectId = commit.CommitId;
update.forceUpdate ();
var index = new GitIndex (rep);
var tree = commit.TreeEntry;
WorkDirCheckout co = new WorkDirCheckout (rep, rep.WorkingDirectory, index, tree);
co.checkout ();
index.write ();
}
}
else
{
MessageService.ShowError ("Cannot clone: no HEAD advertised by remote.");
}
MessageService.ShowMessage(string.Format("Finished cloning {0} to {1}",
repositoryPath,
destination));
}
示例5: createNewEmptyRepo
/// <summary>
/// Helper for creating extra empty repos
/// </summary>
/// <returns>
/// A new empty git repository for testing purposes
/// </returns>
protected Repository createNewEmptyRepo(bool bare)
{
var newTestRepoPath = Path.GetFullPath(trashParent + "/new" + DateTime.Now.Ticks + "." + (_testcount++) );
var newTestRepoPathSuffix = (bare ? "" : "/") + ".git";
var newTestRepo = new DirectoryInfo(newTestRepoPath + newTestRepoPathSuffix);
Assert.IsFalse(newTestRepo.Exists);
var newRepo = new Repository(newTestRepo);
newRepo.Create();
_repositoriesToClose.Add(newRepo);
if (!bare)
{
_directoriesToRemove.Add(newTestRepoPath);
}
else
{
_directoriesToRemove.Add(newTestRepoPath + newTestRepoPathSuffix);
}
return newRepo;
}
示例6: setUp
public virtual void setUp()
{
Configure();
trash = new DirectoryInfo(trashParent + "/trash" + DateTime.Now.Ticks + "." + (_testcount++));
_directoriesToRemove.Add(trash.FullName);
trash_git = new DirectoryInfo(Path.GetFullPath(trash + "/.git"));
var mockSystemReader = new MockSystemReader();
mockSystemReader.userGitConfig = new FileBasedConfig(
new FileInfo(Path.Combine(trash_git.FullName, "usergitconfig")));
SystemReader.setInstance(mockSystemReader);
db = new Repository(trash_git);
db.Create();
string[] packs = {
"pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f",
"pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371",
"pack-9fb5b411fe6dfa89cc2e6b89d2bd8e5de02b5745",
"pack-546ff360fe3488adb20860ce3436a2d6373d2796",
"pack-cbdeda40019ae0e6e789088ea0f51f164f489d14",
"pack-e6d07037cbcf13376308a0a995d1fa48f8f76aaa",
"pack-3280af9c07ee18a87705ef50b0cc4cd20266cf12"
};
var packDir = new DirectoryInfo(db.ObjectsDirectory + "/pack");
foreach (var packname in packs)
{
new FileInfo("Resources/" + Core.Transport.IndexPack.GetPackFileName(packname)).CopyTo(packDir + "/" + Core.Transport.IndexPack.GetPackFileName(packname), true);
new FileInfo("Resources/" + Core.Transport.IndexPack.GetIndexFileName(packname)).CopyTo(packDir + "/" + Core.Transport.IndexPack.GetIndexFileName(packname), true);
}
new FileInfo("Resources/packed-refs").CopyTo(trash_git.FullName + "/packed-refs", true);
}