From e74d9046eeec52d7ccd433a4dad2cee30838c620 Mon Sep 17 00:00:00 2001 From: Aravind Vasudevan Date: Fri, 24 Mar 2023 04:16:35 +0000 Subject: [PATCH] Update abandon to support multiple branches This change updates `repo abandon` command to take multiple space-separated branchnames as parameters. Bug: https://crbug.com/gerrit/13354 Change-Id: I00ad7a79872c0e4161f8183843835f25cd515605 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/365524 Tested-by: Aravind Vasudevan Reviewed-by: Mike Frysinger Commit-Queue: Aravind Vasudevan --- subcmds/abandon.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/subcmds/abandon.py b/subcmds/abandon.py index 1f687f53..4036f306 100644 --- a/subcmds/abandon.py +++ b/subcmds/abandon.py @@ -48,9 +48,15 @@ It is equivalent to "git branch -D ". self.Usage() if not opt.all: - nb = args[0] - if not git.check_ref_format("heads/%s" % nb): - self.OptionParser.error("'%s' is not a valid branch name" % nb) + branches = args[0].split() + invalid_branches = [ + x for x in branches if not git.check_ref_format(f"heads/{x}") + ] + + if invalid_branches: + self.OptionParser.error( + f"{invalid_branches} are not valid branch names" + ) else: args.insert(0, "'All local branches'") @@ -59,7 +65,7 @@ It is equivalent to "git branch -D ". if all_branches: branches = project.GetBranches() else: - branches = [nb] + branches = nb ret = {} for name in branches: @@ -69,7 +75,7 @@ It is equivalent to "git branch -D ". return (ret, project) def Execute(self, opt, args): - nb = args[0] + nb = args[0].split() err = defaultdict(list) success = defaultdict(list) all_projects = self.GetProjects(