lib/git/whence.rb in git-whence-0.1.2 vs lib/git/whence.rb in git-whence-0.1.3
- old
+ new
@@ -10,10 +10,12 @@
unless system("git rev-parse --git-dir 2>&1 >/dev/null")
puts "Not in a git directory"
return 1
end
+ commit = expand(commit)
+
if is_merge?(commit)
$stderr.puts "Commit is a merge"
finished_with_commit(commit, options)
1
else
@@ -28,10 +30,14 @@
end
end
private
+ def expand(commit)
+ sh("git show #{commit} -s --format='%H'").strip
+ end
+
def is_merge?(commit)
sh("git cat-file -p #{commit}").split("\n")[1..2].grep(/parent /).size > 1
end
def finished_with_commit(merge, options)
@@ -56,12 +62,12 @@
merge if merge && merge_include_commit?(merge, commit)
end
def merge_include_commit?(merge, commit)
- commit = sh("git show HEAD -s --format=%h").strip if commit == "HEAD"
- sh("git log #{merge.strip}^..#{merge.strip} --pretty=%h").split("\n").include?(commit)
+ commit = sh("git show HEAD -s --format=%H").strip if commit == "HEAD"
+ sh("git log #{merge.strip}^..#{merge.strip} --pretty=%H").split("\n").include?(commit)
end
def find_merge_fuzzy(commit, branch)
if similar = find_similar(commit, branch)
find_merge_simple(similar, branch)
@@ -70,16 +76,16 @@
def find_similar(commit, branch)
month = 30 * 24 * 60 * 60
time, search = sh("git show -s --format='%ct %an %s' #{commit}").strip.split(" ", 2)
time = time.to_i
- same = sh("git log #{branch} --pretty=format:'%h %an %s' --before #{time + month} --after #{time - month}")
+ same = sh("git log #{branch} --pretty=format:'%H %an %s' --before #{time + month} --after #{time - month}")
found = same.split("\n").map { |x| x.split(" ", 2) }.detect { |commit, message| message == search }
found && found.first
end
def find_merge_simple(commit, branch)
- result = sh "git log #{commit}..#{branch} --ancestry-path --merges --pretty='%h' 2>/dev/null | tail -n 1"
+ result = sh "git log #{commit}..#{branch} --ancestry-path --merges --pretty='%H' 2>/dev/null | tail -n 1"
[commit, result] unless result.strip.empty?
end
def sh(command)
result = `#{command}`