]> git.ipfire.org Git - thirdparty/git.git/commit - builtin/add.c
add: error appropriately on repository with no commits
authorKyle Meyer <kyle@kyleam.com>
Tue, 9 Apr 2019 23:07:37 +0000 (19:07 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Apr 2019 03:52:50 +0000 (12:52 +0900)
commitf937bc2f86ba2c2956b4228bd2386aaafc9afe83
treefa4e2f9e2fd08ab635b2eaede283bc8b649ee900
parentb22827045e0b6c2ae1b12be2820cdc4b7f750895
add: error appropriately on repository with no commits

The previous commit made 'git add' abort when given a repository that
doesn't have a commit checked out.  However, the output upon failure
isn't appropriate:

  % git add repo
  warning: adding embedded git repository: repo
  hint: You've added another git repository inside your current repository.
  hint: [...]
  error: unable to index file 'repo/'
  fatal: adding files failed

The hint doesn't apply in this case, and the error message doesn't
tell the user why 'repo' couldn't be added to the index.

Provide better output by teaching add_to_index() to error when given a
git directory where HEAD can't be resolved.  To avoid the embedded
repository warning and hint, call check_embedded_repo() only after
add_file_to_index() succeeds because, in general, its output doesn't
make sense if adding to the index fails.

Signed-off-by: Kyle Meyer <kyle@kyleam.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/add.c
read-cache.c
t/t3700-add.sh