Branch: Tag:


2011-01-23 14:21:35 by Marcus Comstedt <>

Fix problem when changing a file into a directory

Add a second "allow_empty" mode to get_committed_file, which returns
the empty string is the named file is actually a directory. This is
used by the check_ident() function, which is ok since a directory
can't contain any expanded idents, so there is nothing to check.

Note that get_staged_file() ought to support this mode as well.
Currently, running get_staged_file() on a directory actually returns
the contents of the first file in the directory, which is a bug.

109:    string treeentry = run_git("ls-tree", sha, "--", filename);    if (allow_empty && !sizeof(treeentry))    return ""; +  if (allow_empty == 2 && 2 == sscanf(treeentry, "%*o tree %s\t", blob)) +  return "";    if (2 != sscanf(treeentry, "%*o blob %s\t", blob))    fail("Unexpected output from git ls-tree\n");    return run_git("cat-file", "blob", blob);
353:       int check_ident(string filename)    { -  if (find_expanded_ident(get_file(filename, 1))) { +  if (find_expanded_ident(get_file(filename, 2))) {    write("File %s contains an expanded ident.\n", filename);    if(this_program == PreCommitHook) {    write("Try 'git reset %s; git add %s', "