Tuesday, September 6, 2016

Git Round 1

My experience lately has been very Microsoft-centric. In a way, its the IT version of navel gazing. Everything focused on PowerShell and the occasional mention or thought of another tool/OS/framework. Well, a PowerShell-centered thought to develop a security module on CodePlex:  https://powershellsecurity.codeplex.com/. As I started getting my head around it I realized that the three methods of source control: Team Foundation Server, Git, and, Mercurial. My shop is a TFS shop, so, that was a natural choice, but, as I thought about it I also noted that TFS is really geared towards larger development shops. In our case, it would be prohibitive to require contributors on a community project to use a tool like this. So, we opted for git.

I had never worked with git, although I knew of it. To start my journey I search for git and arrived at the home page:
http://git-scm.com/
Cause I like to read the help, I glanced at this to get an idea of what git really was.
"Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency." 
And shortly after that, the downloads page:
 http://git-scm.com/downloads
If you click on the Win page it automatically starts a download for the version of your OS. The latest stable version is 1.7.11.3 (released 2012-07-11). I, like most people, grabbed an installer package (http://git-scm.com/download/win), loaded it on my machine, and, being a PowerShell guy, fired it up in PowerShell. That was my first mistake. Apparently the way the host handles standard out doesnt jive well with Git. In the end, I had to switch to plain old cmd.exe much to my chagrin. I tried a few Windows GUI clients, but, all of them are focused on GitHub, and, not CodePlex which makes sense. Its not GetCodePlex after all. One thing to note: if you want to get the physical book, you can, but, the same exact content is available for a free download: https://github.s3.amazonaws.com/media/progit.en.pdf.


After getting back in cmd.exe I ran git. It spit out the usual help:
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:Userswsteele>git -?
Unknown option: -?
usage: git [--version] [--exec-path[=]] [--html-path] [--man-path] [--info
-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=] [--work-tree=] [--namespace=]
           [-c name=value] [--help]
           []
To save myself some time and frustration I returned to the CodePlex page which has some great doco on how to use git with CodePlex. For a complete newb, like myself, this was perfect. As I quickly gathered, git is geared, by default, for people with more a pure developer/nix background. Windows folks can get used to it, but, if you come from the Unix/Linux world, it will be much more intuitive than to someone like myself who is almost entirely Windows-oriented.

When I navigated to the source code page of the project (https://powershellsecurity.codeplex.com/SourceControl/list/changesets) I saw an item on the bottom, right hand corner that indicated the source control method was Git. When I hovered over the link button it displayed the basic arguments I needed to know to configure git.
Clone URL: https://git01.codeplex.com/powershellsecurityUsername: willsteelePassword: 
For more information on connecting to CodePlex projects using Git, please see Using Git with CodePlex.
I clicked on the link, Using Git with CodePlex and it redirected me to CodePlex Information and Discussion. As I started reading through the page I got a few key points I needed to get going. First things first, add a global user name (straight from the CodePlex dialog) to your Git instance. To do this you run this command:
Git config --global user.name willsteele
Easy enough. Being the curious sort, I decided to see what the help for --global has to say. This switch gives you the full set of options for the config command:
C:Userswsteele>git config
usage: git config [options]

Config file location
    --global              use global config file
    --system              use system config file
    --local               use repository config file
    -f, --file      use given config file

Action
    --get                 get value: name [value-regex]
    --get-all             get all values: key [value-regex]
    --get-regexp          get values for regexp: name-regex [value-regex]
    --replace-all         replace all matching variables: name value [value_rege
x]
    --add                 adds a new variable: name value
    --unset               removes a variable: name [value-regex]
    --unset-all           removes all matches: name [value-regex]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    -e, --edit            opens an editor
    --get-color     find the color configured: [default]
    --get-colorbool
                          find the color setting: [stdout-is-tty]

Type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --path                value is a path (file or directory name)

Other
    -z, --null            terminate values with NUL byte
    --includes            respect include directives on lookup
In my case, I just want to know all the options, so, this command gets the job done:
C:Userswsteele>git config -l
core.symlinks=false
core.autocrlf=false
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
gui.recentrepo=C:/Users/wsteele/Documents/Git
user.name=willsteele
merge.tool=kdiff3
mergetool.kdiff3.path=C:/Program Files (x86)/KDiff3/kdiff3.exe
diff.guitool=kdiff3
difftool.kdiff3.path=C:/Program Files (x86)/KDiff3/kdiff3.exe
core.editor="C:/Program Files (x86)/GitExtensions/GitExtensions.exe" fileeditor
core.autocrlf=false
Next, I want to see what --Global shows me:
C:Userswsteele>git config --global -l
gui.recentrepo=C:/Users/wsteele/Documents/Git
user.name=willsteele
merge.tool=kdiff3
mergetool.kdiff3.path=C:/Program Files (x86)/KDiff3/kdiff3.exe
diff.guitool=kdiff3
difftool.kdiff3.path=C:/Program Files (x86)/KDiff3/kdiff3.exe
core.editor="C:/Program Files (x86)/GitExtensions/GitExtensions.exe" fileeditor
core.autocrlf=false
Ok, --Global is merely a subset of the config items. In my mind I map this to powershell as a scoping issue. You have global, session, script, function, etc. Got it. Back to the doco. I added my own user.name earlier on. Lets see whats next in the Google code docs. Step 3. Clone the Repository. This command I tried earlier in PowerShell and it failed because the prompt never appeared. In cmd.exe it does, however:
C:Userswsteele>Git clone https://willsteele@git01.codeplex.com/powershellsecurity C:datadocumentspowershellprojectsgit
Cloning into C:datadocumentspowershellprojectsgit...
Password for https://willsteele@git01.codeplex.com:
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 3 (delta 0)
Unpacking objects: 100% (3/3), done.
I had Windows Explorer opened when I ran this command, so, I could see the files being downloaded in real time. At this point, I had an empty repository. The line beginning with Password was simply a prompt for me to enter my CodePlex password. One I entered that and hit the [Enter] key, everything ran just fine. Sweet, step 3, done. I now have a clone of the repository. 

Onto step 4, actually putting something out there. First, I want to be in the root directory in my cmd.exe path.
C:Userswsteele>Cd C:datadocumentspowershellprojectsgit
Next, I want to drop my files into the folder. I just did a drag and drop for now. So, my folder looks like this:
C:DataDocumentsPowershellProjectsGit>dir
 Volume in drive C has no label.
 Volume Serial Number is 6E87-3EB3

 Directory of C:DataDocumentsPowershellProjectsGit

07/28/2012  01:50 AM   
          .
07/28/2012  01:50 AM   
          ..
07/28/2012  01:46 AM                 0 readme.txt
07/27/2012  04:10 PM             5,376 security.psd1
07/28/2012  12:56 AM            49,885 Security.psm1
               3 File(s)         55,261 bytes
To add my files I run this command:
C:DataDocumentsPowershellProjectsGit>git commit -m "Adding .psd1 and .psm1"

# On branch master
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       Security.psm1
#       security.psd1
nothing added to commit but untracked files present (use "git add" to track)
Nope, that didnt do it, lets try reading what they said, "User the file names…."
C:DataDocumentsPowershellProjectsGit>git add security.psm1

C:DataDocumentsPowershellProjectsGit>git add security.psd1
Ok, that worked. Next, adding to the remote repository:
C:DataDocumentsPowershellProjectsGit>git push origin master
Password for https://willsteele@git01.codeplex.com:
Everything up-to-date
Hmm, that didnt work. Let me reread and see what I missed.
C:DataDocumentsPowershellProjectsGit>git add security.psd1

C:DataDocumentsPowershellProjectsGit>git add Security.psm1

C:DataDocumentsPowershellProjectsGit>git commit
error: There was a problem with the editor "C:/Program Files (x86)/GitExtes/GitExtensions.exe" fileeditor.
Please supply the message using either -m or -F option.

C:DataDocumentsPowershellProjectsGit>git commit
error: There was a problem with the editor "C:/Program Files (x86)/GitExtes/GitExtensions.exe" fileeditor.
Please supply the message using either -m or -F option.

C:DataDocumentsPowershellProjectsGit>git commit -m "Security.psm1"
[master 7262ece] Security.psm1
 Committer: willsteele
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 2 files changed, 1701 insertions(+)
 create mode 100644 Security.psm1
 create mode 100644 security.psd1

C:DataDocumentsPowershellProjectsGit>git push origin master
Password for https://willsteele@git01.codeplex.com:
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 14.63 KiB, done.
Total 4 (delta 0), reused 0 (delta 0)
To https://willsteele@git01.codeplex.com/powershellsecurity   2d66ce5..7262ece  master -> master
After all this, I was able to check over at my CodePlex project, and, see the files has been pushed. Yeah, Im cooking with grease! Time to get back to work on my project, but, as I get more git snippets, Ill be sure to add those posts.

Related Post:

0 comments:

Post a Comment

 
Copyright 2009 Information Blog
Powered By Blogger