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

Re: [RFC] Removing deleted files after checkout

From
CBCarl Baldwin <cnb@fc.hp.com>
Date
Aug 23, 2005, 22:21 UTC
Message-ID
<20050823222151.GA15321@hpsvcnb.fc.hp.com>
In-Reply-To
<7vvf1wnwtl.fsf@assigned-by-dhcp.cox.net>

Ok, the following is what I came up with based on your response. This is .git/hooks/update. It mostly works in my situation. See below for my discussion on what didn't work.

#!/bin/sh
export PATH=/usr/local/bin:/usr/bin:/bin

# cd to the root of the project directory (assume one dir up from GIT_DIR) cd $GIT_DIR/.. unset GIT_DIR

if expr "$2" : '0*$' >/dev/null; then
    git-read-tree --reset $3 &&
        git-checkout-cache -q -f -u -a
else
    git-read-tree -m -u $2 $3
fi
exit 0
# --- snip ---

The thing that this doesn't do is remove empty directories when the last file is deleted. I once expressed the opinion in a previous thread that directories should be added and removed explicitly in git. (Thus allowing an empty directory to be added). If this were to happen then this case would get handled correctly. However, if git stays with the status quo then I think that git-read-tree -u should be changed to remove the empty directory. This would make it consistent.

What do you think?  Ideas?
Carl
On Tue, Aug 23, 2005 at 02:54:30PM -0700, Junio C Hamano wrote:
Show 19 quoted lines
> Daniel Barkalow <barkalow@iabervon.org> writes:
> 
> >> > If you don't use -f, git-checkout-script removes deleted files. Using -f
> >> > tells it to ignore the old index, which means that it can't tell the
> >> > difference between removed files and files that weren't tracked at all.
> 
> Yes and no.  "git checkout" assumes that the index file and the
> working tree somewhat resembles what is in .git/HEAD commit.
> Since push operation updates .git/HEAD commit without touching
> the index file, that assumption does not hold.
> 
> The update hook gets old commit name and new commit name, so you
> should be able to do (untested):
> 
>     git-read-tree -m -u $old_commit $new_commit
> 
> there, of course after making sure that you had old_commit (the
> first time push happens to a new ref you would not have that one).
> 
-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Carl Baldwin                        Systems VLSI Laboratory
 Hewlett Packard Company
 MS 88                               work: 970 898-1523
 3404 E. Harmony Rd.                 work: Carl.N.Baldwin@hp.com
 Fort Collins, CO 80525              home: Carl@ecBaldwin.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Previous: Junio C HamanoNext: Daniel Barkalow
Message 8 of 10 in “[RFC] Removing deleted files after checkout”
  1. Carl BaldwinAug 23, 2005
  2. Daniel BarkalowAug 23, 2005
  3. Carl BaldwinAug 23, 2005
  4. Daniel BarkalowAug 23, 2005
  5. Carl BaldwinAug 23, 2005
  6. Daniel BarkalowAug 23, 2005
  7. Junio C HamanoAug 23, 2005
  8. Carl BaldwinAug 23, 2005
  9. Daniel BarkalowAug 23, 2005
  10. Junio C HamanoAug 24, 2005

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.