git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Carl Baldwin <cnb@fc.hp.com>
To: git@vger.kernel.org
Subject: [RFC] Removing deleted files after checkout
Date: Tue, 23 Aug 2005 10:21:56 -0600	[thread overview]
Message-ID: <20050823162156.GA32240@hpsvcnb.fc.hp.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2000 bytes --]

Hello,

I recently started using git to revision control the source for my
web-page.  I wrote a post-update hook to checkout the files when I push
to the 'live' repository.

In this particular context I decided that it was important to me to remove
deleted files after checking out the new HEAD.  I accomplished this by running
git-ls-files before and after the checkout.

Is there a better way?  Could there be some way built into git to easily
find out what files dissappear when replacing the current index with one
from a new tree?  Is there already?  The behavior of git should NOT
change to delete these files but I would argue that some way should
exist to query what files disappeared if removing them is desired.

Here is some code that I wrote for this.  It feels a bit hackish to me but I
couldn't think of anything better.  Comments and criticism are welcome.

#!/bin/sh

# HEAD changed so checkout the new HEAD deleted any files that should no longer
# be around.
oldlist=$(tempfile)
newlist=$(tempfile)
removedlist=$(tempfile)

git-ls-files | sort -r > $oldlist
git-checkout-script -f
git-ls-files | sort -r > $newlist

diff -u $oldlist $newlist |
  tail -n +4 |
  sed -n 's/^-//p' > $removedlist

# Remove each file
cat $removedlist | xargs -rl rm -f
# Remove the directories if empty
cat $removedlist | xargs -rl dirname | xargs -rl rmdir -p --ignore-fail-on-non-empty

rm -f $oldlist $newlist $removedlist

# --- snip ---

If you are interested I attached the full post-update hook script that I
actually use to do this.  Again, comments are welcome.

Thanks,
Carl

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

[-- Attachment #2: post-update --]
[-- Type: text/plain, Size: 827 bytes --]

#!/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

# Set up some temporary files and a trap to delete them
oldlist=$(tempfile)
newlist=$(tempfile)
removelist=$(tempfile)
trap "rm -f $oldlist $newlist $removelist" 0 1 2 3 15

# Get list of files from the current index
git-ls-files | sort -r > $oldlist

# Checkout the index to the working directory
git-checkout-script -f

# Get list of files from the current (new) index
git-ls-files | sort -r > $newlist

# Use diff to determine which files to remove from the working copy
diff -u $oldlist $newlist |
  tail -n +4 |
  sed -n 's/^-//p' > $removelist

cat $removelist | xargs -rl rm -f
cat $removelist | xargs -rl dirname | xargs -rl rmdir -p --ignore-fail-on-non-empty

             reply	other threads:[~2005-08-23 16:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-23 16:21 Carl Baldwin [this message]
2005-08-23 19:43 ` [RFC] Removing deleted files after checkout Daniel Barkalow
2005-08-23 20:50   ` Carl Baldwin
2005-08-23 21:27     ` Daniel Barkalow
2005-08-23 21:40       ` Carl Baldwin
2005-08-23 22:12         ` Daniel Barkalow
2005-08-23 21:54       ` Junio C Hamano
2005-08-23 22:21         ` Carl Baldwin
2005-08-23 22:34           ` Daniel Barkalow
2005-08-24  0:02             ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050823162156.GA32240@hpsvcnb.fc.hp.com \
    --to=cnb@fc.hp.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).