git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 0/4] dir: Treat a repository without commits as a repository

From
Kyle Meyer <kyle@kyleam.com>
Date
Apr 2, 2019, 18:35 UTC
Message-ID
<20190402183505.31512-1-kyle@kyleam.com>
In-Reply-To
<87lg1eq146.fsf@kyleam.com>
Show 32 quoted lines
> Kyle Meyer <kyle@kyleam.com> writes:
>
> [...]
>
>> diff --git a/git-submodule.sh b/git-submodule.sh
>> index 514ede2596..6c74656027 100755
>> --- a/git-submodule.sh
>> +++ b/git-submodule.sh
>> @@ -234,10 +234,18 @@ cmd_add()
>>  	if test -z "$force" &&
>>  		! git add --dry-run --ignore-missing --no-warn-embedded-repo "$sm_path" > /dev/null 2>&1
>>  	then
>> -		eval_gettextln "The following path is ignored by one of your .gitignore files:
>> +		if test -d "$sm_path" &&
>> +			test -z $(git -C "$sm_path" rev-parse --show-cdup 2>/dev/null) &&
>> +			! git -C "$sm_path" rev-parse --verify -q HEAD >/dev/null
>> +		then
>> +			die "$(eval_gettext "'\$sm_path' does not have any commits")"
>> +		else
>> +			eval_gettextln "\
>> +The following path is ignored by one of your .gitignore files:
>>  \$sm_path
>>  Use -f if you really want to add it." >&2
>> -		exit 1
>> +			exit 1
>> +		fi
>
> I didn't think through this check, which would have been obvious had I
> ran the added test without the rest of the patches in this series.  It
> assumes that the 'git add --dry-run' call fails, but that failure
> depends on the last patch of this series.  So I'd need to move this
> patch to the end or find a new place for this "no commits" check.

v2 moves the "no commits" check outside of the 'git add --dry-run' failure condition so that the first patch doesn't depend on the final patch in this series.

Kyle Meyer (4):
  submodule: refuse to add repository with no commits
  t3000: move non-submodule repo test to separate file
  t3009: test that ls-files -o traverses bogus repo
  dir: do not traverse repositories with no commits
 dir.c                                   |  6 ++-
 git-submodule.sh                        |  7 ++++
 t/t3000-ls-files-others.sh              |  7 ----
 t/t3009-ls-files-others-nonsubmodule.sh | 56 +++++++++++++++++++++++++
 t/t3700-add.sh                          |  1 +
 t/t7400-submodule-basic.sh              | 11 ++++-
 6 files changed, 78 insertions(+), 10 deletions(-)
 create mode 100755 t/t3009-ls-files-others-nonsubmodule.sh
Range-diff against v1:
1:  e0db7e3c3c ! 1:  b080e2c557 submodule: refuse to add repository with no commits
    @@ -9,10 +9,9 @@
         in the sub-repository are added to the current repository.
     
         Detect if the path is a repository with no commits and abort to avoid
    -    getting into this state unless --force is used.  Reacting to --force
    -    isn't very useful, especially because an upcoming commit will make
    -    'git add' fail in this situation, but it allows us to use the same
    -    'git add --dry-run' condition as the ignored path case.
    +    getting into this state.  Note that this check must come before the
    +    'git add --dry-run' check because an upcoming commit will make 'git
    +    add' fail in this situation.
     
         Signed-off-by: Kyle Meyer <kyle@kyleam.com>
     
    @@ -20,26 +19,19 @@
      --- a/git-submodule.sh
      +++ b/git-submodule.sh
     @@
    + 		die "$(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")"
    + 	fi
    + 
    ++	if test -d "$sm_path" &&
    ++		test -z $(git -C "$sm_path" rev-parse --show-cdup 2>/dev/null)
    ++	then
    ++	    git -C "$sm_path" rev-parse --verify -q HEAD >/dev/null ||
    ++	    die "$(eval_gettext "'\$sm_path' does not have any commits")"
    ++	fi
    ++
      	if test -z "$force" &&
      		! git add --dry-run --ignore-missing --no-warn-embedded-repo "$sm_path" > /dev/null 2>&1
      	then
    --		eval_gettextln "The following path is ignored by one of your .gitignore files:
    -+		if test -d "$sm_path" &&
    -+			test -z $(git -C "$sm_path" rev-parse --show-cdup 2>/dev/null) &&
    -+			! git -C "$sm_path" rev-parse --verify -q HEAD >/dev/null
    -+		then
    -+			die "$(eval_gettext "'\$sm_path' does not have any commits")"
    -+		else
    -+			eval_gettextln "\
    -+The following path is ignored by one of your .gitignore files:
    - \$sm_path
    - Use -f if you really want to add it." >&2
    --		exit 1
    -+			exit 1
    -+		fi
    - 	fi
    - 
    - 	if test -n "$custom_name"
     
      diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
      --- a/t/t7400-submodule-basic.sh
2:  6eed1f5daf = 2:  c027701842 t3000: move non-submodule repo test to separate file
3:  7ba3209762 = 3:  97f53e30c0 t3009: test that ls-files -o traverses bogus repo
4:  2901375dc1 = 4:  a926b87102 dir: do not traverse repositories with no commits
-- 
2.21.0
Previous: Kyle MeyerNext: Kyle Meyer
Message 7 of 16 in “dir: Treat a repository without commits as a repository”
  1. 0/4 dir: Treat a repository without commits as a repositoryKyle Meyer, Mar 14, 2019
  2. 2/4 t3000: move non-submodule repo test to separate fileKyle Meyer, Mar 14, 2019
  3. 4/4 dir: do not traverse repositories with no commitsKyle Meyer, Mar 14, 2019
  4. 3/4 t3009: test that ls-files -o traverses bogus repoKyle Meyer, Mar 14, 2019
  5. 1/4 submodule: refuse to add repository with no commitsKyle Meyer, Mar 14, 2019
  6. Kyle MeyerMar 16, 2019
  7. 0/4 dir: Treat a repository without commits as a repositoryKyle Meyer, Apr 2, 2019
  8. 1/4 submodule: refuse to add repository with no commitsKyle Meyer, Apr 2, 2019
  9. Junio C HamanoApr 4, 2019
  10. 2/4 t3000: move non-submodule repo test to separate fileKyle Meyer, Apr 2, 2019
  11. Junio C HamanoApr 3, 2019
  12. Kyle MeyerApr 3, 2019
  13. 3/4 t3009: test that ls-files -o traverses bogus repoKyle Meyer, Apr 2, 2019
  14. 4/4 dir: do not traverse repositories with no commitsKyle Meyer, Apr 2, 2019
  15. Junio C HamanoApr 3, 2019
  16. Kyle MeyerApr 3, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.