-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-simpull
executable file
·69 lines (60 loc) · 1.69 KB
/
git-simpull
1
2
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /usr/bin/env ruby
stash = `git stash`.chomp
if $?.exitstatus != 0
print stash
puts "There was an error stashing your local changes"
system 'git status'
exit 1
end
stashed = (stash != "No local changes to save")
puts "Working tree stashed" if stashed
if ARGV[0] && `git branch --list ${ARGV[0]}`
system 'git checkout ARGV[0]'
end
puts "Pulling from remote..."
pull = `git pull -X patience --rebase --log 2>&1`
if $?.exitstatus != 0 # rebase conflict => 1
puts pull
puts "Exit code: %d" % $?.exitstatus
puts "Remember to git stash apply after fixing conflicts" if stashed
exit $?.exitstatus
else
branch = `git rev-parse --abbrev-ref HEAD`.chomp
pull.sub!(/([0-9a-f]{6,}\.\.[0-9a-f]{6,}) +#{branch} .+$/) { |m|
m + "\n" + `git --no-pager log -n40 #{$1} --pretty=format:"%Cblue %aN %Creset %s %d" --reverse`
}
# puts "New commits:"
# system 'git --no-pager log -n40 @{1}..HEAD --pretty=format:"%Cblue %aN %Creset %s %d" --reverse'
# if pull[/Committed:/]
# puts "Rebasing commits:"
# pull.scan(/Committed: (.*)/).each do |a|
# puts " " + a.join
# end
# else
puts pull
# end
end
system "git submodule --quiet update --init --recursive"
if ARGV[0] == '-t'
cmd = ARGV[1..-1]
cmd = cmd.empty? ? 'rake -t' : cmd.join(' ').gsub(', ', ' 2>&1 && ') + ' 2>&1'
puts "Running `#{cmd}`"
result = `#{cmd}`
if $?.exitstatus == 0
puts "Tests passed"
else
puts result
puts "Remember to `git stash apply` after fixing tests" if stashed
exit $?.exitstatus
end
end
if stashed
stash = `git stash pop`
if $?.exitstatus != 0
puts "Restoring working tree..."
print stash
else
puts "Restored working tree"
exec "git status"
end
end