OWASP O2 Platform Blog

O2 Script: Creating a Git Clone using TortoiseGIT

After installing  TortoiseGIT ,  using PuttyGen to create the SSH key and adding the SSH Key to GitHub the final step in this series is to create GIT Clone locally (this is how we check out code using GIT)

public static API_GitHub gitClone(this API_GitHub gitHub)
        {
            var url = "What is the git clone url?".askUser();
            var targetDir = "What is the target directory?".askUser();
            var privateKeyFile = "Where is the private Key?".askUser();
            gitHub.gitClone(url, targetDir, privateKeyFile);
            return gitHub;
        }
        public static API_GitHub gitClone(this API_GitHub gitHub, string url, string targetDir, string privateKeyFile)
        {
            if (targetDir.inValid())
                targetDir = "".tempDir();
            var guiAutomation = new API_GuiAutomation();

            if (guiAutomation.desktopWindow("Git clone").isNull())  // see if there is already an 'Git clone' window
            {
                //Create a form window with a webbrowser that will open a local folder
                var windowName = "This is Git Clone target folder  (id:{0})".format(3.randomNumbers());
                var topPanel = O2Gui.open<Panel>(windowName,600,200 );
                var webBrowser = topPanel.add_WebBrowser_Control();
                webBrowser.open(targetDir);
                webBrowser.mouse_MoveTo_WinForm(); 
               
                // get the form and right click on it
                var window = guiAutomation.desktopWindow(windowName);
                guiAutomation.mouse().click().rightClick();
           
                // get the context menu and click on the 'Git Clone...' menu button
                var contextMenu =  guiAutomation.getContextMenu();
                contextMenu.menu("Git Clone...").mouse().click();
            }
            // get the Git Clone window
            var gitClone = guiAutomation.desktopWindow("Git clone", 10);
            gitClone.bringToFront();
            // get a reference to the textboxes we will need to populate
            var url_TextBox = gitClone.textBox("Url: ");
            var directory_TextBox = gitClone.textBox("Directory:");
            var puttyKey_TextBox = gitClone.textBoxes().id(1571);
            if (url.valid())
                url_TextBox.set_Text(url);
            if (privateKeyFile.valid() && privateKeyFile.fileExists())
                puttyKey_TextBox.set_Text(privateKeyFile);
            //directory_TextBox.set_Text(targetDir);   // no need to do this since it is added when we use the context menu
           
            // Click button
            gitClone.button("OK").mouse().click();           
           
            return gitHub;
        }

March 18, 2011 - Posted by | Interoperability

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: