Index: tools/push-to-trunk/git_recipes.py |
diff --git a/tools/push-to-trunk/git_recipes.py b/tools/push-to-trunk/git_recipes.py |
index c0f0afbede5c17ba122ef1c56ab8a0afe81242b3..8c1e314d7d8c7e493750918295dd044fba4c9b0a 100644 |
--- a/tools/push-to-trunk/git_recipes.py |
+++ b/tools/push-to-trunk/git_recipes.py |
@@ -28,6 +28,11 @@ |
import re |
+ |
+class GitFailedException(Exception): |
+ pass |
+ |
+ |
def Strip(f): |
def new_f(*args, **kwargs): |
return f(*args, **kwargs).strip() |
@@ -59,6 +64,13 @@ class GitRecipesMixin(object): |
assert name |
self.Git(MakeArgs(["branch -D", name])) |
+ def GitReset(self, name): |
+ assert name |
+ self.Git(MakeArgs(["reset --hard", name])) |
+ |
+ def GitRemotes(self): |
+ return map(str.strip, self.Git(MakeArgs(["branch -r"])).splitlines()) |
+ |
def GitCheckout(self, name): |
assert name |
self.Git(MakeArgs(["checkout -f", name])) |
@@ -68,6 +80,26 @@ class GitRecipesMixin(object): |
assert branch_or_hash |
self.Git(MakeArgs(["checkout -f", branch_or_hash, "--", name])) |
+ def GitCheckoutFileSafe(self, name, branch_or_hash): |
+ try: |
+ self.GitCheckoutFile(name, branch_or_hash) |
+ except GitFailedException: # pragma: no cover |
+ # The file doesn't exist in that revision. |
+ return False |
+ return True |
+ |
+ def GitChangedFiles(self, git_hash): |
+ assert git_hash |
+ try: |
+ files = self.Git(MakeArgs(["diff --name-only", |
+ git_hash, |
+ "%s^" % git_hash])) |
+ return map(str.strip, files.splitlines()) |
+ except GitFailedException: # pragma: no cover |
+ # Git fails using "^" at branch roots. |
+ return [] |
+ |
+ |
@Strip |
def GitCurrentBranch(self): |
for line in self.Git("status -s -b -uno").strip().splitlines(): |
@@ -99,6 +131,7 @@ class GitRecipesMixin(object): |
assert git_hash |
return self.Git(MakeArgs(["log", "-1", "-p", git_hash])) |
+ # TODO(machenbach): Unused? Remove. |
def GitAdd(self, name): |
assert name |
self.Git(MakeArgs(["add", Quoted(name)])) |
@@ -147,6 +180,7 @@ class GitRecipesMixin(object): |
def GitSVNFetch(self): |
self.Git("svn fetch") |
+ # TODO(machenbach): Unused? Remove. |
@Strip |
def GitSVNLog(self): |
return self.Git("svn log -1 --oneline") |