Git.Core.ObjectStore.Checkout C# (CSharp) Method

Checkout() public method

Get a tree and create the structure from there
public Checkout ( string baseDir, Tree tree ) : void
baseDir string
tree Tree /// A ///
return void
        public void Checkout(string baseDir, Tree tree)
        {
            for (int i = 0; i < tree.Entries.Length; i++) {
                string fullPath = baseDir + "/" + tree.Entries[i].Name;
                Console.WriteLine ("Entry: #{0} {1} {2}", i, tree.Entries[i].Name, tree.Entries[i].Id.ToHexString ());

                if (tree.Entries[i].IsTree ()) {
                    if (!Directory.Exists (fullPath))
                        Directory.CreateDirectory (fullPath);

                    Checkout (fullPath, (Tree) Get (tree.Entries[i].Id));
                    continue;
                }

                FileStream fs = new FileStream (fullPath, FileMode.Create, FileAccess.Write);
                Blob blobToWrite = (Blob) Get (tree.Entries[i].Id);

                fs.Write (blobToWrite.Data, 0, blobToWrite.Data.Length);

                // TODO: Set FileAttributes
                //File.SetAttributes ("", FileAttributes.

                fs.Close ();
            }
        }

Same methods

ObjectStore::Checkout ( string baseDir, Commit commit ) : void

Usage Example

Example #1
0
        public static void CheckoutTest(string hash, string objStorePath)
        {
            ObjectStore store = new ObjectStore (objStorePath);

            SHA1 id = new SHA1 (SHA1.FromHexString (hash), false);

            Console.WriteLine ("Hash: " + hash);
            Console.WriteLine ("Id:   " + id.ToHexString ());

            Console.WriteLine ("hash created");

            Tree tree = (Tree) store.Get (id);

            Console.WriteLine ("tree created No. entries: " + tree.Entries.Length);

            store.Checkout (Environment.CurrentDirectory, tree);

            Console.WriteLine ("Checkout done WIIIII!!!");
        }