Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index 9961f7eded13d5c99639d73ef618a80fa7a36fb3..d13b948f35310f3c1f50b20e4d5fe9553441c0f6 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -2524,21 +2524,25 @@ def GerritUpload(options, args, cl, change): |
| branch = GetTargetRef(remote, remote_branch, options.target_branch, |
| pending_prefix='') |
| - change_desc = ChangeDescription( |
| - options.message or CreateDescriptionFromLog(args)) |
| - if not change_desc.description: |
| - print "\nDescription is empty. Aborting..." |
| - return 1 |
| - |
| if options.title: |
| print "\nPatch titles (-t) are not supported in Gerrit. Aborting..." |
| return 1 |
| if options.squash: |
| - # Try to get the message from a previous upload. |
| - shadow_branch = 'refs/heads/git_cl_uploads/' + cl.GetBranch() |
| - message = RunGitSilent(['show', '--format=%B', '-s', shadow_branch]) |
| - if not message: |
| + if cl.GetIssue(): |
| + # Try to get the message from a previous upload. |
| + message = cl.GetDescription() |
| + if not message: |
| + DieWithError( |
| + 'failed to fetch description from current Gerrit issue %d\n' |
| + '%s' % (cl.GetIssue(), cl.GetIssueURL())) |
| + # Issues already on Gerrit really must have exactly 1 Change-Id. |
|
Bernhard Bauer
2016/03/29 08:22:49
In practice this could fail (e.g. an old CL that w
tandrii(chromium)
2016/03/29 08:37:41
Didn't know it was possible, but let's assume so.
Bernhard Bauer
2016/03/29 09:03:21
If a commit is pushed that doesn't have a Change-I
tandrii(chromium)
2016/03/29 13:06:24
Ah, i see.
|
| + change_ids = git_footers.get_footer_change_id(message) |
| + assert len(change_ids) == 1 |
| + change_desc = ChangeDescription(message) |
| + else: |
| + change_desc = ChangeDescription( |
| + options.message or CreateDescriptionFromLog(args)) |
| if not options.force: |
| change_desc.prompt() |
| if not change_desc.description: |
| @@ -2547,29 +2551,35 @@ def GerritUpload(options, args, cl, change): |
| message = change_desc.description |
| change_ids = git_footers.get_footer_change_id(message) |
| if len(change_ids) > 1: |
| - DieWithError('too many Change-Id footers in %s branch' % shadow_branch) |
| + DieWithError('too many Change-Id footers, at most 1 allowed.') |
| if not change_ids: |
| + # Generate the Change-Id automatically. |
| message = git_footers.add_footer_change_id( |
| message, GenerateGerritChangeId(message)) |
| change_desc.set_description(message) |
| change_ids = git_footers.get_footer_change_id(message) |
| assert len(change_ids) == 1 |
| - |
| - change_id = change_ids[0] |
| + change_id = change_ids[0] |
| remote, upstream_branch = cl.FetchUpstreamTuple(cl.GetBranch()) |
| if remote is '.': |
| # If our upstream branch is local, we base our squashed commit on its |
| # squashed version. |
| - parent = ('refs/heads/git_cl_uploads/' + |
| - scm.GIT.ShortBranchName(upstream_branch)) |
| - |
| - # Verify that the upstream branch has been uploaded too, otherwise Gerrit |
| - # will create additional CLs when uploading. |
| - if (RunGitSilent(['rev-parse', upstream_branch + ':']) != |
| - RunGitSilent(['rev-parse', parent + ':'])): |
| - print 'Upload upstream branch ' + upstream_branch + ' first.' |
| - return 1 |
| + upstream_branch_name = scm.GIT.ShortBranchName(upstream_branch) |
| + # Check the squashed hash of the parent. |
| + parent = RunGit(['config', |
| + 'branch.%s.gerritsquashhash' % upstream_branch_name], |
| + error_ok=True).strip() |
| + # Verify that the upstream branch has been uploaded too, otherwise |
| + # Gerrit will create additional CLs when uploading. |
| + if not parent or (RunGitSilent(['rev-parse', upstream_branch + ':']) != |
| + RunGitSilent(['rev-parse', parent + ':'])): |
| + # TODO(tandrii): remove "old depot_tools" part on April 12, 2016. |
| + DieWithError( |
| + 'Upload upstream branch %s first.\n' |
| + 'Note: maybe you\'ve uploaded it with --no-squash or with old\n' |
|
Bernhard Bauer
2016/03/29 08:22:49
Nit: "[...] with an old version [...]".
tandrii(chromium)
2016/03/29 13:06:24
Done.
|
| + ' version of depot_tools. If so, then re-upload it with:\n' |
| + ' git cl upload --squash\n' % upstream_branch_name) |
| else: |
| parent = cl.GetCommonAncestorWithUpstream() |
| @@ -2577,6 +2587,12 @@ def GerritUpload(options, args, cl, change): |
| ref_to_push = RunGit(['commit-tree', tree, '-p', parent, |
| '-m', message]).strip() |
| else: |
| + change_desc = ChangeDescription( |
| + options.message or CreateDescriptionFromLog(args)) |
| + if not change_desc.description: |
| + print "\nDescription is empty. Aborting..." |
|
ukai
2016/03/29 02:16:16
nit: DieWithError?
what is difference between Die
tandrii(chromium)
2016/03/29 08:37:41
Same thing, afaiu. This was copy-paste from above,
tandrii(chromium)
2016/03/29 13:06:24
Done.
|
| + return 1 |
| + |
| if not git_footers.get_footer_change_id(change_desc.description): |
| DownloadGerritHook(False) |
| change_desc.set_description(AddChangeIdToCommitMessage(options, args)) |
| @@ -2584,6 +2600,7 @@ def GerritUpload(options, args, cl, change): |
| parent = '%s/%s' % (gerrit_remote, branch) |
| change_id = git_footers.get_footer_change_id(change_desc.description)[0] |
| + assert change_desc |
| commits = RunGitSilent(['rev-list', '%s..%s' % (parent, |
| ref_to_push)]).splitlines() |
| if len(commits) > 1: |
| @@ -2630,8 +2647,8 @@ def GerritUpload(options, args, cl, change): |
| ('Created|Updated %d issues on Gerrit, but only 1 expected.\n' |
| 'Change-Id: %s') % (len(change_numbers), change_id)) |
| cl.SetIssue(change_numbers[0]) |
| - head = RunGit(['rev-parse', 'HEAD']).strip() |
| - RunGit(['update-ref', '-m', 'Uploaded ' + head, shadow_branch, ref_to_push]) |
| + RunGit(['config', 'branch.%s.gerritsquashhash' % cl.GetBranch(), |
| + ref_to_push]) |
| return 0 |
| @@ -2922,6 +2939,9 @@ def CMDupload(parser, args): |
| options.reviewers = cleanup_list(options.reviewers) |
| options.cc = cleanup_list(options.cc) |
| + # For sanity of test expectations, do this otherwise lazy-loading *now*. |
| + settings.GetIsGerrit() |
| + |
| cl = Changelist(auth_config=auth_config) |
| if args: |
| # TODO(ukai): is it ok for gerrit case? |