Skip to content

Instantly share code, notes, and snippets.

@ekimekim
Last active December 31, 2015 21:39
Show Gist options
  • Save ekimekim/8048731 to your computer and use it in GitHub Desktop.
Save ekimekim/8048731 to your computer and use it in GitHub Desktop.
Pulls every change ref from gerrit remote (TODO: configurable remote), and assigns latest patch to refs/changes/CHANGE_ID
#!/bin/env python
import sys
from subprocess import check_call as cmd
from subprocess import check_output as cmd_out
from subprocess import CalledProcessError
out = cmd_out(['git', 'ls-remote', 'origin'])
refs = [line.split("\t") for line in out.strip().split("\n")]
changes = {}
for commit, ref in refs:
if '/changes/' not in ref: continue
change_id = ref.split("/")[3] # refs/changes/??/CHANGE_ID/PATCH_NO
changes[change_id] = commit
fetch_args = [':'.join([commit, "refs/changes/%s" % change_id]) for change_id, commit in changes.items()]
cmd(['git', 'fetch', 'origin'] + fetch_args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment