Branching with Git

Now that jQuery UI is on Github, I need to learn how to branch and merge with Git – and not just local branches, but also pushing branches to Git so that others can work on them.

The chapter on branching from Pro Git is a good start for learning branching in Git. And the next step, remote branches, has its own chapter as well.

In order to be able to repeat the necessary steps, I’ll describe here how to create a local branch, commit some changes, and then push that branch to your Github repository.

The following command creates a new branch and switches to that:

git checkout -b "newbranch"

To see the local branches and which one is the active one, use:

git branch

That should now display a list like

master
* newbranch

Where the asterix marks the new active branch. With that, you can modify stuff in the branch. Then, to add all modified files to a commit, along with a message:

git commit -a -m "Message along with modifications"

Now comes the interesting part, pushing the branch back to the remote repository, Github in my case:

git push origin tooltip

Git knows that “origin” refers to [email protected]:jquery/jquery-ui.git, so it’s enough to add the name of the branch.

This works so far, but isn’t optimal yet: To push from the tooltip branch, I need to use “git push origin tooltip” again. I’ve found two ways to fix this, both way to complicated for such a simple requirement.

Either manually edit your .git/config file and add the branch, you should then end up with something like this:

[branch "master"]
	remote = origin
	merge = refs/heads/master
[branch "tooltip"]
	remote = origin
	merge = refs/heads/tooltip

For my “tooltip” branch, I added the entry below the entry for “master”, and just replaced “master” with “tooltip”.

To avoid editing that config file, I found this to work:

git branch -D tooltip
git checkout --track origin/tooltip

With branch -D I forced a deletion of the local branch, then used checkout with the –track option to check it out again and have Git set up the config entries for “tracking”. There should be an easier way to do that.

Update: Apparently you can configure Git to automatically setup the tracking via:

git config --global branch.autosetupmerge true

You can leave out “–global” to apply it only to the current project. Seems to be more useful as a global setting…

Release: Validation Plugin 1.7

An update for the jQuery validation plugin is available. Most important: Its now fully compatible with jQuery 1.4.2, and still fully compatible with jQuery 1.3.2. I didn’t test with 1.2.6, but it should work, too.

There are four new localizations: Lithuanian, Greek, Latvian and Hebrew. The Spanish localization got a few improvements (I fully trust my contributors on that). Someone also contributed phoneUK and mobileUK methods, which can be found in additional-methods.js (while adding those, I renamed the phone-method to phoneUS).

And as a first proof of concept, there is now a demo styled with jQuery UI Themeroller classes. I’ll improve that when form support gets better in jQuery UI (planned for 1.9).

Download this release.

The full changelog:

The right place for support changed a bit – the mailinglist is no more, replaced by a much cooler forum:

  • Please post questions to the official Using jQuery Plugins Forum, tagging your question with (at least) “validate”. Keep your question short and succinct and provide code when possible; a testpage makes it much more likely that you get an useful answer in no time.
  • Please post bug reports and other contributions (enhancements, features, eg. new validation methods) to the plugins.jQuery.com bug tracker (requires registration).

Enjoy!

Java Tricks: Find out who invoked you

There is a setting in the log4j framework that allows you to log the exact location of where the logger was invoked (I’d provide a link to the related documentation, but I can’t find it; the lo4j site is a horrible mess). I always wondered how that works, here’s how:

public class Invoker {

        public static void main(String[] args) {
                System.out.println("Invoked from: " + invoker());
                System.out.println("A bit more indirect: " + test());
        }
       
        private static String test() {
                return invoker();
        }

        public static String invoker() {
                try {
                        throw new RuntimeException();
                } catch(RuntimeException e) {
                        return e.getStackTrace()[1].toString();
                }
        }
}

The output format matches the Exception#printStackTrace format, so that you can click on the result in the Eclipse console and it opens the file at the correct line:

Invoked from: Invoker.main(Invoker.java:4)
A bit more indirect: Invoker.test(Invoker.java:9) 

Based on the comment attached to the code where I found this, there is an easier way to obtain the stack in Java 1.5. And with a bit of searching, I found the getStackTrace method, added to Thread in 1.5. With that, the code becomes even simpler:

public class Invoker {

        public static void main(String[] args) {
                System.out.println("Invoked from: " + invoker());
                System.out.println("A bit more indirect: " + test());
        }
       
        private static String test() {
                return invoker();
        }

        public static String invoker() {
                return Thread.currentThread().getStackTrace()[2].toString();
        }

} 

Note that the call to Thread#getStackTrace ends up on the stack, too, so the interesting StackTraceElement is at index 2, not 1 as before.

A final warning: While this is immensly helpful for log-based debugging, the performance hit should be kept in mind. The log4j documentation warns about that as well, though I suspect that the Java 1.5 methods will have less impact than the try-catch approach. And some very primitive benchmarking proved me wrong…

Reboot?

I’m thinking about rebooting this blog: Create a new .com site with my jQuery stuff and posting about technical/programming stuff there, while relaunching this site into a german blog, posting about non-technical stuff, music, politics…

If you read this, please let me know what you think: leave a comment, or send me a mail at [email protected]