From: "Dirk Süsserott" <newsletter@dirk.my1.cc>
To: Git Mailing List <git@vger.kernel.org>
Subject: Q about git rev-parse {--is-inside-work-tree, --show-cdup}
Date: Fri, 03 Dec 2010 22:06:36 +0100 [thread overview]
Message-ID: <4CF95BDC.60506@dirk.my1.cc> (raw)
Hi together,
I wrote some shell scripts that do sth with my git repositories. I place
my scripts in my ~/bin folder (not in the repo). So the first step in my
scripts is always to check whether they get called from whithin a git
repo and bail out if they don't.
I do this like so:
---------------------
if [ "$(git rev-parse --is-inside-work-tree)" = "true" ] # (1)
then
here=$(pwd)
cdup=$(git rev-parse --show-cdup); # (2a)
cdup=${cdup:-"."} # (2b)
cd $cdup # (2c)
[do sth useful from the topdir]
cd $here
exit 0;
else
echo "Not inside a git working tree."
exit 1;
fi
---------------------
I have two questions:
1. Wouldn't it be useful, if "git rev-parse" (1) had an option "-q" that
simply indicates whether "--is-inside-work-tree" is true by means of the
return code? Actually it has an option "-q" but that doesn't work with
"--is-inside-work-tree".
2. Wouldn't it be useful, if "git rev-parse --show-cdup" (2a) would
return a dot "." instead of nothing if we are already in the topdir?
That would make the steps (2a), (2b), (2c) to a simple "cd $(git
rev-parse --show-cdup)".
(For those who aren't familiar with shell programming: (2b) means: 'if
$cdup is empty, then set it to "."'.)
I know that 2. is a problem, because "git rev-parse" is a plumbing tool.
People likely rely on "--show-dup" to return an empty string. But what
about 1.? I think there's no harm if "-q" would work for
"--is-inside-work-tree" as well.
BTW: I'm sorry that all my sentences start with "I". ;-)
What do you think? If appreciated, I'd like to work on a patch for (1).
Cheers,
Dirk
next reply other threads:[~2010-12-03 21:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-03 21:06 Dirk Süsserott [this message]
2010-12-03 21:20 ` Q about git rev-parse {--is-inside-work-tree, --show-cdup} Jeff King
2010-12-03 21:25 ` Junio C Hamano
2010-12-03 21:50 ` Jeff King
2010-12-04 15:12 ` Dirk Süsserott
2010-12-04 16:52 ` Andreas Schwab
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=4CF95BDC.60506@dirk.my1.cc \
--to=newsletter@dirk.my1.cc \
--cc=git@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).