Module: Git

Defined in:
lib/git.rb

Constant Summary collapse

@@wagon =
"wagon-branch"
@@local =
"local-branch"

Class Method Summary collapse

Class Method Details

.add_allObject

Add all local changes to be committed.



9
10
11
# File 'lib/git.rb', line 9

def self.add_all()
  Command.run("git add -A .")
end

.checkout(branch) ⇒ Object



39
40
41
# File 'lib/git.rb', line 39

def self.checkout(branch)
  Command.run("git checkout #{branch}")
end

.checkout_masterObject



43
44
45
# File 'lib/git.rb', line 43

def self.checkout_master()
  self.checkout("master")
end

.checkout_new_localObject



51
52
53
# File 'lib/git.rb', line 51

def self.checkout_new_local()
  self.checkout("-b #{@@local}")
end

.checkout_new_wagonObject



47
48
49
# File 'lib/git.rb', line 47

def self.checkout_new_wagon()
  self.checkout("-b #{@@wagon}")
end

.clean_whitespace_changesObject



103
104
105
106
# File 'lib/git.rb', line 103

def self.clean_whitespace_changes()
# git stash && git stash apply && git diff -w > ws.patch && git checkout . && git apply --ignore-space-change --ignore-whitespace ws.patch && rm ws.patch
  puts "This does nothin yet"
end

.commit(message) ⇒ Object

Git commit using provided message



23
24
25
# File 'lib/git.rb', line 23

def self.commit(message)
  Command.run("git commit -m '#{message}'")
end

.commit_promptObject

Git commit, will prompt user for commit message



15
16
17
18
19
20
# File 'lib/git.rb', line 15

def self.commit_prompt()
  return unless has_changes?
  puts "Enter a git commit message:"
  message = $stdin.gets.chomp
  self.commit(message)
end

.delete_branch(branch) ⇒ Object



55
56
57
# File 'lib/git.rb', line 55

def self.delete_branch(branch)
  Command.run("git branch -D #{branch}")
end

.delete_localObject



63
64
65
# File 'lib/git.rb', line 63

def self.delete_local()
  self.delete_branch(@@local)
end

.delete_wagonObject



59
60
61
# File 'lib/git.rb', line 59

def self.delete_wagon()
  self.delete_branch(@@wagon)
end

.has_changes?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/git.rb', line 99

def self.has_changes?()
  return !!Command.run("git ls-files -m")
end

.is_git_dir?(dir = Dir.pwd) ⇒ Boolean

Return true if the provided directory is in a git repo, otherwise false. Can optionally provide wa

Returns:

  • (Boolean)


110
111
112
113
114
# File 'lib/git.rb', line 110

def self.is_git_dir?(dir = Dir.pwd)
    return Dir.chdir dir do 
      return Command.run("git rev-parse", false)
    end
end

.merge(branch) ⇒ Object



75
76
77
# File 'lib/git.rb', line 75

def self.merge(branch)
  Command.run("git merge #{branch}")
end

.merge_localObject



83
84
85
# File 'lib/git.rb', line 83

def self.merge_local()
  self.merge(@@local)
end

.merge_wagonObject



79
80
81
# File 'lib/git.rb', line 79

def self.merge_wagon()
  self.merge(@@wagon)
end

.pullObject

Git pull



35
36
37
# File 'lib/git.rb', line 35

def self.pull()
  Command.run("git pull")
end

.pushObject

Git push



29
30
31
# File 'lib/git.rb', line 29

def self.push()
  Command.run("git push")
end

.rebase(from, to) ⇒ Object



87
88
89
# File 'lib/git.rb', line 87

def self.rebase(from, to)
  Command.run("git rebase #{} #{}")
end

.rebase_localObject



95
96
97
# File 'lib/git.rb', line 95

def self.rebase_local()
  self.rebase("master", @@local)
end

.rebase_wagonObject



91
92
93
# File 'lib/git.rb', line 91

def self.rebase_wagon()
  self.rebase("master", @@wagon)
end

.stashObject



67
68
69
# File 'lib/git.rb', line 67

def self.stash()
  Command.run("git stash")
end

.stash_popObject



71
72
73
# File 'lib/git.rb', line 71

def self.stash_pop()
  Command.run("git stash pop")
end