Module: GitCrecord::Git
- Defined in:
- lib/git_crecord/git.rb
Class Method Summary collapse
- ._stage(diff, reverse = false) ⇒ Object
- .add_file(file) ⇒ Object
- .add_file_full(file) ⇒ Object
- .branch ⇒ Object
- .commit ⇒ Object
- .diff(filename: nil, staged: false) ⇒ Object
- .reset_file(file) ⇒ Object
- .stage(file) ⇒ Object
- .stage_files(files, reverse = false) ⇒ Object
- .status ⇒ Object
- .tab ⇒ Object
- .toplevel_dir ⇒ Object
- .unstage(file) ⇒ Object
Class Method Details
._stage(diff, reverse = false) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/git_crecord/git.rb', line 33 def self._stage(diff, reverse = false) cmd = "git apply --cached --unidiff-zero #{reverse ? '-R' : ''} - " content, status = Open3.capture2e(cmd, stdin_data: diff) LOGGER.info(cmd) LOGGER.info(diff) LOGGER.info(diff.lines.size) LOGGER.info('stdout/stderr:') LOGGER.info(content) LOGGER.info("return code: #{status}") status.success? end |
.add_file(file) ⇒ Object
45 46 47 |
# File 'lib/git_crecord/git.rb', line 45 def self.add_file(file) system("git add -N #{file.filename_a}") end |
.add_file_full(file) ⇒ Object
49 50 51 |
# File 'lib/git_crecord/git.rb', line 49 def self.add_file_full(file) system("git add #{file.filename_a}") end |
.branch ⇒ Object
75 76 77 |
# File 'lib/git_crecord/git.rb', line 75 def self.branch `git rev-parse --abbrev-ref HEAD`.chomp end |
.commit ⇒ Object
61 62 63 |
# File 'lib/git_crecord/git.rb', line 61 def self.commit exec('git commit') end |
.diff(filename: nil, staged: false) ⇒ Object
65 66 67 68 69 |
# File 'lib/git_crecord/git.rb', line 65 def self.diff(filename: nil, staged: false) filename = "'#{filename}'" if filename staged_option = staged ? '--staged' : '' `git diff --no-ext-diff --no-color -D #{staged_option} #{filename}` end |
.reset_file(file) ⇒ Object
53 54 55 |
# File 'lib/git_crecord/git.rb', line 53 def self.reset_file(file) system("git reset -q #{file.filename_a}") end |
.stage(file) ⇒ Object
21 22 23 |
# File 'lib/git_crecord/git.rb', line 21 def self.stage(file) _stage(file.generate_diff, false) end |
.stage_files(files, reverse = false) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/git_crecord/git.rb', line 8 def self.stage_files(files, reverse = false) method_name = reverse ? :unstage_steps : :stage_steps success = true files.each do |file| next unless file.selected file.send(method_name).each do |step| success &&= send(step, file) end end success end |
.status ⇒ Object
57 58 59 |
# File 'lib/git_crecord/git.rb', line 57 def self.status `git status --porcelain --untracked-files=all` end |
.tab ⇒ Object
79 80 81 |
# File 'lib/git_crecord/git.rb', line 79 def self.tab @tab ||= ' ' * [2, `git config crecord.tabwidth`.to_i].max end |
.toplevel_dir ⇒ Object
71 72 73 |
# File 'lib/git_crecord/git.rb', line 71 def self.toplevel_dir `git rev-parse --show-toplevel`.chomp end |
.unstage(file) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/git_crecord/git.rb', line 25 def self.unstage(file) success = _stage(file.generate_diff, true) return false unless success return true unless file.type == :new && file.selected == true reset_file(file) end |