All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Nazri Ramliy <ayiehere@gmail.com>
Cc: Eric Sunshine <sunshine@sunshineco.com>,
	Git List <git@vger.kernel.org>, Jeff King <peff@peff.net>,
	Jonathan Nieder <jrnieder@gmail.com>
Subject: Re: [PATCH v3] Teach git to change to a given directory using -C option
Date: Mon, 09 Sep 2013 09:32:02 -0700	[thread overview]
Message-ID: <xmqqtxhu3qil.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20130909134743.GA11335@gmail.com> (Nazri Ramliy's message of "Mon, 9 Sep 2013 21:47:43 +0800")

Nazri Ramliy <ayiehere@gmail.com> writes:

> Subject: git: run in a directory given with -C option
>
> This is similar in spirit to to "make -C dir ..." and "tar -C dir ...".

The doubled-"to to" which I locally fixed when I queued the last one
(together with other rewording to make it more agreeable and easier
to read) somehow came back ;-) Will fix locally again.

> +-C <path>::
> +	Run as if git was started in '<path>' instead of the current working
> +	directory.  When multiple '-C' options are given, each subsequent

I think this should be `-C` to typeset it as "typed literally".

> +	non-absolute `-C <path>` is interpreted relative to the preceding `-C
> +	<path>`.
> ++
> +This option affects options that expect path name like '--git-dir' and
> +'--work-tree' in that their interpretations of the path names would be

Likewise for `--git-dir` and `--work-tree`.

> +made relative to the working directory caused by the '-C' option. For

and here.

> diff --git a/t/t0056-git-C.sh b/t/t0056-git-C.sh
> new file mode 100755
> index 0000000..c0006da
> --- /dev/null
> +++ b/t/t0056-git-C.sh
> @@ -0,0 +1,82 @@
> +#!/bin/sh
> +
> +test_description='"-C <path>" option and its effects on other path-related options'
> +
> +. ./test-lib.sh
> +
> +test_expect_success '"git -C <path>" runs git from the directory <path>' '
> +	test_create_repo dir1 &&
> +	echo 1 >dir1/a.txt &&
> +	(cd dir1 && git add a.txt && git commit -m "initial in dir1") &&

Curious why this does not use -C here.

> +	echo "initial in dir1" >expected &&
> +	git -C dir1 log --format=%s >actual &&
> +	test_cmp expected actual
> +'
> +
> +test_expect_success 'Multiple -C options: "-C dir1 -C dir2" is equivalent to "-C dir1/dir2"' '
> +	test_create_repo dir1/dir2 &&
> +	echo 1 >dir1/dir2/a.txt &&
> +	git -C dir1/dir2 add a.txt &&

Because "a.txt" exists in both dir1 and dir1/dir2, this has less
chance of catching a bug (if somebody breaks the feature to run it
in dir1 not dir1/dir2, "add" will happily say "Oh, I found something
to add", instead of saying "Huh? there is no such path".

If you used b.txt instead, you would catch such a breakage.

Remember, tests are not about demonstrating how cool the new feature
is and/or how well it works in an expected setting.  Imagine ways
other people can break your spiffy new feature in later patches, and
design tests that are more likely to catch them.

The same comment applies throughout the remainder of this script.

> +	echo "initial in dir1/dir2" >expected &&
> +	git -C dir1/dir2 commit -m "initial in dir1/dir2" &&

to reduce possibilities of breaking this test in the future due to
typos (e.g. somebody may want to say "initial commit in dir1/dir2"),
doing this may be a better idea:

	msg="initial in dir1/dir2" &&
        echo "$msg" >expected &&
        git -C dir1/dir2 commit -m "$msg" &&

The same comment applies to the previous one.

  reply	other threads:[~2013-09-09 16:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-03 11:59 [PATCH v3] Teach git to change to a given directory using -C option Nazri Ramliy
2013-09-03 22:46 ` Junio C Hamano
2013-09-03 23:37   ` Eric Sunshine
2013-09-04  6:36   ` Nazri Ramliy
2013-09-04  6:45     ` Eric Sunshine
2013-09-04 12:20     ` Nazri Ramliy
2013-09-08 10:32       ` Eric Sunshine
2013-09-09  1:49         ` Nazri Ramliy
2013-09-09  5:01           ` Eric Sunshine
2013-09-09 13:47             ` Nazri Ramliy
2013-09-09 16:32               ` Junio C Hamano [this message]
2013-09-09 17:42                 ` Eric Sunshine
2013-09-09 17:59                   ` Junio C Hamano
2013-09-09 18:43                 ` Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqtxhu3qil.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=ayiehere@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.