Peter Sanchez avatar Peter Sanchez committed cf0d80c

Added support for git repos.

Comments (0)

Files changed (1)

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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.