lib/git/whence.rb in git-whence-0.1.1 vs lib/git/whence.rb in git-whence-0.1.2

- old
+ new

@@ -48,15 +48,22 @@ remotes = sh("git remote -v").split("\n") remotes.detect { |l| l.start_with?("origin\t") }.split(" ")[1] end def find_merge(commit) - find_merge_simple(commit, "HEAD") || + commit, merge = find_merge_simple(commit, "HEAD") || find_merge_simple(commit, "master") || find_merge_fuzzy(commit, "master") + + 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) + end + def find_merge_fuzzy(commit, branch) if similar = find_similar(commit, branch) find_merge_simple(similar, branch) end end @@ -70,10 +77,10 @@ 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 unless result.strip.empty? + [commit, result] unless result.strip.empty? end def sh(command) result = `#{command}` raise unless $?.success?