Class: Gitup

Inherits:
Object
  • Object
show all
Defined in:
lib/gitup.rb

Class Method Summary collapse

Class Method Details

.current_branchObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/gitup.rb', line 61

def self.current_branch
 current = ''
 branches = `git branch`.split("\n")
 branches.each do |branch|
   if (branch[0, 2] == '* ')
     current = branch.gsub('* ', '').strip
   end
 end
 current
end

.everything_commited?Boolean

Do we have anything uncommitted in this repository?

Returns:

  • (Boolean)


73
74
75
# File 'lib/gitup.rb', line 73

def self.everything_commited?
  `git ls-files --deleted --modified --others --exclude-standard` == ""
end

.gitdown!Object



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
# File 'lib/gitup.rb', line 3

def self.gitdown!
  
  if on_master?
    puts "You are on the master branch. Gitdown is intended to be used in local branches."
    puts "git checkout -b yournewbranch to create a new local branch"
    puts "or git checkout yourexistingbranch to checkout an existing one."
    system "git pull origin master"
    exit
  end
  
  unless everything_commited?
    system "git status"
    puts "You have uncommitted changes in #{current_branch}. Do you want to try gitdown anyway? (y/n)"
    input = gets.chomp
    
    if input.downcase == 'y'
      system "git stash"
      run_gitdown_commands(current_branch)
      system "git stash apply"
    else
      puts "Ok... coward."
      exit
    end
    
  else
    run_gitdown_commands(current_branch)
  end
  puts "Finished."
  exit
end

.gitup!Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gitup.rb', line 34

def self.gitup!
  
  unless everything_commited?
    system "git status"
    puts "Warning: You have uncommitted changes. Continue? (y/n)"
    input = gets.chomp
    
    if input.downcase == 'y'
      # Stash the changes, do the push and then apply our stash
      system "git stash"
      self.run_gitup_commands(current_branch)      
      system "git stash apply"
    else
      puts 'Good girl.'
      exit
    end
  else
    # Push it!
    self.run_gitup_commands(current_branch)      
    exit
  end
end

.on_master?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/gitup.rb', line 57

def self.on_master?
  current_branch == 'master'
end

.run_gitdown_commands(branch) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/gitup.rb', line 92

def self.run_gitdown_commands(branch)
  puts "Branch: #{branch}"
  system "git checkout master"
  system "git pull origin master"
  system "git checkout #{branch}"
  system "git rebase master"
end

.run_gitup_commands(branch) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/gitup.rb', line 77

def self.run_gitup_commands(branch)
  puts "Branch: #{branch}"
  unless branch == 'master'
    system "git checkout master"
    system "git merge #{branch}"
  end
  system "git push origin master"
  unless branch == 'master'
    system "git checkout #{branch}"
    system "git rebase master"
  else
    puts "You should really consider doing development locally in a branch that is not the master branch."
  end
end