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

Re: [PATCH] add: don't complain when adding empty project root

From
Torsten Bögershausen <tboegi@web.de>
Date
Dec 23, 2013, 17:48 UTC
Message-ID
<52B87759.2090901@web.de>
In-Reply-To
<1387789361-29036-1-git-send-email-pclouds@gmail.com>
On 2013-12-23 10.02, Nguyễn Thái Ngọc Duy wrote:
Show 39 quoted lines
> This behavior was added in 07d7bed (add: don't complain when adding
> empty project root - 2009-04-28) then broken by 84b8b5d (remove
> match_pathspec() in favor of match_pathspec_depth() -
> 2013-07-14). Reinstate it.
> 
> Noticed-by: Thomas Ferris Nicolaisen <tfnico@gmail.com>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  builtin/add.c  | 2 +-
>  t/t3700-add.sh | 4 ++++
>  2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/builtin/add.c b/builtin/add.c
> index 226f758..fbd3f3a 100644
> --- a/builtin/add.c
> +++ b/builtin/add.c
> @@ -544,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
>  
>  		for (i = 0; i < pathspec.nr; i++) {
>  			const char *path = pathspec.items[i].match;
> -			if (!seen[i] &&
> +			if (!seen[i] && pathspec.items[i].match[0] &&
>  			    ((pathspec.items[i].magic &
>  			      (PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
>  			     !file_exists(path))) {
> diff --git a/t/t3700-add.sh b/t/t3700-add.sh
> index aab86e8..1535d8f 100755
> --- a/t/t3700-add.sh
> +++ b/t/t3700-add.sh
> @@ -307,4 +307,8 @@ test_expect_success 'git add --dry-run --ignore-missing of non-existing file out
>  	test_i18ncmp expect.err actual.err
>  '
>  
> +test_expect_success 'git add -A on empty repo does not error out' '
> +	git init empty && ( cd empty && git add -A . )
> +'
> +
>  test_done
> 
I am (a little bit) confused.
This is what git does:
 rm -rf test && mkdir test && cd test && git init && touch A && mkdir D && cd D && touch B && git add . && git status
Initialized empty Git repository in /Users/tb/test/test/.git/
On branch master
Initial commit
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   B
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        ../A
----------------
And the behaviour is in line with
https://www.kernel.org/pub/software/scm/git/docs/git-add.html

"." stands for the current directory somewhere in the worktree, not only the "project root". -----------------

Could it make sense to mention that replace [PATCH] add: don't complain when adding empty project root with [PATCH] add: don't complain when adding empty directory.

(and similar in the commit message) /Torsten

Previous: Nguyễn Thái Ngọc DuyNext: Duy Nguyen
Message 10 of 18 in “git add -A fails in empty repository since 1.8.5”
  1. Thomas Ferris NicolaisenDec 18, 2013
  2. Antoine PelisseDec 18, 2013
  3. Duy NguyenDec 18, 2013
  4. Junio C HamanoDec 18, 2013
  5. Matthieu MoyDec 18, 2013
  6. Junio C HamanoDec 18, 2013
  7. Junio C HamanoDec 18, 2013
  8. Duy NguyenDec 19, 2013
  9. add: don't complain when adding empty project rootNguyễn Thái Ngọc Duy, Dec 23, 2013
  10. Torsten BögershausenDec 23, 2013
  11. Duy NguyenDec 23, 2013
  12. Torsten BögershausenDec 24, 2013
  13. Duy NguyenDec 24, 2013
  14. Torsten BögershausenJan 30, 2014
  15. Junio C HamanoJan 31, 2014
  16. Jonathan NiederDec 26, 2013
  17. Junio C HamanoDec 26, 2013
  18. Junio C HamanoDec 26, 2013

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.