Thanks a lot Konstantin for the information, will doing research on this.
On Thu, Nov 14, 2013 at 8:03 AM, Konstantin Khomoutov <
> On Wed, 13 Nov 2013 12:00:00 -0500
> lingfei ouyang <oylf1...@gmail.com> wrote:
> > and one more quick question?
> > What is the correct way for define the variable in pre-commit hooks
> > in Git bash so I can using those three variables to run git commands,
> > i.e.
> > git show $newrev
> > git merge-base $oldreve $newrev
> > since what I tried in my bash scripts first to define:
> > refname="$1"
> > oldrev="$2"
> > newrev="$3"
> > but when I run check if those three variables are valid first and it
> > doesn't return any value.
> Your question has little sense as is: to define a variable in bash (and
> in any other POSIX shell) yo do
> to assign value to a variable named "variable" (possibly creating it).
> Hence a dumb answer is that you're doing assignments right.
> On the other hand, I'm not so sure about these "$1", "$2" and "$3":
> in a POSIX shell, $1 expands to the value of the first so-called
> positional parameter, $2 to the value of the second positional
> parameter and so on. Positional parameters are arguments passed to the
> shell process on its command line, for instance, if you call
> $ ./myscript.sh foo bar baz
> $1 inside myscript.sh would expand to foo, $2 to bar etc.
> The problem is that by (stupid) default it's not an error in a POSIX
> shell to attempt to expand a parameter which does not exist.
> I mean, if you have a script myscript.sh reading
> echo "$foo"
> and run it without any arguments, like just
> $ ./myscript.sh
> it will execute successfully and print nothing (a newline, actually).
> The reason: there was no first positional parameter, so $1 expanded to
> an empty string instead of erroring out and so the variable foo has been
> assigned an empty string which echo printed.
> What I'm leading you to is just supposedly what you're observing is
> your hook not receiving any arguments and hence it has no positional
> parameters set. Which leads us to the next question: did you read the
> githooks(5) manual page to read up on how exactly Git communicates
> its information to your kind of hook? Or is there any such information
> at all? I know the answer but I want you to start thinking and doing
> some active research.
You received this message because you are subscribed to the Google Groups "Git
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/groups/opt_out.