threads / patch / 13231

patchclone: detect and fail on excess parameters

Subject: [PATCH] clone: detect and fail on excess parameters

## tl;dr

3 messages between Apr 23, 2008 and Apr 28, 2008. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Junio C Hamano· Apr 23, 2008, 17:53 UTC · lore

"git clone [options] $src $dst excess-garbage" simply ignored excess-garbage without giving any diagnostic message. Fix it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * I noticed it while trying "git clone --reference $there $src $dst" with
   various combinations of options, and in one case I errorneously removed
   "--reference" without removing $there.  It happily created a clone of
   the reference repository under a funnily named directory whose name
   looked like a URL.
 git-clone.sh     |    1 +
 t/t5601-clone.sh |   26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 0 deletions(-)
Show changes to 2 files +27 −0

git-clone.sh, t/t5601-clone.sh

diff --git a/git-clone.sh b/git-clone.sh
index 2636159..9e433c0 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -219,6 +219,7 @@ fi
 if test -n "$2"
 then
 	dir="$2"
+	test $# == 2 || die "excess parameter to git-clone"
 else
 	# Derive one from the repository name
 	# Try using "humanish" part of source repo if user didn't specify one
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
new file mode 100755
index 0000000..dc9d63d
--- /dev/null
+++ b/t/t5601-clone.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+test_description=clone
+
+. ./test-lib.sh
+
+test_expect_success setup '
+
+	rm -fr .git &&
+	test_create_repo src &&
+	(
+		cd src
+		>file
+		git add file
+		git commit -m initial
+	)
+
+'
+
+test_expect_success 'clone with excess parameters' '
+
+	test_must_fail git clone -n "file://$(pwd)/src" dst junk
+
+'
+
+test_done
SZEDER Gábor· Apr 28, 2008, 16:36 UTC · re: Junio C Hamano · lore

Re: [PATCH] clone: detect and fail on excess parameters

Hi,
On Wed, Apr 23, 2008 at 10:53:47AM -0700, Junio C Hamano wrote:
Show 12 quoted lines
> "git clone [options] $src $dst excess-garbage" simply ignored
> excess-garbage without giving any diagnostic message.  Fix it.
> 
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> [...]
> --- a/git-clone.sh
> +++ b/git-clone.sh
> @@ -219,6 +219,7 @@ fi
>  if test -n "$2"
>  then
>  	dir="$2"
> +	test $# == 2 || die "excess parameter to git-clone"
                ^^
I think you mean:
    test $# = 2 || die "excess parameter to git-clone"
I just noticed because it broke t1020-subdirectory at me.

Best, Gábor

Alex Riesen· Apr 28, 2008, 21:09 UTC · re: SZEDER Gábor · lore

[PATCH] Use "=" instead of "==" in condition as it is more portable

At least the dash from Ubuntu's /bin/sh says:
    test: 233: ==: unexpected operator
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
SZEDER Gábor, Mon, Apr 28, 2008 18:36:42 +0200:
Show 12 quoted lines
> On Wed, Apr 23, 2008 at 10:53:47AM -0700, Junio C Hamano wrote:
> > "git clone [options] $src $dst excess-garbage" simply ignored
> > excess-garbage without giving any diagnostic message.  Fix it.
> > 
> >  	dir="$2"
> > +	test $# == 2 || die "excess parameter to git-clone"
>                 ^^
> I think you mean:
> 
>     test $# = 2 || die "excess parameter to git-clone"
> 
> I just noticed because it broke t1020-subdirectory at me.

And me. Almost every test which uses git-clone (I expect some don't test its exit code in setup routines).

 git-clone.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to git-clone.sh +1 −1
diff --git a/git-clone.sh b/git-clone.sh
index 9e433c0..8c7fc7f 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -219,7 +219,7 @@ fi
 if test -n "$2"
 then
 	dir="$2"
-	test $# == 2 || die "excess parameter to git-clone"
+	test $# = 2 || die "excess parameter to git-clone"
 else
 	# Derive one from the repository name
 	# Try using "humanish" part of source repo if user didn't specify one
-- 
1.5.5.1.118.g6dd1b6.dirty

← back to recent threads