Commits

Peter Sanchez  committed cf0d80c

Added support for git repos.

  • Participants
  • Parent commits 12afb9f

Comments (0)

Files changed (1)

File app/controllers/bitbucket_hook_controller.rb

     
     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
     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