git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: grep open pull requests

From
Jeff King <peff@peff.net>
Date
Jan 19, 2017, 19:02 UTC
Message-ID
<20170119190227.opjisryyqn766tqy@sigill.intra.peff.net>
In-Reply-To
<276f6ed9-ff06-a00f-b88a-4d40d55c6d40@nottheoilrig.com>
On Thu, Jan 19, 2017 at 11:12:03AM -0700, Jack Bates wrote:
Show 6 quoted lines
> I have a couple questions around grepping among open pull requests.
> 
> First, "git for-each-ref --no-merged": When I run the following,
> it lists refs/pull/1112/head, even though #1112 was merged in commit
> ced4da1. I guess this is because the tip of refs/pull/1112/head is 107fc59,
> not ced4da1?
Right. Git's `--no-merged` is about commit ancestry.
Show 5 quoted lines
> This maybe shows my lack of familiarity with Git details,
> but superficially the two commits appear identical -- [1] and [2] --
> same parent, etc. Nonetheless they have different SHA-1s.
> I'm not sure why that is -- I didn't merge the commit --
> but regardless, GitHub somehow still connects ced4da1 with #1112.
The commits differ only in the committer timestamp. Try:
  diff -u <(git cat-file commit 107fc5910) \
          <(git cat-file commit ced4da132)

Is it possible that somebody cherry-pick or rebased it? Looking at the history of apache/trafficserver, I don't see any merges, which implies to me that the project is using a rebase workflow to merge PRs.

It's much trickier to find from the git topology whether a particular history contains rebased versions of commits. You can look at the --cherry options to "git log", which use patch-ids to try to equate commits. Something like:

  git for-each-ref --format='%(refname)' 'refs/pull/*/head' |
  while read refname; do
	if test -z "$(git rev-list --right-only --cherry-pick -1 origin...$refname)
	then
		echo "$refname: not merged"
	fi
  done

That's obviously much less efficient than `--no-merged`, but it should generally work. The exception is if the rebase changed the commit sufficiently that its patch-id may have changed.

> So my question is, how are they doing that,

I suspect the answer is "somebody clicked the rebase button GitHub" which simultaneously did the rebase and marked the PR as merged.

> Lastly, a question more about GitHub than Git, but: Given the way GitHub is
> setup, I hope I can get a list of unmerged pull requests from Git alone. Can
> you think of a way to list *open* pull requests,
> or is that status only available out of band?

That information isn't reflected in the git topology. It's in GitHub's database. You can ask the API:

  https://developer.github.com/v3/
There are libraries to help with that:
  https://developer.github.com/libraries/

I think that's probably the best answer to your "unmerged" question, too. Ask the API which PRs are unmerged, and then do whatever git-level analysis you want based on that.

-Peff
Previous: Jack BatesNext: Jack Bates
Message 2 of 4 in “grep open pull requests”
  1. Jack BatesJan 19, 2017
  2. Jeff KingJan 19, 2017
  3. Jack BatesJan 19, 2017
  4. Jeff KingJan 19, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.