From 9ca5fc85965b33b062b70f8dc7ebbcc7e6e581e9 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 18 Aug 2021 03:28:15 -0700 Subject: [PATCH] projtool.pl: accept --force with sethead for new branch There's no reason not to allow a different unborn branch name to be set provided that's the intent. Allow a non-existent branch name to be used with `--force` provided it passes the valid_branch_name check. All the code to properly handle an unborn HEAD already exists since that's been the default state of new push projects for some time. Signed-off-by: Kyle J. McKay --- toolbox/projtool.pl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/toolbox/projtool.pl b/toolbox/projtool.pl index 6c97cc7..ffa214e 100755 --- a/toolbox/projtool.pl +++ b/toolbox/projtool.pl @@ -10,7 +10,7 @@ use strict; use warnings; use vars qw($VERSION); -BEGIN {*VERSION = \'1.0.7'} +BEGIN {*VERSION = \'1.0.8'} use File::Basename; use Digest::MD5 qw(md5_hex); use IO::Socket; @@ -201,7 +201,7 @@ Usage: %s [...] with "set" and/or is required without "set" and only 2 args, just show current readme setting - [set]head + [set]head [--force] set project HEAD symbolic ref to without "set" and only 1 arg, just show current project HEAD @@ -1813,10 +1813,15 @@ sub valid_head { } sub cmd_sethead { + my $force = 0; + parse_options(force => \$force); @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage; my $project = get_project_harder($ARGV[0]); if (@ARGV == 2 && !valid_head($project, $ARGV[1])) { - die "invalid head (try \"@{[basename($0)]} listheads $ARGV[0]\"): \"$ARGV[1]\"\n"; + die "invalid head (try \"@{[basename($0)]} listheads $ARGV[0]\"): \"$ARGV[1]\"\n" unless $force; + valid_branch_name($ARGV[1]) or + die "grossly invalid new HEAD: $ARGV[1]\n"; + warn "Continuing with --force even though requested branch does not exist\n" unless $quiet; } my $old = $project->{HEAD}; if (@ARGV == 1) { -- 2.11.4.GIT