# HG changeset patch # User Peter Sanchez # Date 1351381950 25200 # Sat Oct 27 16:52:30 2012 -0700 # Node ID cf0d80caf293c5c5bef723e7f3d307a0c26309e9 # Parent 12afb9f4bd15d16ae7ee68ad039b1a5569fcfa41 Added support for git repos. diff --git a/app/controllers/bitbucket_hook_controller.rb b/app/controllers/bitbucket_hook_controller.rb --- a/app/controllers/bitbucket_hook_controller.rb +++ b/app/controllers/bitbucket_hook_controller.rb @@ -16,11 +16,15 @@ repository = project.repository raise TypeError, "Project '#{identifier}' has no repository" if repository.nil? - raise TypeError, "Repository for project '#{identifier}' is not a Mercurial repository" unless repository.is_a?(Repository::Mercurial) + raise TypeError, "Repository for project '#{identifier}' is not a BitBucket repository" unless repository.is_a?(Repository::Mercurial) || repository.is_a?(Repository::Git) # Get updates from the bitbucket repository - command = "cd \"#{repository.url}\" && hg pull" - exec(command) + if repository.is_a?(Repository::Git) + update_git_repository(repository) + else + command = "cd \"#{repository.url}\" && hg pull" + exec(command) + end # Fetch the new changesets into Redmine repository.fetch_changesets @@ -36,4 +40,17 @@ logger.info { "BitbucketHook: Shell returned '#{output}'" } end + # Taken from: https://github.com/koppen/redmine_github_hook + def git_command(command, repository) + "git --git-dir='#{repository.url}' #{command}" + end + + def update_git_repository(repository) + command = git_command('fetch origin', repository) + if exec(command) + command = git_command("fetch origin '+refs/heads/*:refs/heads/*'", repository) + exec(command) + end + end + end