Created
August 18, 2015 08:50
-
-
Save cyocun/b1f9822178bee071915b to your computer and use it in GitHub Desktop.
差分抽出
fork:https://gist.github.com/ahomu/863857
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby -Ku | |
| require 'fileutils' | |
| # つかいかた | |
| if ARGV.length == 0 | |
| print "[Usage?] $ git_diff [from SHA] [to SHA]\n" | |
| exit(false) | |
| end | |
| # 引数が足りないよ | |
| if ARGV.length != 2 | |
| print "[Error!] Arguments are not worth." | |
| exit(false) | |
| end | |
| # 引数をとるよ | |
| revFrom = ARGV[0] | |
| revTo = ARGV[1] | |
| dir = "./diff" | |
| # エクスポート先が確保できないよ | |
| if !File::exist?(dir) && !FileUtils.mkdir_p(dir, :mode => 0755) | |
| print "[Error!] Specified dirname is not exists & cannot mkdir.\n" | |
| exit(false) | |
| end | |
| # おしりにスラッシュ | |
| if !dir.match(/\/$/) | |
| dir += '/' | |
| end | |
| # git diffを実行 | |
| print "[ exec ] git diff --name-status #{revFrom} #{revTo}\n" | |
| lines = `git diff --name-status #{revFrom} #{revTo}` | |
| dirName = dir + Time.now.strftime("%y%m%d") + '--' + revFrom + '_' + revTo; | |
| # 削除リスト | |
| killnote = [] | |
| # 1行ずつ処理 | |
| lines.each_line do |line| | |
| line = line.sub(/\n$/, '') | |
| status = line.slice!(/^[ADM]{1}\s+/).sub(/\s+/, '') | |
| # D のとき | |
| if status == 'D' | |
| killnote.push(line) | |
| # A, M のとき | |
| else | |
| from = line.sub(/\n$/, '') | |
| to = dirName + '/' + from | |
| dirname = File::dirname(to) | |
| # すでに存在するディレクトリは無視 | |
| if File::exist?(dirname) | |
| #print "[notice] This dir(#{dirname}) was already created.\n" | |
| # いずれにも該当しなければ作成 | |
| else | |
| # print "[ mkdir] #{dirname}\n" | |
| FileUtils.mkdir_p(dirname) | |
| end | |
| # ファイルをコピー | |
| if File::exist?(from) | |
| # print "[ copy ] #{from} => #{to}\n" | |
| FileUtils.cp(from, to) | |
| end | |
| end | |
| end | |
| # デスノート ...〆(.. ) | |
| if killnote != [] | |
| print "[remove] Please check '__REMOVE_US__.txt' and delete them.\n" | |
| F = open(dirName+'__REMOVE_US__.txt', 'w') do |f| | |
| f.puts killnote.join("\n") | |
| end | |
| end | |
| print "\n ---end process\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment