Module: Spoom::Context::Git
Overview
Git features for a context
Instance Method Summary collapse
- #git(command) ⇒ Object
- #git_checkout!(ref: "main") ⇒ Object
- #git_commit!(message: "message", time: Time.now.utc, allow_empty: false) ⇒ Object
- #git_current_branch ⇒ Object
- #git_diff(*arg) ⇒ Object
- #git_init!(branch: nil) ⇒ Object
- #git_last_commit(short_sha: true) ⇒ Object
- #git_log(*arg) ⇒ Object
- #git_show(*arg) ⇒ Object
- #git_workdir_clean?(path: ".") ⇒ Boolean
Instance Method Details
#git(command) ⇒ Object
43 44 45 |
# File 'lib/spoom/context/git.rb', line 43 def git(command) exec("git #{command}") end |
#git_checkout!(ref: "main") ⇒ Object
62 63 64 |
# File 'lib/spoom/context/git.rb', line 62 def git_checkout!(ref: "main") git("checkout #{ref}") end |
#git_commit!(message: "message", time: Time.now.utc, allow_empty: false) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/spoom/context/git.rb', line 68 def git_commit!(message: "message", time: Time.now.utc, allow_empty: false) git("add --all") args = ["-m '#{}'", "--date '#{time}'"] args << "--allow-empty" if allow_empty exec("GIT_COMMITTER_DATE=\"#{time}\" git -c commit.gpgsign=false commit #{args.join(" ")}") end |
#git_current_branch ⇒ Object
79 80 81 82 83 84 |
# File 'lib/spoom/context/git.rb', line 79 def git_current_branch res = git("branch --show-current") return nil unless res.status res.out.strip end |
#git_diff(*arg) ⇒ Object
88 89 90 |
# File 'lib/spoom/context/git.rb', line 88 def git_diff(*arg) git("diff #{arg.join(" ")}") end |
#git_init!(branch: nil) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/spoom/context/git.rb', line 52 def git_init!(branch: nil) if branch git("init -b #{branch}") else git("init") end end |
#git_last_commit(short_sha: true) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/spoom/context/git.rb', line 94 def git_last_commit(short_sha: true) res = git_log("HEAD --format='%#{short_sha ? "h" : "H"} %at' -1") return nil unless res.status out = res.out.strip return nil if out.empty? Spoom::Git::Commit.parse_line(out) end |
#git_log(*arg) ⇒ Object
105 106 107 |
# File 'lib/spoom/context/git.rb', line 105 def git_log(*arg) git("log #{arg.join(" ")}") end |
#git_show(*arg) ⇒ Object
110 111 112 |
# File 'lib/spoom/context/git.rb', line 110 def git_show(*arg) git("show #{arg.join(" ")}") end |
#git_workdir_clean?(path: ".") ⇒ Boolean
116 117 118 |
# File 'lib/spoom/context/git.rb', line 116 def git_workdir_clean?(path: ".") git_diff("HEAD").out.empty? end |