threads / patch / 6916

patchFix 'git commit -a' in a newly initialized repository

Subject: [PATCH] Fix 'git commit -a' in a newly initialized repository

## tl;dr

9 messages between Feb 22, 2007 and Feb 23, 2007. Diffs are folded; open one to read it.

replies: 8people: 4as markdown or json

Fredrik Kuivinen· Feb 22, 2007, 20:28 UTC · lore
With current git:

$ git init $ git commit -a cp: cannot stat `.git/index': No such file or directory

Output a nice error message instead.
Signed-off-by: Fredrik Kuivinen <frekui@gmail.com>
---
 git-commit.sh |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Show changes to git-commit.sh +4 −0
diff --git a/git-commit.sh b/git-commit.sh
index ec506d9..476f4f1 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -318,6 +318,10 @@ esac
 
 case "$all,$also" in
 t,)
+	if test ! -f "$THIS_INDEX"
+	then
+		die 'nothing to commit (use "git add file1 file2" to include for commit)'
+	fi
 	save_index &&
 	(
 		cd_to_toplevel &&
Johannes Schindelin· Feb 22, 2007, 20:42 UTC · re: Fredrik Kuivinen · lore

Re: [PATCH] Fix 'git commit -a' in a newly initialized repository

Hi,
On Thu, 22 Feb 2007, Fredrik Kuivinen wrote:
> +		die 'nothing to commit (use "git add file1 file2" to include for commit)'

Would it not make more sense to tell the user about "git add ."? Maybe together with a hint about .gitignore?

This error message is important. The most likely recipients are total git newsters, and we really should try to help them here.

Ciao, Dscho

Nicolas Pitre· Feb 22, 2007, 20:54 UTC · re: Johannes Schindelin · lore

Re: [PATCH] Fix 'git commit -a' in a newly initialized repository

On Thu, 22 Feb 2007, Johannes Schindelin wrote:
Show 7 quoted lines
> Hi,
> 
> On Thu, 22 Feb 2007, Fredrik Kuivinen wrote:
> 
> > +		die 'nothing to commit (use "git add file1 file2" to include for commit)'
> 
> Would it not make more sense to tell the user about "git add ."?

Isn't what the patch does? IMHO it looks just like the empty commit message which is good.

Show 5 quoted lines
> Maybe 
> together with a hint about .gitignore?
> 
> This error message is important. The most likely recipients are total git 
> newsters, and we really should try to help them here.

Sure. But to really help newsters it is better _not_ to talk about .gitignore at all. It certainly won't exist at that point anyway.

Nicolas
Johannes Schindelin· Feb 22, 2007, 20:59 UTC · re: Nicolas Pitre · lore

Re: [PATCH] Fix 'git commit -a' in a newly initialized repository

Hi,
On Thu, 22 Feb 2007, Nicolas Pitre wrote:
Show 10 quoted lines
> On Thu, 22 Feb 2007, Johannes Schindelin wrote:
> 
> > On Thu, 22 Feb 2007, Fredrik Kuivinen wrote:
> > 
> > > +		die 'nothing to commit (use "git add file1 file2" to include for commit)'
> > 
> > Would it not make more sense to tell the user about "git add ."?
> 
> Isn't what the patch does?  IMHO it looks just like the empty commit 
> message which is good.

I wanted to get at the "." thing. You know, when I start a project with git, there are usually some files there already. Provided I have a .gitignore there, I can just say "git add ." and be done.

But maybe that is _not_ common practice?
Show 7 quoted lines
> > Maybe together with a hint about .gitignore?
> > 
> > This error message is important. The most likely recipients are total 
> > git newsters, and we really should try to help them here.
> 
> Sure.  But to really help newsters it is better _not_ to talk about 
> .gitignore at all.  It certainly won't exist at that point anyway.
Hmm. That is a really good point. Hmmm. I think you're right.

Ciao, Dscho

Nicolas Pitre· Feb 22, 2007, 21:09 UTC · re: Johannes Schindelin · lore

Re: [PATCH] Fix 'git commit -a' in a newly initialized repository

On Thu, 22 Feb 2007, Johannes Schindelin wrote:
Show 20 quoted lines
> Hi,
> 
> On Thu, 22 Feb 2007, Nicolas Pitre wrote:
> 
> > On Thu, 22 Feb 2007, Johannes Schindelin wrote:
> > 
> > > On Thu, 22 Feb 2007, Fredrik Kuivinen wrote:
> > > 
> > > > +		die 'nothing to commit (use "git add file1 file2" to include for commit)'
> > > 
> > > Would it not make more sense to tell the user about "git add ."?
> > 
> > Isn't what the patch does?  IMHO it looks just like the empty commit 
> > message which is good.
> 
> I wanted to get at the "." thing. You know, when I start a project with 
> git, there are usually some files there already. Provided I have a 
> .gitignore there, I can just say "git add ." and be done.
> 
> But maybe that is _not_ common practice?

Well... If you're that acquainted with GIT to perform the above, I'm sure a message like "use "git add file1 file2" to include for commit" won't leave you puzzled. ;-)

Nicolas
Johannes Schindelin· Feb 22, 2007, 21:13 UTC · re: Nicolas Pitre · lore

Re: [PATCH] Fix 'git commit -a' in a newly initialized repository

Hi,
On Thu, 22 Feb 2007, Nicolas Pitre wrote:
Show 11 quoted lines
> On Thu, 22 Feb 2007, Johannes Schindelin wrote:
> 
> > I wanted to get at the "." thing. You know, when I start a project 
> > with git, there are usually some files there already. Provided I have 
> > a .gitignore there, I can just say "git add ." and be done.
> > 
> > But maybe that is _not_ common practice?
> 
> Well... If you're that acquainted with GIT to perform the above, I'm 
> sure a message like "use "git add file1 file2" to include for commit" 
> won't leave you puzzled.  ;-)
;-) Yes, you are right!

Ciao, Dscho

Junio C Hamano· Feb 22, 2007, 21:36 UTC · re: Nicolas Pitre · lore

Re: [PATCH] Fix 'git commit -a' in a newly initialized repository

If we want to limit the help to lone liner, I am with Nicolas and Fredrik on this one. Suggesting only "git add ." does not feel helpful.

However, because ! test -f "$THIS_INDEX" is such a special case (totally new check-in), we can afford to be verbose if we wanted to, and offer tons of possibilities, say:

	die 'nothing to commit.  You can use "git add file..."
to include individual files, or use "git add ." if you want to 
include all files in the current directory, for your first
commit.'

But if we want to say "for your first commit" in the message, we should also be checking if HEAD commit really does not exist.

Nicolas Pitre· Feb 23, 2007, 00:06 UTC · re: Junio C Hamano · lore

Re: [PATCH] Fix 'git commit -a' in a newly initialized repository

On Thu, 22 Feb 2007, Junio C Hamano wrote:
Show 11 quoted lines
> However, because ! test -f "$THIS_INDEX" is such a special case
> (totally new check-in), we can afford to be verbose if we wanted
> to, and offer tons of possibilities, say:
> 
> 	die 'nothing to commit.  You can use "git add file..."
> to include individual files, or use "git add ." if you want to 
> include all files in the current directory, for your first
> commit.'
> 
> But if we want to say "for your first commit" in the message, we
> should also be checking if HEAD commit really does not exist.
Seems to me that the single line message avoids all those issues.
Nicolas
Junio C Hamano· Feb 23, 2007, 05:03 UTC · re: Nicolas Pitre · lore

Re: [PATCH] Fix 'git commit -a' in a newly initialized repository

Nicolas Pitre <nico@cam.org> writes:
Show 15 quoted lines
> On Thu, 22 Feb 2007, Junio C Hamano wrote:
>
>> However, because ! test -f "$THIS_INDEX" is such a special case
>> (totally new check-in), we can afford to be verbose if we wanted
>> to, and offer tons of possibilities, say:
>> 
>> 	die 'nothing to commit.  You can use "git add file..."
>> to include individual files, or use "git add ." if you want to 
>> include all files in the current directory, for your first
>> commit.'
>> 
>> But if we want to say "for your first commit" in the message, we
>> should also be checking if HEAD commit really does not exist.
>
> Seems to me that the single line message avoids all those issues.
Yup.  Will apply Fredrik's original to 'maint'.

← back to recent threads