views:

526

answers:

2

I'm having problems getting hudson to checkout my git repo and merge into master. I'm fairly inexperienced with Git so the terminology (refs etc...) is still all new to me. I've included the output from the Hudson console below:

What I think is happening is that Hudson is checking out the master branch on the remote, but not merging it into it's own master. When I ssh into my server and go to the workspace and type in git branch the current branch is * (no branch) and the logs for that "no branch" are up to date.

If I check out the master branch I get Your branch is behind the tracked remote branch 'origin/master' by x commits So obviously it's not merging into master. How does this work though, how can it merge into "no branch" ??

I've listed my git setup below. Not sure what I need to do to get hudson to merge into it's master branch (or any branch that I specify for that matter) I will eventually be setting it up to have a staging and production branch so I need to make sure that it pulls and merges the proper branch so I can run a deploy. I got those hudson settings from some tutorial I found, so I don't fully understand everything. Why for example, the branch to build is */master instead of just master (it doesn't seem to make a difference if I change it to just master)

Any hints are greatly appreciated!!

Hudson Git Settings

URL of repository: /home/git/repositories/my_repo.git
Name of repository: origin
Refspec: +refs/heads/*:refs/remotes/origin/*
Branches to build: */master

Hudson Git Console Log

Last Built Revision: Revision 6ffd51afe6b87393d3215ab2bb30dbcd2de73dde (origin/master )
Checkout:workspace / /mnt/data/hudson/jobs/MyApp-master/workspace - hudson.remoting.LocalChannel@16a31bf
Fetching changes from the remote Git repository
Fetching upstream changes from /home/git/repositories/my_repo.git
[workspace] $ git fetch /home/git/repositories/my_repo.git +refs/heads/*:refs/remotes/origin/*
From /home/git/repositories/my_repo
   6ffd51a..7333c68  master     -> origin/master
[workspace] $ git ls-tree HEAD
Seen branch in repository heroku-devel/master
Seen branch in repository origin/staging
Seen branch in repository origin/master
Seen branch in repository origin/production
[workspace] $ git merge-base 45ae1c52e350fc1463f8b057d81b8cd4472ecdd9 7333c68d2b959eec6b472d7897ec30a3a3cfb5b5
Commencing build of Revision 7333c68d2b959eec6b472d7897ec30a3a3cfb5b5 (origin/master )
Checking out Revision 7333c68d2b959eec6b472d7897ec30a3a3cfb5b5 (origin/master )
[workspace] $ git checkout -f 7333c68d2b959eec6b472d7897ec30a3a3cfb5b5
[workspace] $ git tag -a -f -m "Hudson Build #94" hudson-MyApp-master-94
Recording changes in branch origin/master
[workspace] $ git log --numstat -M --summary --pretty=raw 6ffd51afe6b87393d3215ab2bb30dbcd2de73dde..7333c68d2b959eec6b472d7897ec30a3a3cfb5b5

Versions
Hudson: 1.337
Git: 1.5.6.5
Hudson Git Plugin: 0.7.3
Linux: Debian Lenny 5.0.3

+1  A: 

Just uncheck "Merge before build" and set your banch to master. You don't want merge before build... it's for merging topic branches into master (or any branch) and then pushing it back to master (or any branch) if it builds/integrates and the build succeeds.

The hudson plugin is actually putting you on (no branch) on purpose... and it's a little confusing at first but here's my attempt at an explanation.

When you run git checkout {Some SHA} git ends up on (no branch) or what's called a detached head state. A SHA is a unique id for a commit (and other things but for the purposes of this explanation it's for commits). This is a feature... not a bug. When you check out a SHA your telling git you want to point the symbolic revision titled HEAD at a specific SHA. Don't worry... you're still on master you're just in a detached head state.

My assumption on why the hudson git plugin does this is because the symbolic HEAD revision moves around in a remote repository when people commit to a git repo. So the plugin issues commands like this (in plain english)

  1. git fetch (pull the latest remote branches in the remote git repository into my copy of the remote branches - you can see this by using git branch -a or -r)
  2. git rev-parse origin/master (Grab the latest SHA from the master branch in the origin repo in this example we'll use xxxx as the SHA)
  3. git checkout xxxx (checks out the latest SHA from the remote repo... this will place you in a detached head state.)

Ok... now we're ready to build. (It also does other things like diff the last SHA against the current SHA so that it can spit out a list of changes between the two builds.)

Hope that helps get you going and explains it a bit. (Or at least the next guy that finds this on the interweb.)

Clint Modien
thx for the response, this project I was working on is on hold so when I get back to it I'll verify what you've said.
brad
ok so hudson checks out the latest revision and leaves me in a detached head state, what's my best course of action to merge that head into master? I'm trying to do a Heroku deploy on successful build which is just pushing master to the heroku remote, but I can never get master updated properly.
brad
nm... git 1.0 plugin provides an optional local branch to merge to. worked like a charm!
brad
A: 

Solution to this is the install v1.0 of the Hudson Git plugin. It allows for an optional local branch to merge HEAD to.

brad