Subject: Re: StGIT refreshes all added files - limitation of git-write-tree?

From: Shawn Pearce <[email-masked]>
Date: Wed, 15 Feb 2006 01:28:14 -0500

Pavel Roskin <[email-masked]> wrote:
> Or maybe git-write-tree and other utilities could be changed to work on
> a copy of the index file?  I would prefer not to move the
> actual .git/index away, but to make a copy for the current "stg refresh"
> operation.

git-write-tree pays attention to the GIT_INDEX_FILE environment
variable; if this, GIT_DIR and GIT_OBJECT_DIRECTORY are set you can
redirect git-write-tree to look at a different index.  One way to
create a tree from a mixture of your current index and the current
HEAD's tree is to set GIT_INDEX_FILE to a temporary file name
(which doesn't exist), use git-read-tree to load the current tree
unmodified into that index, copy the modified records of interest
from the current index to the temporary index, then git-write-tree
from the temporary index.  But now you need to update your current
index with the real SHA1s of the written files.

Somewhat convoluted.  I think that git-commit.sh and cg-commit.sh
play such games to do partial commits based on what the user has
passed on the command line or modified in their editor (which is
actually a rather cool feature of Cogito).  I'm using a similar
trick in pg to load binary objects from a patch directory (for a
specific use case that I have).  git-am.sh uses a similar trick
to perform a 3 way merge if git-apply fails.

-- 
Shawn.