-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-zip
executable file
·42 lines (33 loc) · 1010 Bytes
/
git-zip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env ruby
# encoding: utf-8
path = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
require File.join(File.dirname(File.expand_path(path)), "console/colorize.rb")
class Zip
include Console::Colorize
INFO = "Create package from your repository\nUsage: git zip PATH"
def initialize(args)
if args.length == 0
puts INFO
exit
end
@path, _ = args
end
def run
# print all files in git changelist
list_of_untracked_files = `git status --untracked-files=no -s`
# for non-empty list
(list_of_untracked_files.length == 0) ? head(@path) : stash(@path)
end
def stash(path)
puts blue{ 'Building from modified repository' }
puts `git status --untracked-files=no -sb`
`git archive --format zip --output "#{path}" \`git stash create\``
end
private :stash
def head(path)
puts green{ 'Building from updated repository' }
`git archive --format zip --output "#{path}" HEAD`
end
private :head
end
Zip.new(ARGV).run