chore: save HEAD when git-import-patches runs (#17824)
This commit is contained in:
parent
f901170a4f
commit
fdaa75354a
3 changed files with 41 additions and 8 deletions
|
@ -9,6 +9,27 @@ import sys
|
||||||
|
|
||||||
def guess_base_commit(repo):
|
def guess_base_commit(repo):
|
||||||
"""Guess which commit the patches might be based on"""
|
"""Guess which commit the patches might be based on"""
|
||||||
|
try:
|
||||||
|
args = [
|
||||||
|
'git',
|
||||||
|
'-C',
|
||||||
|
repo,
|
||||||
|
'rev-parse',
|
||||||
|
'--verify',
|
||||||
|
'refs/patches/upstream-head',
|
||||||
|
]
|
||||||
|
upstream_head = subprocess.check_output(args).strip()
|
||||||
|
args = [
|
||||||
|
'git',
|
||||||
|
'-C',
|
||||||
|
repo,
|
||||||
|
'rev-list',
|
||||||
|
'--count',
|
||||||
|
upstream_head + '..',
|
||||||
|
]
|
||||||
|
num_commits = subprocess.check_output(args).strip()
|
||||||
|
return [upstream_head, num_commits]
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
args = [
|
args = [
|
||||||
'git',
|
'git',
|
||||||
'-C',
|
'-C',
|
||||||
|
|
|
@ -17,6 +17,12 @@ def main(argv):
|
||||||
help="use 3-way merge to resolve conflicts")
|
help="use 3-way merge to resolve conflicts")
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
|
# save the upstream HEAD so we can refer to it when we later export patches
|
||||||
|
git.update_ref(
|
||||||
|
repo='.',
|
||||||
|
ref='refs/patches/upstream-head',
|
||||||
|
newvalue='HEAD'
|
||||||
|
)
|
||||||
git.am(
|
git.am(
|
||||||
repo='.',
|
repo='.',
|
||||||
patch_data=patch_from_dir(args.patch_dir),
|
patch_data=patch_from_dir(args.patch_dir),
|
||||||
|
|
|
@ -102,6 +102,12 @@ def get_head_commit(repo):
|
||||||
return subprocess.check_output(args).strip()
|
return subprocess.check_output(args).strip()
|
||||||
|
|
||||||
|
|
||||||
|
def update_ref(repo, ref, newvalue):
|
||||||
|
args = ['git', '-C', repo, 'update-ref', ref, newvalue]
|
||||||
|
|
||||||
|
return subprocess.check_call(args)
|
||||||
|
|
||||||
|
|
||||||
def reset(repo):
|
def reset(repo):
|
||||||
args = ['git', '-C', repo, 'reset']
|
args = ['git', '-C', repo, 'reset']
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue