git-bro 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
@@ -0,0 +1,18 @@
1
+ git-bro - serve and browse your Git repositories
2
+
3
+ You can install it as a gem
4
+ sudo gem install git-bro
5
+
6
+ Or build from sources
7
+ git clone git://github.com/kolo/git-bro.git
8
+ cd git-bro
9
+ rake build
10
+ rake install
11
+
12
+ Usage: git-bro [--version] [--help] COMMAND [ARGS]
13
+
14
+ List of available commands:
15
+ serve Serves current or specified directory
16
+
17
+ Dmitry Maksimov <dmtmax@gmail.com>
18
+ http://github.com/kolo/git-bro
data/bin/git-bro ADDED
@@ -0,0 +1,85 @@
1
+ #! /usr/bin/ruby
2
+
3
+ require 'optparse'
4
+ require 'ostruct'
5
+ require 'rbconfig'
6
+ require 'git-bro'
7
+ require 'git-bro/commands'
8
+
9
+ module GitBro
10
+ TARGET_OS = Config::CONFIG['target_os']
11
+ require 'git-bro/process' if TARGET_OS == 'mswin32'
12
+ end
13
+
14
+ class GitBroApp
15
+ attr_reader :options
16
+
17
+ def initialize(arguments)
18
+ @valid_commands = ['serve']
19
+ @arguments = arguments
20
+ @options = OpenStruct.new
21
+
22
+ @options.gem_path = File.expand_path(File.dirname(__FILE__)) + "/.."
23
+ end
24
+
25
+ # parse options, check arguments, then process the command
26
+ def run
27
+ if parsed_options? and arguments_valid?
28
+ process_arguments
29
+ process_command
30
+ else
31
+ output_usage
32
+ end
33
+ end
34
+
35
+ protected
36
+ include GitBro::ServeCommand
37
+
38
+ def parsed_options?
39
+ return false if @arguments.empty?
40
+ @command = @arguments.delete_at(0)
41
+
42
+ opts = OptionParser.new
43
+ opts.on('-v', '--version'){output_version;exit 0}
44
+ opts.on('-h', '--help'){output_help;exit 0}
45
+
46
+ opts.parse!(@arguments) rescue return false
47
+
48
+ true
49
+ end
50
+
51
+ def arguments_valid?
52
+ return false unless @valid_commands.include?(@command)
53
+ self.send("#{@command}_arguments_valid?")
54
+ end
55
+
56
+ def process_arguments
57
+ self.send("#{@command}_process_arguments")
58
+ end
59
+
60
+ def output_version
61
+ puts "#{GitBro::VERSION}"
62
+ end
63
+
64
+ def output_help
65
+ output_version
66
+ File.readlines("#{File.dirname(__FILE__)}/short_help.txt").each {|l| puts l}
67
+ end
68
+
69
+ def output_usage
70
+ puts "Usage: git-bro [--version] [--help] COMMAND [options]"
71
+ end
72
+
73
+ def process_command
74
+ self.send("do_#{@command}")
75
+ end
76
+ end
77
+
78
+ begin
79
+ gb_app = GitBroApp.new(ARGV)
80
+ gb_app.run
81
+ rescue SystemExit
82
+ # do nothing
83
+ rescue Exception => e
84
+ puts e.message
85
+ end
Binary file
Binary file
data/bin/server.rb ADDED
@@ -0,0 +1,52 @@
1
+ #! /usr/bin/ruby
2
+
3
+ require 'rubygems'
4
+ require 'git-bro'
5
+ require 'sinatra'
6
+ require 'haml'
7
+ require 'sass'
8
+ require 'git-bro/sinatra/helpers'
9
+
10
+ set :run, true
11
+
12
+ begin
13
+ if ARGV.size != 1
14
+ puts 'USAGE: ruby git-bro <path to git repository>'
15
+ exit 1
16
+ end
17
+ repository = GitBro::Repository.new(File.expand_path(ARGV.first))
18
+ rescue ArgumentError
19
+ puts "Cannot locate a repository in #{ARGV.first}"
20
+ exit 1
21
+ end
22
+
23
+ # Routes
24
+
25
+ get '/' do
26
+ @branches = repository.branches
27
+ haml :index
28
+ end
29
+
30
+ get '/tree/:branch' do
31
+ @url_prefix = "/tree/#{params[:branch]}"
32
+ @path = "#{repository.name}/"
33
+ @objs = repository.tree(params[:branch], [])
34
+ haml :dir_listing
35
+ end
36
+
37
+ get '/tree/:branch/*/' do
38
+ @url_prefix = "/tree/#{params[:branch]}/#{params[:splat].first}"
39
+ @path = "#{repository.name}/#{params[:splat].first}/"
40
+ @objs = repository.tree(params[:branch], [].push(params[:splat].first + '/'))
41
+ haml :dir_listing
42
+ end
43
+
44
+ get '/tree/:branch/*' do
45
+ @content = repository.file_content(params[:branch], params[:splat].first)
46
+ haml :file_content
47
+ end
48
+
49
+ get '/application.css' do
50
+ content_type 'text/css', :charset => 'utf-8'
51
+ sass :application
52
+ end
@@ -0,0 +1,4 @@
1
+ Usage: git-bro [--version] [--help] COMMAND [options]
2
+
3
+ List of available commands:
4
+ git-bro serve PATH_TO_REPOSITORY - will serve the given repository
@@ -0,0 +1,69 @@
1
+ body
2
+ width: 1000px
3
+ margin: auto
4
+
5
+ !blue_clr= #227CE8
6
+
7
+ h2
8
+ :color= !blue_clr
9
+
10
+ a
11
+ :color= !blue_clr
12
+ text-decoration: none
13
+ a:hover
14
+ text-decoration: underline
15
+
16
+ #header
17
+ padding: 5px 25px
18
+ border-bottom: 2px solid #66A3D2
19
+ background-color: #66A3D2
20
+ margin-top: 10px
21
+ color: #FFF
22
+ #header p
23
+ padding: 0
24
+ margin: 0
25
+ #header h1
26
+ padding: 0
27
+ margin: 0
28
+
29
+ #path
30
+ font-size: 1.3em
31
+ padding: 10px 0
32
+ #repo-name
33
+ font-weight: bold
34
+
35
+ #content h2
36
+ font-size: 1.2em
37
+
38
+ #files
39
+ width: 100%
40
+ border-collapse: collapse
41
+ #files th
42
+ text-align: left
43
+ padding: 2px 5px
44
+ background-color: #66A3D2
45
+ color: #2A2829
46
+ font-size: 0.8em
47
+ #files tr
48
+ border: 1px solid #66A3D2
49
+ #files td
50
+ padding: 2px 5px
51
+ font-size: 0.8em
52
+
53
+ #files .date
54
+ font-size: 0.7em
55
+ color: #444
56
+ #files .icon
57
+ width: 16px
58
+ #files .age
59
+ width: 20%
60
+ #files td a
61
+ text-decoration: none
62
+ #files td a:hover
63
+ text-decoration: underline
64
+ color= !blue_clr
65
+
66
+ #footer
67
+ margin-top: 20px
68
+ text-align: right
69
+ font-size: 0.7em
@@ -0,0 +1,23 @@
1
+ %table#files
2
+ %colgroup
3
+ %col.icon
4
+ %col.name
5
+ %col.age
6
+ %col.message
7
+ %tr
8
+ %th
9
+ %th name
10
+ %th age
11
+ %th message
12
+ - objs.each do |obj|
13
+ %tr
14
+ %td
15
+ - if obj[:type] == 'file'
16
+ %img{:src => '/images/file.png'}
17
+ - else
18
+ %img{:src => '/images/folder.png'}
19
+ %td
20
+ %a{:href => "#{@url_prefix}/#{obj[:name]}"}
21
+ = obj[:name]
22
+ %td.date #{obj[:date]}
23
+ %td #{obj[:message]} (#{obj[:author]})
@@ -0,0 +1,3 @@
1
+ %div#path
2
+ - render_path(@path, params[:branch])
3
+ = partial :dir, :locals => {:path_prefix => @url_prefix, :objs => @objs}
@@ -0,0 +1,3 @@
1
+ %p
2
+ = @content.gsub("\n", '<br/>')
3
+ %a{:href => '/'} Home
@@ -0,0 +1,4 @@
1
+ %h2 Branches
2
+ - @branches.each do |b|
3
+ %div
4
+ %a{:href => "/tree/#{b.name}"} #{b.name}
@@ -0,0 +1,16 @@
1
+ = '<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”'
2
+ = '“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>'
3
+ = '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'
4
+ %html{:xmlns => "http://www.w3.org/1999/xhtml"}
5
+ %head
6
+ %title Git-Bro - browse your repositories
7
+ %link{:rel => 'stylesheet', :type => 'text/css', :href => '/application.css'}
8
+ %body
9
+ #wrapper
10
+ #header
11
+ %h1 Git-Bro
12
+ %p browse your Git repositories
13
+ #content
14
+ = yield
15
+ #footer
16
+ %a{:href => 'http://github.com/kolo/git-bro'}git-bro on Github
data/git-bro.gemspec ADDED
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile.rb, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{git-bro}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dmitry Maksimov"]
12
+ s.date = %q{2010-03-04}
13
+ s.default_executable = %q{git-bro}
14
+ s.description = %q{Git-bro provides tools to serve your Git repositories}
15
+ s.email = %q{dmtmax@gmail.com}
16
+ s.executables = ["git-bro"]
17
+ s.extra_rdoc_files = [
18
+ "README"
19
+ ]
20
+ s.files = [
21
+ "README",
22
+ "bin/git-bro",
23
+ "bin/public/images/file.png",
24
+ "bin/public/images/folder.png",
25
+ "bin/server.rb",
26
+ "bin/short_help.txt",
27
+ "bin/views/application.sass",
28
+ "bin/views/dir.haml",
29
+ "bin/views/dir_listing.haml",
30
+ "bin/views/file_content.haml",
31
+ "bin/views/index.haml",
32
+ "bin/views/layout.haml",
33
+ "git-bro.gemspec",
34
+ "lib/git-bro.rb",
35
+ "lib/git-bro/commands.rb",
36
+ "lib/git-bro/commands/serve.rb",
37
+ "lib/git-bro/process.rb",
38
+ "lib/git-bro/repository.rb",
39
+ "lib/git-bro/sinatra/helpers.rb",
40
+ "rakefile.rb"
41
+ ]
42
+ s.homepage = %q{http://github.com/kolo/git-bro}
43
+ s.rdoc_options = ["--charset=UTF-8"]
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = %q{1.3.5}
46
+ s.summary = %q{Serve and browse your Git repositories}
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ s.add_runtime_dependency(%q<grit>, [">= 0"])
54
+ s.add_runtime_dependency(%q<sinatra>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<grit>, [">= 0"])
57
+ s.add_dependency(%q<sinatra>, [">= 0"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<grit>, [">= 0"])
61
+ s.add_dependency(%q<sinatra>, [">= 0"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,22 @@
1
+ module GitBro
2
+ # Provides functions for implementing serve command
3
+ module ServeCommand
4
+ def serve_arguments_valid?
5
+ @arguments.size <= 1 ? true : false
6
+ end
7
+
8
+ def serve_process_arguments
9
+ @options.repo_path = @arguments.size == 1 ? @arguments.first : Dir.pwd
10
+ end
11
+
12
+ def do_serve
13
+ case GitBro::TARGET_OS
14
+ when 'mswin32'
15
+ Process::create("ruby #{@options.gem_path}/bin/server.rb #{@options.repo_path}")
16
+ when 'linux'
17
+ system "/usr/bin/env ruby #{@options.gem_path}/bin/server.rb #{@options.repo_path}"
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,14 @@
1
+ # module GitBro
2
+ # module Command
3
+ # def command_arguments_valid?
4
+ # end
5
+ #
6
+ # def command_process_arguments
7
+ # end
8
+ #
9
+ # def do_command
10
+ # end
11
+ # end
12
+ # end
13
+
14
+ require 'git-bro/commands/serve'
@@ -0,0 +1,28 @@
1
+ require 'windows/process'
2
+ require 'windows/handle'
3
+
4
+ module Process
5
+ VERSION = '0.0.1'
6
+
7
+ extend Windows::Process
8
+ extend Windows::Handle
9
+
10
+ def self.create(cmdline, opts = {:close_handles => true})
11
+ startinfo = Array.new(18,0).pack("LLLLLLLLLLLLSSLLLL")
12
+ startinfo[0,4] = [startinfo.size].pack("L")
13
+
14
+ pi = Array.new(4,0).pack("LLLL")
15
+
16
+ res = CreateProcess(0, cmdline, 0, 0, FALSE, 0, 0, 0, startinfo, pi)
17
+
18
+ unless res
19
+ puts 'Start process failed!'
20
+ return
21
+ end
22
+
23
+ if opts[:close_handles]
24
+ CloseHandle(pi[0,4].unpack("L").first)
25
+ CloseHandle(pi[4,4].unpack("L").first)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,81 @@
1
+ require 'grit'
2
+
3
+ module GitBro
4
+ class Repository
5
+ attr_reader :name
6
+
7
+ def initialize(repo_path)
8
+ @repo = Grit::Repo.new(repo_path)
9
+ @name = @repo.path.split('/')[-2]
10
+ end
11
+
12
+ def path
13
+ @repo.path.gsub('.git','')
14
+ end
15
+
16
+ def file_content(branch, filepath)
17
+ blobs = @repo.tree(branch, [].push(filepath)).blobs
18
+ if blobs.size != 1
19
+ return 'FILE NOT FOUND'
20
+ end
21
+
22
+ blobs.first.data
23
+ end
24
+
25
+ def tree(branch, paths)
26
+ objs = []
27
+ cur_time = Time.now
28
+ paths.empty? ? prefix = "" : prefix = paths.first
29
+
30
+ @repo.tree(branch, paths).trees.each do |t|
31
+ lc = last_commit(branch, prefix + t.basename)
32
+ objs << {
33
+ :type => 'dir',
34
+ :name => t.basename + '/',
35
+ :sha => t.id,
36
+ :author => lc.author.name,
37
+ :date => relative(cur_time - lc.date, lc.date),
38
+ :message => shortify(lc.message)
39
+ }
40
+ end
41
+ @repo.tree(branch, paths).blobs.each do |b|
42
+ lc = last_commit(branch, prefix + b.basename)
43
+ objs << {
44
+ :type => 'file',
45
+ :name => b.basename,
46
+ :sha => b.id,
47
+ :author => lc.author.name,
48
+ :date => relative(cur_time - lc.date, lc.date),
49
+ :message => shortify(lc.message)
50
+ }
51
+ end
52
+
53
+ objs
54
+ end
55
+
56
+ def branches
57
+ @repo.heads
58
+ end
59
+
60
+ protected
61
+ # TODO: Check what returns log function if there is dir and file with equal names
62
+ def last_commit(branch, filename)
63
+ lc = @repo.log(branch, filename, {:n => 1})
64
+ lc.empty? ? nil : lc.first
65
+ end
66
+
67
+ def shortify(s)
68
+ s.length > 40 ? s[0..38] + '...' : s
69
+ end
70
+
71
+ def relative(diff, orig)
72
+ return "#{diff.to_i} seconds ago" if diff < 60
73
+ return "#{(diff/60).to_i} minutes ago" if diff < 3600
74
+ return "#{(diff/3600).to_i} hours ago" if diff < 86400
75
+ return "#{(diff/86400).to_i} days ago" if diff < 604800
76
+
77
+ orig.strftime("%B %d, %Y")
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,32 @@
1
+ helpers do
2
+ def partial(template, options = {})
3
+ haml template, options.merge!(:layout => false)
4
+ end
5
+
6
+ def render_path(p, branch)
7
+ path_parts = p.split('/')
8
+ url_prefix = "/tree/#{branch}"
9
+
10
+ repository_name = path_parts.delete_at(0)
11
+ haml_tag :span do
12
+ haml_tag :a, repository_name, {:href => url_prefix, :id => "repo-name"}
13
+ end
14
+ haml_tag :span, "/"
15
+
16
+ unless path_parts.empty?
17
+ url_prefix += '/'
18
+ last_part = path_parts.delete_at(-1)
19
+
20
+ path_parts.each do |i|
21
+ url_prefix += "#{i}/"
22
+ haml_tag :span do
23
+ haml_tag :a, i, {:href => url_prefix}
24
+ end
25
+ haml_tag :span, "/"
26
+ end
27
+
28
+ haml_tag :span, last_part
29
+ end
30
+
31
+ end
32
+ end
data/lib/git-bro.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'git-bro/repository'
2
+
3
+ module GitBro
4
+ VERSION = "0.1.0"
5
+ end
data/rakefile.rb ADDED
@@ -0,0 +1,29 @@
1
+ $:.unshift("lib")
2
+ require "git-bro"
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |s|
7
+ s.version = GitBro::VERSION
8
+ s.name = 'git-bro'
9
+ s.executables = "git-bro"
10
+ s.summary = "Serve and browse your Git repositories"
11
+ s.description = "Git-bro provides tools to serve your Git repositories"
12
+ s.email = "dmtmax@gmail.com"
13
+ s.homepage = "http://github.com/kolo/git-bro"
14
+ s.authors = ["Dmitry Maksimov"]
15
+ s.files = FileList["[a-z]*", "[A-Z]*", "{bin,docs,lib,test}/**/*"]
16
+ s.add_dependency "grit"
17
+ s.add_dependency "sinatra"
18
+ end
19
+ rescue LoadError
20
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ desc 'Builds gem, uninstall old one, install new version'
24
+ task :reinstall do
25
+ system("rake build")
26
+ system("sudo gem uninstall -x git-bro")
27
+ system("sudo gem install --no-ri --no-rdoc pkg/git-bro-#{GitBro::VERSION}.gem")
28
+ end
29
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-bro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Maksimov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-04 00:00:00 +03:00
13
+ default_executable: git-bro
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: grit
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: sinatra
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Git-bro provides tools to serve your Git repositories
36
+ email: dmtmax@gmail.com
37
+ executables:
38
+ - git-bro
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ files:
44
+ - README
45
+ - bin/git-bro
46
+ - bin/public/images/file.png
47
+ - bin/public/images/folder.png
48
+ - bin/server.rb
49
+ - bin/short_help.txt
50
+ - bin/views/application.sass
51
+ - bin/views/dir.haml
52
+ - bin/views/dir_listing.haml
53
+ - bin/views/file_content.haml
54
+ - bin/views/index.haml
55
+ - bin/views/layout.haml
56
+ - git-bro.gemspec
57
+ - lib/git-bro.rb
58
+ - lib/git-bro/commands.rb
59
+ - lib/git-bro/commands/serve.rb
60
+ - lib/git-bro/process.rb
61
+ - lib/git-bro/repository.rb
62
+ - lib/git-bro/sinatra/helpers.rb
63
+ - rakefile.rb
64
+ has_rdoc: true
65
+ homepage: http://github.com/kolo/git-bro
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options:
70
+ - --charset=UTF-8
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.5
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Serve and browse your Git repositories
92
+ test_files: []
93
+