From: Fredrik Gustafsson <iveqy@iveqy.com>
To: git@vger.kernel.org
Cc: iveqy@iveqy.com, jens.lehmann@web.de, hvoigt@hvoigt.net,
gitster@pobox.com
Subject: [PATCH v3 1/2] rev-parse: add option --is-well-formed-git-dir [path]
Date: Fri, 12 Aug 2011 21:55:12 +0200 [thread overview]
Message-ID: <1313178913-25617-2-git-send-email-iveqy@iveqy.com> (raw)
In-Reply-To: <1313178913-25617-1-git-send-email-iveqy@iveqy.com>
Check if [path] is a valid git-dir or a valid git-file that points
to a valid git-dir.
We want tests to be independent from the fact that a git-dir may
be a git-file. Thus we changed tests to use this feature.
Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
Mentored-by: Jens Lehmann <Jens.Lehmann@web.de>
Mentored-by: Heiko Voigt <hvoigt@hvoigt.net>
---
Documentation/git-rev-parse.txt | 4 ++
builtin/rev-parse.c | 8 +++
cache.h | 1 +
setup.c | 7 +++
t/t7400-submodule-basic.sh | 4 +-
t/t7403-submodule-sync.sh | 5 +-
t/t7407-submodule-foreach.sh | 97 ++++++++++++++++++++-------------------
7 files changed, 75 insertions(+), 51 deletions(-)
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 42c9676..3ce81c0 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -180,6 +180,10 @@ print a message to stderr and exit with nonzero status.
<args>...::
Flags and parameters to be parsed.
+--is-well-formed-git-dir [path]::
+ Check if [path] is a valid git-dir or a git-file pointing to a valid
+ git-dir. If [path] is a valid git-dir the resolved path to git-dir will
+ be printed.
include::revisions.txt[]
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 4c19f84..21ac43f 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -468,6 +468,14 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
return 0;
}
+ if (argc > 2 && !strcmp(argv[1], "--is-well-formed-git-dir")) {
+ const char *gitdir = resolve_gitdir(argv[2]);
+ if (!gitdir)
+ die("not a gitdir '%s'", argv[2]);
+ puts(gitdir);
+ return 0;
+ }
+
if (argc > 1 && !strcmp("-h", argv[1]))
usage(builtin_rev_parse_usage);
diff --git a/cache.h b/cache.h
index 9e12d55..550f632 100644
--- a/cache.h
+++ b/cache.h
@@ -436,6 +436,7 @@ extern char *get_graft_file(void);
extern int set_git_dir(const char *path);
extern const char *get_git_work_tree(void);
extern const char *read_gitfile_gently(const char *path);
+extern const char *resolve_gitdir(const char *suspect);
extern void set_git_work_tree(const char *tree);
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
diff --git a/setup.c b/setup.c
index 5ea5502..efad002 100644
--- a/setup.c
+++ b/setup.c
@@ -808,3 +808,10 @@ const char *setup_git_directory(void)
{
return setup_git_directory_gently(NULL);
}
+
+const char *resolve_gitdir(const char *suspect)
+{
+ if (is_git_directory(suspect))
+ return suspect;
+ return read_gitfile_gently(suspect);
+}
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 14dc927..4df53e5 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -360,10 +360,10 @@ test_expect_success 'update --init' '
git submodule update init > update.out &&
cat update.out &&
test_i18ngrep "not initialized" update.out &&
- ! test -d init/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir init/.git &&
git submodule update --init init &&
- test -d init/.git
+ git rev-parse --is-well-formed-git-dir init/.git
'
test_expect_success 'do not add files from a submodule' '
diff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh
index 95ffe34..3620215 100755
--- a/t/t7403-submodule-sync.sh
+++ b/t/t7403-submodule-sync.sh
@@ -56,8 +56,9 @@ test_expect_success '"git submodule sync" should update submodule URLs' '
git pull --no-recurse-submodules &&
git submodule sync
) &&
- test -d "$(git config -f super-clone/submodule/.git/config \
- remote.origin.url)" &&
+ test -d "$(cd super-clone/submodule &&
+ git config remote.origin.url
+ )" &&
(cd super-clone/submodule &&
git checkout master &&
git pull
diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh
index be745fb..1a974e2 100755
--- a/t/t7407-submodule-foreach.sh
+++ b/t/t7407-submodule-foreach.sh
@@ -118,19 +118,19 @@ test_expect_success 'use "submodule foreach" to checkout 2nd level submodule' '
git clone super clone2 &&
(
cd clone2 &&
- test ! -d sub1/.git &&
- test ! -d sub2/.git &&
- test ! -d sub3/.git &&
- test ! -d nested1/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir sub1/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir sub2/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir sub3/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir nested1/.git &&
git submodule update --init &&
- test -d sub1/.git &&
- test -d sub2/.git &&
- test -d sub3/.git &&
- test -d nested1/.git &&
- test ! -d nested1/nested2/.git &&
+ git rev-parse --is-well-formed-git-dir sub1/.git &&
+ git rev-parse --is-well-formed-git-dir sub2/.git &&
+ git rev-parse --is-well-formed-git-dir sub3/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir nested1/nested2/.git &&
git submodule foreach "git submodule update --init" &&
- test -d nested1/nested2/.git &&
- test ! -d nested1/nested2/nested3/.git
+ git rev-parse --is-well-formed-git-dir nested1/nested1/nested2/.git
+ test_must_fail git rev-parse --is-well-formed-git-dir nested1/nested2/nested3/.git
)
'
@@ -138,8 +138,8 @@ test_expect_success 'use "foreach --recursive" to checkout all submodules' '
(
cd clone2 &&
git submodule foreach --recursive "git submodule update --init" &&
- test -d nested1/nested2/nested3/.git &&
- test -d nested1/nested2/nested3/submodule/.git
+ git rev-parse --is-well-formed-git-dir nested1/nested2/nested3/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/nested2/nested3/submodule/.git
)
'
@@ -183,18 +183,18 @@ test_expect_success 'use "update --recursive" to checkout all submodules' '
git clone super clone3 &&
(
cd clone3 &&
- test ! -d sub1/.git &&
- test ! -d sub2/.git &&
- test ! -d sub3/.git &&
- test ! -d nested1/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir sub1/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir sub2/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir sub3/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir nested1/.git &&
git submodule update --init --recursive &&
- test -d sub1/.git &&
- test -d sub2/.git &&
- test -d sub3/.git &&
- test -d nested1/.git &&
- test -d nested1/nested2/.git &&
- test -d nested1/nested2/nested3/.git &&
- test -d nested1/nested2/nested3/submodule/.git
+ git rev-parse --is-well-formed-git-dir sub1/.git &&
+ git rev-parse --is-well-formed-git-dir sub2/.git &&
+ git rev-parse --is-well-formed-git-dir sub3/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/nested2/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/nested2/nested3/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/nested2/nested3/submodule/.git
)
'
@@ -247,14 +247,17 @@ test_expect_success 'ensure "status --cached --recursive" preserves the --cached
test_expect_success 'use "git clone --recursive" to checkout all submodules' '
git clone --recursive super clone4 &&
- test -d clone4/.git &&
- test -d clone4/sub1/.git &&
- test -d clone4/sub2/.git &&
- test -d clone4/sub3/.git &&
- test -d clone4/nested1/.git &&
- test -d clone4/nested1/nested2/.git &&
- test -d clone4/nested1/nested2/nested3/.git &&
- test -d clone4/nested1/nested2/nested3/submodule/.git
+ (
+ cd clone4 &&
+ git rev-parse --is-well-formed-git-dir .git &&
+ git rev-parse --is-well-formed-git-dir sub1/.git &&
+ git rev-parse --is-well-formed-git-dir sub2/.git &&
+ git rev-parse --is-well-formed-git-dir sub3/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/nested2/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/nested2/nested3/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/nested2/nested3/submodule/.git
+ )
'
test_expect_success 'test "update --recursive" with a flag with spaces' '
@@ -262,11 +265,11 @@ test_expect_success 'test "update --recursive" with a flag with spaces' '
git clone super clone5 &&
(
cd clone5 &&
- test ! -d nested1/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir d nested1/.git &&
git submodule update --init --recursive --reference="$(dirname "$PWD")/common objects" &&
- test -d nested1/.git &&
- test -d nested1/nested2/.git &&
- test -d nested1/nested2/nested3/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/nested2/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/nested2/nested3/.git &&
test -f nested1/.git/objects/info/alternates &&
test -f nested1/nested2/.git/objects/info/alternates &&
test -f nested1/nested2/nested3/.git/objects/info/alternates
@@ -277,18 +280,18 @@ test_expect_success 'use "update --recursive nested1" to checkout all submodules
git clone super clone6 &&
(
cd clone6 &&
- test ! -d sub1/.git &&
- test ! -d sub2/.git &&
- test ! -d sub3/.git &&
- test ! -d nested1/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir sub1/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir sub2/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir sub3/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir nested1/.git &&
git submodule update --init --recursive -- nested1 &&
- test ! -d sub1/.git &&
- test ! -d sub2/.git &&
- test ! -d sub3/.git &&
- test -d nested1/.git &&
- test -d nested1/nested2/.git &&
- test -d nested1/nested2/nested3/.git &&
- test -d nested1/nested2/nested3/submodule/.git
+ test_must_fail git rev-parse --is-well-formed-git-dir sub1/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir sub2/.git &&
+ test_must_fail git rev-parse --is-well-formed-git-dir sub3/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/nested2/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/nested2/nested3/.git &&
+ git rev-parse --is-well-formed-git-dir nested1/nested2/nested3/submodule/.git
)
'
--
1.7.6.403.g1fd2f.dirty
next prev parent reply other threads:[~2011-08-12 19:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-12 19:55 [PATCH v3 0/2] submodule: move gitdir into superproject Fredrik Gustafsson
2011-08-12 19:55 ` Fredrik Gustafsson [this message]
2011-08-12 20:57 ` [PATCH v3 1/2] rev-parse: add option --is-well-formed-git-dir [path] Junio C Hamano
2011-08-13 2:49 ` Nguyen Thai Ngoc Duy
2011-08-13 6:13 ` Heiko Voigt
2011-08-14 21:42 ` Junio C Hamano
2011-08-12 19:55 ` [PATCH v3 2/2] Move git-dir for submodules Fredrik Gustafsson
2011-08-15 14:30 ` Marc Branchaud
2011-08-15 15:14 ` Fredrik Gustafsson
2011-08-16 17:34 ` Junio C Hamano
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=1313178913-25617-2-git-send-email-iveqy@iveqy.com \
--to=iveqy@iveqy.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hvoigt@hvoigt.net \
--cc=jens.lehmann@web.de \
/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).