summaryrefslogtreecommitdiff
path: root/git-p4.py
diff options
context:
space:
mode:
authorPete Wyckoff <pw@padd.com>2012-09-09 20:16:11 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-09-17 04:52:52 (GMT)
commitef739f0829f866b7e70e072a6744dc9cd1e12822 (patch)
tree469c5f23afb35e2476b5bd8182047bc4ce7b4284 /git-p4.py
parentb0ccc80d3cd12e41eaa9bc643b3aec3f50d134d8 (diff)
downloadgit-ef739f0829f866b7e70e072a6744dc9cd1e12822.zip
git-ef739f0829f866b7e70e072a6744dc9cd1e12822.tar.gz
git-ef739f0829f866b7e70e072a6744dc9cd1e12822.tar.bz2
git p4: add submit --dry-run option
A new option, "git p4 submit --dry-run" can be used to verify what commits and labels would be moved into p4. Signed-off-by: Pete Wyckoff <pw@padd.com> Acked-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-p4.py')
-rwxr-xr-xgit-p4.py43
1 files changed, 30 insertions, 13 deletions
diff --git a/git-p4.py b/git-p4.py
index 464f64d..04e9a80 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -853,12 +853,14 @@ class P4Submit(Command, P4UserMap):
# preserve the user, requires relevant p4 permissions
optparse.make_option("--preserve-user", dest="preserveUser", action="store_true"),
optparse.make_option("--export-labels", dest="exportLabels", action="store_true"),
+ optparse.make_option("--dry-run", "-n", dest="dry_run", action="store_true"),
]
self.description = "Submit changes from git to the perforce depot."
self.usage += " [name of git branch to submit into perforce depot]"
self.origin = ""
self.detectRenames = False
self.preserveUser = gitConfig("git-p4.preserveUser").lower() == "true"
+ self.dry_run = False
self.isWindows = (platform.system() == "Windows")
self.exportLabels = False
self.p4HasMoveCommand = p4_has_command("move")
@@ -1366,14 +1368,17 @@ class P4Submit(Command, P4UserMap):
for mapping in clientSpec.mappings:
labelTemplate += "\t%s\n" % mapping.depot_side.path
- p4_write_pipe(["label", "-i"], labelTemplate)
+ if self.dry_run:
+ print "Would create p4 label %s for tag" % name
+ else:
+ p4_write_pipe(["label", "-i"], labelTemplate)
- # Use the label
- p4_system(["tag", "-l", name] +
- ["%s@%s" % (mapping.depot_side.path, changelist) for mapping in clientSpec.mappings])
+ # Use the label
+ p4_system(["tag", "-l", name] +
+ ["%s@%s" % (mapping.depot_side.path, changelist) for mapping in clientSpec.mappings])
- if verbose:
- print "created p4 label for tag %s" % name
+ if verbose:
+ print "created p4 label for tag %s" % name
def run(self, args):
if len(args) == 0:
@@ -1432,12 +1437,15 @@ class P4Submit(Command, P4UserMap):
os.makedirs(self.clientPath)
chdir(self.clientPath)
- print "Synchronizing p4 checkout..."
- if new_client_dir:
- # old one was destroyed, and maybe nobody told p4
- p4_sync("...", "-f")
+ if self.dry_run:
+ print "Would synchronize p4 checkout in %s" % self.clientPath
else:
- p4_sync("...")
+ print "Synchronizing p4 checkout..."
+ if new_client_dir:
+ # old one was destroyed, and maybe nobody told p4
+ p4_sync("...", "-f")
+ else:
+ p4_sync("...")
self.check()
commits = []
@@ -1488,10 +1496,17 @@ class P4Submit(Command, P4UserMap):
# Apply the commits, one at a time. On failure, ask if should
# continue to try the rest of the patches, or quit.
#
+ if self.dry_run:
+ print "Would apply"
applied = []
last = len(commits) - 1
for i, commit in enumerate(commits):
- ok = self.applyCommit(commit)
+ if self.dry_run:
+ print " ", read_pipe(["git", "show", "-s",
+ "--format=format:%h %s", commit])
+ ok = True
+ else:
+ ok = self.applyCommit(commit)
if ok:
applied.append(commit)
else:
@@ -1515,7 +1530,9 @@ class P4Submit(Command, P4UserMap):
chdir(self.oldWorkingDirectory)
- if len(commits) == len(applied):
+ if self.dry_run:
+ pass
+ elif len(commits) == len(applied):
print "All commits applied!"
sync = P4Sync()