Class: Giticious::Cli::Main

Inherits:
Thor
  • Object
show all
Defined in:
lib/giticious/cli/main.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



13
14
15
16
17
18
19
20
21
# File 'lib/giticious/cli/main.rb', line 13

def check
  begin
    Giticious::Check.run
    puts "Everything looks fine!"
  rescue => e
    $stderr.puts e.message
    exit 1
  end
end

#gitserve(user) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/giticious/cli/main.rb', line 34

def gitserve(user)
  abort unless user
  abort if ENV["SSH_ORIGINAL_COMMAND"].nil?

  command_match = ENV["SSH_ORIGINAL_COMMAND"].match(/(git\-upload\-pack|git\-receive\-pack) \'([A-Za-z0-9\-_\.]+)\.git\'/)
  abort "Project not found / Command invalid" if command_match.nil?

  action = command_match[1]
  repo = command_match[2]
  perms = Giticious::Service::Repository.new.permissions_for(repo, user)        
  abort "You have no access to #{repo}" if perms == false

  command = "#{command_match[1]} 'repositories/#{command_match[2]}.git'"

  abort "Read access denied" unless perms.perm_read

  if action == "git-receive-pack"
    abort "Write access denied" unless perms.perm_write
  end

  Kernel.exec "git", "shell", "-c", command
end

#initObject



24
25
26
27
28
29
30
31
# File 'lib/giticious/cli/main.rb', line 24

def init
  begin
    Giticious::Setup.run
  rescue => e
    $stderr.puts e.message
    exit 1
  end
end

#versionObject



7
8
9
10
# File 'lib/giticious/cli/main.rb', line 7

def version
  puts "Giticious: #{Giticious::VERSION}"
  puts "Ruby: #{RUBY_VERSION}"
end