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

Re: git-testadd: Execute a command with only the staged changes in Git applied

From
Øyvind A. Holm <sunny@sunbase.org>
Date
Jul 28, 2016, 22:31 UTC
Message-ID
<CAA787rm+qLig6mzHw0NjNDt-6HF_77FOwmg5dBBOdwbqo3wP6A@mail.gmail.com>
In-Reply-To
<579A5D97.7080708@gmail.com>
On 28 July 2016 at 21:31, Jakub Narębski <jnareb@gmail.com> wrote:
Show 19 quoted lines
> W dniu 2016-07-28 o 18:56, Øyvind A. Holm pisze:
> > Øyvind A. Holm <sunny@sunbase.org> writes:
> > > This is a script I created some weeks ago, and I've found it to be
> > > immensely useful. Here is a snippet from git-testadd --help:
> > > [...]
> > >   This script clones the repository to the directory
> > >   ".testadd.tmp" in the current directory and applies the staged
> > >   chenges there (unless -u/--unmodified or -p/--pristine is
> > >   specified), chdirs to the same relative directory in the clone
> > >   and executes the command specified on the command line there.
> >
> > That's correct, the test clone is entirely separated from the
> > working copy, and you can keep working while the tests are running
> > in the clone. Combined with git-gui and/or "git add -p/git reset
> > -p", it's easy to tweak the staged changes until things are ok.
>
> I wonder if using `git worktree` instead of `git clone` (well, local
> clone uses hardlinks, so it is not that costly as it looks like) would
> be a better solution.

That's an interesting idea. Have to test it out. This is the result from the current master in linux.git:

With clone:
  $ time git testadd pwd
  git-testadd: Using ".testadd.tmp" as destination directory
  Cloning into '.testadd.tmp'...
  done.
  Checking out files: 100% (55256/55256), done.
  git-testadd: Applying staged changes
  git-testadd: Executing "pwd" in /home/sunny/src/test-wt/.testadd.tmp
  /home/sunny/src/test-wt/.testadd.tmp
  real    0m10.464s
  user    0m5.983s
  sys     0m2.790s
  $
With worktree:
  $ time git worktree add testaddtmp
  Preparing testaddtmp (identifier testaddtmp)
  Checking out files: 100% (55256/55256), done.
  HEAD is now at 194dc87 Add braces to avoid "ambiguous ‘else’" compiler
  warnings
  real    0m10.343s
  user    0m6.010s
  sys     0m2.523s
  $

Both tests were run with cold cache ("echo 3 >/proc/sys/vm/drop_caches" as root). It seems as there's no difference, and that git clone is as fast as it can get without breaking physical laws. And we probably shouldn't do that. :)

Z poważaniem, Øyvind

Previous: Jakub NarębskiNext: Øyvind A. Holm
Message 4 of 5 in “git-testadd: Execute a command with only the staged changes in Git applied”
  1. Øyvind A. HolmJul 28, 2016
  2. Øyvind A. HolmJul 28, 2016
  3. Jakub NarębskiJul 28, 2016
  4. Øyvind A. HolmJul 28, 2016
  5. Øyvind A. HolmJul 28, 2016

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.