Add git thaw/freeze to depot_tools.
R=agable@chromium.org, hinoka@chromium.org, stip@chromium.org, szager@chromium.org BUG=261738 Review URL: https://codereview.chromium.org/181043018 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@256778 0039d316-1c4b-4281-b951-d872f2087c98experimental/szager/collated-output
parent
a112f03fcf
commit
97345ebf1a
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright 2014 The Chromium Authors. All rights reserved.
|
||||||
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
|
# found in the LICENSE file.
|
||||||
|
|
||||||
|
# git_freezer.py freeze -- a git-command to suspend all existing working
|
||||||
|
# directory modifications. This can be reversed with the 'git thaw' command.
|
||||||
|
|
||||||
|
SCRIPT=git_freezer.py
|
||||||
|
set -- freeze "$@"
|
||||||
|
. $(type -P python_git_runner.sh)
|
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright 2014 The Chromium Authors. All rights reserved.
|
||||||
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
|
# found in the LICENSE file.
|
||||||
|
|
||||||
|
# git_freezer.py thaw -- a git-command to reverse the effect of the 'git freeze'
|
||||||
|
# command. Any changes suspended on this branch with the freeze command will be
|
||||||
|
# restored to the state they were in immediately prior to running the freeze
|
||||||
|
# command.
|
||||||
|
|
||||||
|
SCRIPT=git_freezer.py
|
||||||
|
set -- thaw "$@"
|
||||||
|
. $(type -P python_git_runner.sh)
|
@ -0,0 +1,73 @@
|
|||||||
|
#!/usr/local/bin/python
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
import optparse
|
||||||
|
|
||||||
|
import subcommand
|
||||||
|
import subprocess2
|
||||||
|
|
||||||
|
from git_common import run, stream
|
||||||
|
|
||||||
|
FREEZE = 'FREEZE'
|
||||||
|
SECTIONS = {
|
||||||
|
'indexed': 'soft',
|
||||||
|
'unindexed': 'mixed'
|
||||||
|
}
|
||||||
|
MATCHER = re.compile(r'%s.(%s)' % (FREEZE, '|'.join(SECTIONS)))
|
||||||
|
|
||||||
|
|
||||||
|
def freeze():
|
||||||
|
took_action = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
run('commit', '-m', FREEZE + '.indexed')
|
||||||
|
took_action = True
|
||||||
|
except subprocess2.CalledProcessError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
run('add', '-A')
|
||||||
|
run('commit', '-m', FREEZE + '.unindexed')
|
||||||
|
took_action = True
|
||||||
|
except subprocess2.CalledProcessError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not took_action:
|
||||||
|
return 'Nothing to freeze.'
|
||||||
|
|
||||||
|
|
||||||
|
def thaw():
|
||||||
|
took_action = False
|
||||||
|
for sha in (s.strip() for s in stream('rev-list', 'HEAD').xreadlines()):
|
||||||
|
msg = run('show', '--format=%f%b', '-s', 'HEAD')
|
||||||
|
match = MATCHER.match(msg)
|
||||||
|
if not match:
|
||||||
|
if not took_action:
|
||||||
|
return 'Nothing to thaw.'
|
||||||
|
break
|
||||||
|
|
||||||
|
run('reset', '--' + SECTIONS[match.group(1)], sha)
|
||||||
|
took_action = True
|
||||||
|
|
||||||
|
|
||||||
|
def CMDfreeze(parser, args): # pragma: no cover
|
||||||
|
"""Freeze a branch's changes."""
|
||||||
|
parser.parse_args(args)
|
||||||
|
return freeze()
|
||||||
|
|
||||||
|
|
||||||
|
def CMDthaw(parser, args): # pragma: no cover
|
||||||
|
"""Returns a frozen branch to the state before it was frozen."""
|
||||||
|
parser.parse_args(args)
|
||||||
|
return thaw()
|
||||||
|
|
||||||
|
|
||||||
|
def main(): # pragma: no cover
|
||||||
|
dispatcher = subcommand.CommandDispatcher(__name__)
|
||||||
|
ret = dispatcher.execute(optparse.OptionParser(), sys.argv[1:])
|
||||||
|
if ret:
|
||||||
|
print ret
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__': # pragma: no cover
|
||||||
|
main()
|
@ -0,0 +1,99 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# Copyright 2014 The Chromium Authors. All rights reserved.
|
||||||
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
|
# found in the LICENSE file.
|
||||||
|
|
||||||
|
"""Unit tests for git_freezer.py"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
DEPOT_TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
sys.path.insert(0, DEPOT_TOOLS_ROOT)
|
||||||
|
|
||||||
|
from testing_support import coverage_utils
|
||||||
|
from testing_support import git_test_utils
|
||||||
|
|
||||||
|
|
||||||
|
class GitFreezeThaw(git_test_utils.GitRepoReadWriteTestBase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super(GitFreezeThaw, cls).setUpClass()
|
||||||
|
import git_freezer
|
||||||
|
cls.gf = git_freezer
|
||||||
|
|
||||||
|
REPO = """
|
||||||
|
A B C D
|
||||||
|
B E D
|
||||||
|
"""
|
||||||
|
|
||||||
|
COMMIT_A = {
|
||||||
|
'some/files/file1': {'data': 'file1'},
|
||||||
|
'some/files/file2': {'data': 'file2'},
|
||||||
|
'some/files/file3': {'data': 'file3'},
|
||||||
|
'some/other/file': {'data': 'otherfile'},
|
||||||
|
}
|
||||||
|
|
||||||
|
COMMIT_C = {
|
||||||
|
'some/files/file2': {
|
||||||
|
'mode': 0755,
|
||||||
|
'data': 'file2 - vanilla'},
|
||||||
|
}
|
||||||
|
|
||||||
|
COMMIT_E = {
|
||||||
|
'some/files/file2': {'data': 'file2 - merged'},
|
||||||
|
}
|
||||||
|
|
||||||
|
COMMIT_D = {
|
||||||
|
'some/files/file2': {'data': 'file2 - vanilla\nfile2 - merged'},
|
||||||
|
}
|
||||||
|
|
||||||
|
def testNothing(self):
|
||||||
|
self.assertIsNotNone(self.repo.run(self.gf.thaw)) # 'Nothing to thaw'
|
||||||
|
self.assertIsNotNone(self.repo.run(self.gf.freeze)) # 'Nothing to freeze'
|
||||||
|
|
||||||
|
def testAll(self):
|
||||||
|
def inner():
|
||||||
|
with open('some/files/file2', 'a') as f2:
|
||||||
|
print >> f2, 'cool appended line'
|
||||||
|
os.mkdir('some/other_files')
|
||||||
|
with open('some/other_files/subdir_file', 'w') as f3:
|
||||||
|
print >> f3, 'new file!'
|
||||||
|
with open('some/files/file5', 'w') as f5:
|
||||||
|
print >> f5, 'New file!1!one!'
|
||||||
|
|
||||||
|
STATUS_1 = '\n'.join((
|
||||||
|
' M some/files/file2',
|
||||||
|
'A some/files/file5',
|
||||||
|
'?? some/other_files/'
|
||||||
|
)) + '\n'
|
||||||
|
|
||||||
|
self.repo.git('add', 'some/files/file5')
|
||||||
|
|
||||||
|
# Freeze group 1
|
||||||
|
self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1)
|
||||||
|
self.assertIsNone(self.gf.freeze())
|
||||||
|
self.assertEquals(self.repo.git('status', '--porcelain').stdout, '')
|
||||||
|
|
||||||
|
# Freeze group 2
|
||||||
|
with open('some/files/file2', 'a') as f2:
|
||||||
|
print >> f2, 'new! appended line!'
|
||||||
|
self.assertEquals(self.repo.git('status', '--porcelain').stdout,
|
||||||
|
' M some/files/file2\n')
|
||||||
|
self.assertIsNone(self.gf.freeze())
|
||||||
|
self.assertEquals(self.repo.git('status', '--porcelain').stdout, '')
|
||||||
|
|
||||||
|
# Thaw it out!
|
||||||
|
self.assertIsNone(self.gf.thaw())
|
||||||
|
self.assertIsNotNone(self.gf.thaw()) # One thaw should thaw everything
|
||||||
|
|
||||||
|
self.assertEquals(self.repo.git('status', '--porcelain').stdout, STATUS_1)
|
||||||
|
|
||||||
|
self.repo.run(inner)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(coverage_utils.covered_main(
|
||||||
|
os.path.join(DEPOT_TOOLS_ROOT, 'git_freezer.py')
|
||||||
|
))
|
Loading…
Reference in New Issue