Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Unified Diff: trychange.py

Issue 233913002: trychange.py: create patch refs in refs/patches/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: added TODO about commit-tree Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trychange.py
diff --git a/trychange.py b/trychange.py
index 8fe2b5fb17eafa0ff879d0d2bbf5bd92a515d216..d181e141baff4c312c8fd1c8343fc98c8918991c 100755
--- a/trychange.py
+++ b/trychange.py
@@ -611,7 +611,15 @@ def _GetPatchGitRepo(git_url):
def _SendChangeGit(bot_spec, options):
- """Send a change to the try server by committing a diff file to a GIT repo"""
+ """Sends a change to the try server by committing a diff file to a GIT repo.
+
+ Creates a temp orphan branch, commits patch.diff, creates a ref pointing to
+ that commit, deletes the temp branch, checks master out, adds 'ref' file
+ containing the name of the new ref, pushes master and the ref to the origin.
+
+ TODO: instead of creating a temp branch, use git-commit-tree.
+ """
+
if not options.git_repo:
raise NoTryServerAccess('Please use the --git_repo option to specify the '
'try server git repository to connect to.')
@@ -640,35 +648,50 @@ def _SendChangeGit(bot_spec, options):
with _PrepareDescriptionAndPatchFiles(description, options) as (
patch_filename, description_filename):
logging.info('Committing patch')
- target_branch = 'refs/patches/%s/%s' % (
+
+ temp_branch = 'tmp_patch'
+ target_ref = 'refs/patches/%s/%s' % (
Escape(options.user),
os.path.basename(patch_filename).replace(' ','_'))
target_filename = os.path.join(patch_dir, 'patch.diff')
branch_file = os.path.join(patch_dir, GIT_BRANCH_FILE)
+
+ patch_git('checkout', 'master')
try:
+ # Try deleting an existing temp branch, if any.
+ try:
+ patch_git('branch', '-D', temp_branch)
+ logging.debug('Deleted an existing temp branch.')
+ except subprocess2.CalledProcessError:
+ pass
# Create a new branch and put the patch there.
- patch_git('checkout', '--orphan', target_branch)
+ patch_git('checkout', '--orphan', temp_branch)
patch_git('reset')
patch_git('clean', '-f')
shutil.copyfile(patch_filename, target_filename)
add_and_commit(target_filename, description_filename)
assert not scm.GIT.IsWorkTreeDirty(patch_dir)
- # Update the branch file in the master
+ # Create a ref and point it to the commit referenced by temp_branch.
+ patch_git('update-ref', target_ref, temp_branch)
+
+ # Delete the temp ref.
patch_git('checkout', 'master')
+ patch_git('branch', '-D', temp_branch)
+ # Update the branch file in the master.
def update_branch():
with open(branch_file, 'w') as f:
- f.write(target_branch)
+ f.write(target_ref)
add_and_commit(branch_file, description_filename)
update_branch()
- # Push master and target_branch to origin.
+ # Push master and target_ref to origin.
logging.info('Pushing patch')
for attempt in xrange(_GIT_PUSH_ATTEMPTS):
try:
- patch_git('push', 'origin', 'master', target_branch)
+ patch_git('push', 'origin', 'master', target_ref)
except subprocess2.CalledProcessError as e:
is_last = attempt == _GIT_PUSH_ATTEMPTS - 1
if is_last:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698