More Git Notes

Neo4J and Github trainer Peter Bell was at the Austin Groovy and Grails User Group a couple of weeks ago. He gave some git tips and tricks. I took notes. The guys at AGGUG said they would have something online. So far I have not seen anything, so I am posting my notes.

These are unedited, so you have to mentally parse it yourself. But there were a few things I did not know about.

start gitconfig
You can use the properties as setters and getters
git config –global user.name
git config –global user.name “Daffy Duck”
True for Windows
git config –global core.autocrlf true input
Colors for different status in git
git config –global color.ui true
Can be global, local
global is for every repo
local is the default, for a repo
system is not used too often. This is for all the users of that system.
It is in ~/.gitignore

To create a repo:
git init webgg1
cd webgg1
You might touch a file just to make a file
touch slslsls
git add .
git commit -m “Hello”
Status in silent mode: reduces the output
git status -s
git config –global alias.s “status -s”
Now you can type
git s
git log has bad default output
git log –oneline
git log –oneline –decorate
HEAD is the commit branch you currently have checked out
git log –oneline –decorate –all –graph
git config –global alias.lg “log –online –all –decorate –graph”
The alias is after the alias.
You want to commit to a different branch than master.
git checkout -b about_us
Any untracked files from master come with you
For a modified file (will not work for new files):
git commit -am “djdj”
git merge sjsjs
That is a fast forward merge.
He does not like that.
First he must undo the merge:
git reset –keep master@{1}
Go back one step in the ref log

git merge –no-ff $BRANCH -m “Hello”

Then
git branch -d about_us
He likes to delete a branch when he commits
Merge other branches into master
I always thought you do the opposite: Never mess with master

TO remove a commit:
git reset –hard head~1

rebasing: a branch has a starting point from which it grew
Could we move the base to somewhere else
git rebase master
You might get a merge conflict.
git rebase –continue
If you delete branches and do not do fast forward commits, you still see the commits from those other branches

git reset will undo commits
–soft affects history
–mixed affects staging area as well
–hard affects working directory

We want the two new files, but undo the commits. This will undo 2 commits
git reset HEAD~2
git commit -m “jjs”

Make the last two commits into one commit
git reset –soft HEAD~2
git commit -m “hddh”

Once you push to a server, reset will be bad news
git revert $SHA_CODE

git reset –hard HEAD~2
That will delete history and the files

git ref log will track everything, it is local to each machine.
You can still reset

git commit -m “Logic stuff adofhdofh”
git commit –amend
that only affects the last commit

git rebase interactive will take commits and reorder them or concatenate them
git rebase -i HEAD~4
r = reword
f = fix up
Squash will add all the commit message. You just want to reword the first, fix the rest.

I Got a New Laptop Running Windows 8

Last week my older laptop running Windows XP died. So I got one running Windows 8. The only reason I run Windows is because my mp3 player will not connect to my Linux laptop.

So far, it is okay. I have not worked with the touch screen. I like the fact that if you hit Windows-X you can have the old XP interface. It is nice that Microsoft is actually giving people some degree of choice. I guess that the newer way of doing things might someday become the standard, so I should probably look at it at some point. Maybe it will be like Intel’s Itanium: Consumers will ignore it and it will just die.

When I was setting up my user account it tried to force me to get a Microsoft account. I did some googling on my other machine, and one of the results pointed out there was a link in fine print that would allow me to log in without a Microsoft account. One thing that I did not like was that Windows 8 tried to call the mothership. I have my router set up to only allow explicit ethernet addresses through. But I could not get the ethernet address without logging in, so I had to disable that on my router. I got the ethernet address, entered it, and re-enabled that feature. I am not a security expert. Maybe the Russians are using my WiFi to plan their next invasion of Estonia. But I do not like doing something that I know for sure will make me less secure.

I then downloaded Firefox, the JDK, and a few other apps that I use, like jEdit and aTunes. For one of those, I downloaded an installer from Sourceforge by mistake that installed a browser add-on called mysearchdial. I got id of it from Firefox. I was only able to disable it in IE. I have not figured out how to delete it. I was a bit surprised that Sourceforge was installing spyware on machines. It is not that hard to avoid doing it, you just have to be careful what you click on.

But so far Windows 8 seems nice.

2014-03-31 Tweets

2014-03-30 Update

I am still getting into Groovy.

I am on a new project at work, so getting used to that takes a lot of time and energy.

I did write something in Groovy to make a few tasks easier. I don’t know if other people will be using it. We shall see.

I spent some time going through Programming Concurrency on the JVM by Venkat Subramaniam again. I have a repo on github. I typed in a lot of the examples, and I refactored some of them. I went through and I added a README.md file to each directory giving a summary of that the apps do, and making some comments. I also added a few more classes. I learned some more by going through it. I might give a presentation on it someday.

I also might be giving a presentation on ActiveJDBC, an ORM framework for Java. I got it working with Gradle. It uses instrumentation for a lot of its magic under the hood. I had honestly never heard of instrumentation before. I think it is when you compile a Java class, and add some more bytecode to your compiled class. Anyway, I will work on something to present to the Austin Groovy and Grails group in a few months.

 

Groovy: Stubbing With Spock

I have a github repo for working with RabbitMQ clients. I have not done much with it so far, just a few of the Java samples.

I worked a bit on a Spock test that stubs a message. I am still not completely clear on the difference between mocking and stubbing. With Spock, it seems like you use stubbing when you want your fake object to return a value from a method call, while mocking will check if that method is invoked. It is one of those things that I do not look at very often and then quickly forget.

So I will post this so I at least remember how to do it.

Here is the code in the sample that gets the message:

QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String( delivery.getBody() );
System.out.println(" [x] Received '" + message + "'");

Here is the code for the test:

def delivery = Stub( QueueingConsumer.Delivery )
def x = "ok".getBytes()
delivery.getBody() >> x
// setup:

when:
    println( "Here is delivery.getBody(): ${delivery.getBody()}" )
    def stringOutput = new String( delivery.getBody() )
    println( "Here is stringOutput: ${stringOutput}" )
then:
    // (1..5) * delivery.getBody()
    stringOutput == "ok"

I admit, it needs a bit of cleaning up.

One thing that took me so long was that I thought the method I was stubbing returned a String, when it returned an array of bytes. delivery.getBody() kept returning null because I had

delivery.getBody() >> "ok"

Perhaps I should start making gists when I figure things out.

2014-02-24 Tweets