// Constructor for creating a repository public Repository(string aPath, string aOrigin, string aMaster) { iPath = aPath; iOrigin = aOrigin; iMaster = aMaster; iFolder = new DirectoryInfo(iPath); try { Directory.Delete(Path.Combine(iFolder.FullName, ".git"), true); } catch (DirectoryNotFoundException) { } iFolderGit = iFolder.CreateSubdirectory(".git"); //DirectoryInfo hooks = git.CreateSubdirectory("hooks"); iFolderObjects = iFolderGit.CreateSubdirectory("objects"); iFolderInfo = iFolderObjects.CreateSubdirectory("info"); iFolderPack = iFolderObjects.CreateSubdirectory("pack"); iFolderRefs = iFolderGit.CreateSubdirectory("refs"); iFolderHeads = iFolderRefs.CreateSubdirectory("heads"); iFolderTags = iFolderRefs.CreateSubdirectory("tags"); var info = iFolderGit.CreateSubdirectory("info"); var exclude = new FileStream(Path.Combine(info.FullName, "exclude"), FileMode.CreateNew, FileAccess.Write); using (var writer = new StreamWriter(exclude)) { writer.Write("# git-ls-files --others --exclude-from=.git/info/exclude\n"); writer.Write("# Lines that start with '#' are comments.\n"); writer.Write("# For a project mostly in C, the following would be a good set of\n"); writer.Write("# exclude patterns (uncomment them if you want to use them):\n"); writer.Write("# *.[oa]\n"); writer.Write("# *~\n"); } var head = new FileStream(Path.Combine(iFolderGit.FullName, "HEAD"), FileMode.CreateNew, FileAccess.Write); using (var writer = new StreamWriter(head)) { writer.Write("ref: refs/heads/" + aMaster + "\n"); } var description = new FileStream(Path.Combine(iFolderGit.FullName, "description"), FileMode.CreateNew, FileAccess.Write); using (var writer = new StreamWriter(description)) { writer.Write("Unnamed repository; edit this file 'description' to name the repository.\n"); } var config = new FileStream(Path.Combine(iFolderGit.FullName, "config"), FileMode.CreateNew, FileAccess.Write); using (var writer = new StreamWriter(config)) { writer.Write("[core]\n"); writer.Write("\trepositoryformatversion = 0\n"); writer.Write("\tfilemode = false\n"); writer.Write("\tbare = false\n"); writer.Write("\tlogallrefupdates = true\n"); writer.Write("\tsymlinks = false\n"); writer.Write("\tignorecase = true\n"); writer.Write("\thideDotFiles = dotGitOnly\n"); writer.Write("[remote \"origin\"]\n"); writer.Write("\turl = {0}\n", iOrigin); writer.Write("[branch \"master\"]\n"); writer.Write("\tremote = origin\n"); } iBranches = FindBranches(); iRefs = FindRefs(); foreach (var entry in FindPackedRefs()) { iRefs.Add(entry); } iPacks = FindPacks(); iHash = new Hash(); }
// Constructor for opening a repository public Repository(string aPath) { iPath = aPath; if (!Directory.Exists(iPath)) { throw (new DirectoryNotFoundException()); } // Open existing git iFolder = new DirectoryInfo(iPath); iFolderGit = GetSubFolder(iFolder, ".git"); iFolderObjects = GetSubFolder(iFolderGit, "objects"); iFolderInfo = GetSubFolder(iFolderObjects, "info"); iFolderPack = GetSubFolder(iFolderObjects, "pack"); iFolderRefs = GetSubFolder(iFolderGit, "refs"); iFolderHeads = GetSubFolder(iFolderRefs, "heads"); iFolderTags = GetSubFolder(iFolderRefs, "tags"); //iFolderRemotes = GetSubFolder(iFolderRefs, "remotes"); iOrigin = FindOrigin(); iMaster = FindMaster(); iBranches = FindBranches(); iRefs = FindRefs(); foreach (var entry in FindPackedRefs()) { iRefs.Add(entry); } iPacks = FindPacks(); iHash = new Hash(); }