Commit db7e074d authored by machenbach's avatar machenbach Committed by Commit bot

Make release scripts more robust.

Remembering the current branch is a relic from the past
where no work-dir checkout was used. Now this doesn't give
much benefit and screws up the script if it was left in
a bad state (e.g. after a master restart).

TBR=tandrii@chromium.org
NOTRY=true

Review URL: https://codereview.chromium.org/1002383002

Cr-Commit-Position: refs/heads/master@{#27196}
parent 4d23fc1e
...@@ -538,8 +538,8 @@ class Step(GitRecipesMixin): ...@@ -538,8 +538,8 @@ class Step(GitRecipesMixin):
if not self.GitIsWorkdirClean(): # pragma: no cover if not self.GitIsWorkdirClean(): # pragma: no cover
self.Die("Workspace is not clean. Please commit or undo your changes.") self.Die("Workspace is not clean. Please commit or undo your changes.")
# Persist current branch. # Checkout master in case the script was left on a work branch.
self["current_branch"] = self.GitCurrentBranch() self.GitCheckout('origin/master')
# Fetch unfetched revisions. # Fetch unfetched revisions.
self.vc.Fetch() self.vc.Fetch()
...@@ -549,11 +549,7 @@ class Step(GitRecipesMixin): ...@@ -549,11 +549,7 @@ class Step(GitRecipesMixin):
self.DeleteBranch(self._config["BRANCHNAME"]) self.DeleteBranch(self._config["BRANCHNAME"])
def CommonCleanup(self): def CommonCleanup(self):
if ' ' in self["current_branch"]: self.GitCheckout('origin/master')
self.GitCheckout('master')
else:
self.GitCheckout(self["current_branch"])
if self._config["BRANCHNAME"] != self["current_branch"]:
self.GitDeleteBranch(self._config["BRANCHNAME"]) self.GitDeleteBranch(self._config["BRANCHNAME"])
# Clean up all temporary files. # Clean up all temporary files.
......
...@@ -437,7 +437,7 @@ class ScriptTest(unittest.TestCase): ...@@ -437,7 +437,7 @@ class ScriptTest(unittest.TestCase):
def testCommonPrepareDefault(self): def testCommonPrepareDefault(self):
self.Expect([ self.Expect([
Cmd("git status -s -uno", ""), Cmd("git status -s -uno", ""),
Cmd("git status -s -b -uno", "## some_branch"), Cmd("git checkout -f origin/master", ""),
Cmd("git fetch", ""), Cmd("git fetch", ""),
Cmd("git branch", " branch1\n* %s" % TEST_CONFIG["BRANCHNAME"]), Cmd("git branch", " branch1\n* %s" % TEST_CONFIG["BRANCHNAME"]),
RL("Y"), RL("Y"),
...@@ -445,24 +445,22 @@ class ScriptTest(unittest.TestCase): ...@@ -445,24 +445,22 @@ class ScriptTest(unittest.TestCase):
]) ])
self.MakeStep().CommonPrepare() self.MakeStep().CommonPrepare()
self.MakeStep().PrepareBranch() self.MakeStep().PrepareBranch()
self.assertEquals("some_branch", self._state["current_branch"])
def testCommonPrepareNoConfirm(self): def testCommonPrepareNoConfirm(self):
self.Expect([ self.Expect([
Cmd("git status -s -uno", ""), Cmd("git status -s -uno", ""),
Cmd("git status -s -b -uno", "## some_branch"), Cmd("git checkout -f origin/master", ""),
Cmd("git fetch", ""), Cmd("git fetch", ""),
Cmd("git branch", " branch1\n* %s" % TEST_CONFIG["BRANCHNAME"]), Cmd("git branch", " branch1\n* %s" % TEST_CONFIG["BRANCHNAME"]),
RL("n"), RL("n"),
]) ])
self.MakeStep().CommonPrepare() self.MakeStep().CommonPrepare()
self.assertRaises(Exception, self.MakeStep().PrepareBranch) self.assertRaises(Exception, self.MakeStep().PrepareBranch)
self.assertEquals("some_branch", self._state["current_branch"])
def testCommonPrepareDeleteBranchFailure(self): def testCommonPrepareDeleteBranchFailure(self):
self.Expect([ self.Expect([
Cmd("git status -s -uno", ""), Cmd("git status -s -uno", ""),
Cmd("git status -s -b -uno", "## some_branch"), Cmd("git checkout -f origin/master", ""),
Cmd("git fetch", ""), Cmd("git fetch", ""),
Cmd("git branch", " branch1\n* %s" % TEST_CONFIG["BRANCHNAME"]), Cmd("git branch", " branch1\n* %s" % TEST_CONFIG["BRANCHNAME"]),
RL("Y"), RL("Y"),
...@@ -470,7 +468,6 @@ class ScriptTest(unittest.TestCase): ...@@ -470,7 +468,6 @@ class ScriptTest(unittest.TestCase):
]) ])
self.MakeStep().CommonPrepare() self.MakeStep().CommonPrepare()
self.assertRaises(Exception, self.MakeStep().PrepareBranch) self.assertRaises(Exception, self.MakeStep().PrepareBranch)
self.assertEquals("some_branch", self._state["current_branch"])
def testInitialEnvironmentChecks(self): def testInitialEnvironmentChecks(self):
TextToFile("", os.path.join(TEST_CONFIG["DEFAULT_CWD"], ".git")) TextToFile("", os.path.join(TEST_CONFIG["DEFAULT_CWD"], ".git"))
...@@ -774,7 +771,7 @@ Performance and stability improvements on all platforms.""" ...@@ -774,7 +771,7 @@ Performance and stability improvements on all platforms."""
expectations.append(Cmd("which vi", "/usr/bin/vi")) expectations.append(Cmd("which vi", "/usr/bin/vi"))
expectations += [ expectations += [
Cmd("git status -s -uno", ""), Cmd("git status -s -uno", ""),
Cmd("git status -s -b -uno", "## some_branch\n"), Cmd("git checkout -f origin/master", ""),
Cmd("git fetch", ""), Cmd("git fetch", ""),
Cmd("git branch", " branch1\n* branch2\n"), Cmd("git branch", " branch1\n* branch2\n"),
Cmd("git branch", " branch1\n* branch2\n"), Cmd("git branch", " branch1\n* branch2\n"),
...@@ -828,7 +825,7 @@ Performance and stability improvements on all platforms.""" ...@@ -828,7 +825,7 @@ Performance and stability improvements on all platforms."""
" origin/candidates", "hsh_to_tag"), " origin/candidates", "hsh_to_tag"),
Cmd("git tag 3.22.5 hsh_to_tag", ""), Cmd("git tag 3.22.5 hsh_to_tag", ""),
Cmd("git push origin 3.22.5", ""), Cmd("git push origin 3.22.5", ""),
Cmd("git checkout -f some_branch", ""), Cmd("git checkout -f origin/master", ""),
Cmd("git branch -D %s" % TEST_CONFIG["BRANCHNAME"], ""), Cmd("git branch -D %s" % TEST_CONFIG["BRANCHNAME"], ""),
Cmd("git branch -D %s" % TEST_CONFIG["CANDIDATESBRANCH"], ""), Cmd("git branch -D %s" % TEST_CONFIG["CANDIDATESBRANCH"], ""),
] ]
...@@ -1189,7 +1186,7 @@ LOG=N ...@@ -1189,7 +1186,7 @@ LOG=N
self.Expect([ self.Expect([
Cmd("git status -s -uno", ""), Cmd("git status -s -uno", ""),
Cmd("git status -s -b -uno", "## some_branch\n"), Cmd("git checkout -f origin/master", ""),
Cmd("git fetch", ""), Cmd("git fetch", ""),
Cmd("git branch", " branch1\n* branch2\n"), Cmd("git branch", " branch1\n* branch2\n"),
Cmd("git new-branch %s --upstream refs/remotes/origin/candidates" % Cmd("git new-branch %s --upstream refs/remotes/origin/candidates" %
...@@ -1263,7 +1260,7 @@ LOG=N ...@@ -1263,7 +1260,7 @@ LOG=N
"hsh_to_tag"), "hsh_to_tag"),
Cmd("git tag 3.22.5.1 hsh_to_tag", ""), Cmd("git tag 3.22.5.1 hsh_to_tag", ""),
Cmd("git push origin 3.22.5.1", ""), Cmd("git push origin 3.22.5.1", ""),
Cmd("git checkout -f some_branch", ""), Cmd("git checkout -f origin/master", ""),
Cmd("git branch -D %s" % TEST_CONFIG["BRANCHNAME"], ""), Cmd("git branch -D %s" % TEST_CONFIG["BRANCHNAME"], ""),
]) ])
...@@ -1350,7 +1347,7 @@ Cr-Commit-Position: refs/heads/4.2.71@{#1} ...@@ -1350,7 +1347,7 @@ Cr-Commit-Position: refs/heads/4.2.71@{#1}
self.Expect([ self.Expect([
Cmd("git status -s -uno", ""), Cmd("git status -s -uno", ""),
Cmd("git status -s -b -uno", "## some_branch\n"), Cmd("git checkout -f origin/master", ""),
Cmd("git fetch", ""), Cmd("git fetch", ""),
Cmd("git branch", " branch1\n* branch2\n"), Cmd("git branch", " branch1\n* branch2\n"),
Cmd("git new-branch %s" % TEST_CONFIG["BRANCHNAME"], ""), Cmd("git new-branch %s" % TEST_CONFIG["BRANCHNAME"], ""),
...@@ -1443,7 +1440,7 @@ Cr-Commit-Position: refs/heads/4.2.71@{#1} ...@@ -1443,7 +1440,7 @@ Cr-Commit-Position: refs/heads/4.2.71@{#1}
cwd=chrome_dir), cwd=chrome_dir),
Cmd("git checkout -f master", "", cwd=chrome_dir), Cmd("git checkout -f master", "", cwd=chrome_dir),
Cmd("git branch -D %s" % TEST_CONFIG["BRANCHNAME"], "", cwd=chrome_dir), Cmd("git branch -D %s" % TEST_CONFIG["BRANCHNAME"], "", cwd=chrome_dir),
Cmd("git checkout -f some_branch", ""), Cmd("git checkout -f origin/master", ""),
Cmd("git branch -D %s" % TEST_CONFIG["BRANCHNAME"], ""), Cmd("git branch -D %s" % TEST_CONFIG["BRANCHNAME"], ""),
]) ])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment