git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Make git ls-files omit deleted files
@ 2024-01-12 21:19 Raul Rangel
  2024-01-12 21:37 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Raul Rangel @ 2024-01-12 21:19 UTC (permalink / raw)
  To: git

Hello,
I'm trying to copy my current git worktree to a new directory, while
including all modified and untracked files, but excluding any ignored
files. I essentially want a copy of the tree assuming someone ran `git
add --all && git commit` and cloned that commit into a different
directory.

I got pretty close with the following command:

    $ git ls-files --cached --modified --others --exclude-standard
--deduplicate | xargs cp --parents --no-dereference
--target-directory=/tmp/clone/

The problem is that if I have an unstaged delete, `ls-files` will
print it out as a modification and `cp` will print an error saying
that it failed to copy the non-existing file.

The man page states this behavior:

> --modified: Show files with an unstaged modification (note that an unstaged deletion also counts as an unstaged modification)

Is there another way to achieve what I'm doing that's not too
expensive? If not, could a `--no-deleted-as-modified` flag be added?

Thanks,
Raul

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Make git ls-files omit deleted files
  2024-01-12 21:19 Make git ls-files omit deleted files Raul Rangel
@ 2024-01-12 21:37 ` Junio C Hamano
  2024-01-12 21:50   ` Raul Rangel
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Junio C Hamano @ 2024-01-12 21:37 UTC (permalink / raw)
  To: Raul Rangel; +Cc: git

Raul Rangel <rrangel@google.com> writes:

> I'm trying to copy my current git worktree to a new directory, while
> including all modified and untracked files, but excluding any ignored
> files.

Curiously missing from the above is "unmodified".  You only talked
about modified, untracked, and ignored, but what do you want to do
with them?

As you are grabbing the files from the working tree, I suspect that
you do not want to base your decision on what is in the index, which
means that ls-files might be a wrong tool for the job.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Make git ls-files omit deleted files
  2024-01-12 21:37 ` Junio C Hamano
@ 2024-01-12 21:50   ` Raul Rangel
  2024-01-12 22:18   ` rsbecker
  2024-01-16 21:22   ` Raul Rangel
  2 siblings, 0 replies; 5+ messages in thread
From: Raul Rangel @ 2024-01-12 21:50 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Fri, Jan 12, 2024 at 2:37 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Raul Rangel <rrangel@google.com> writes:
>
> > I'm trying to copy my current git worktree to a new directory, while
> > including all modified and untracked files, but excluding any ignored
> > files.
>
> Curiously missing from the above is "unmodified".  You only talked
> about modified, untracked, and ignored, but what do you want to do
> with them?

I guess another way of saying it is, I want to make a copy of the
worktree while honoring .gitignore. i.e., I don't want my copied work
tree to contain any ignored files.

>
> As you are grabbing the files from the working tree, I suspect that
> you do not want to base your decision on what is in the index, which
> means that ls-files might be a wrong tool for the job.

Hrmm, that makes sense. Do you have any recommendations?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Make git ls-files omit deleted files
  2024-01-12 21:37 ` Junio C Hamano
  2024-01-12 21:50   ` Raul Rangel
@ 2024-01-12 22:18   ` rsbecker
  2024-01-16 21:22   ` Raul Rangel
  2 siblings, 0 replies; 5+ messages in thread
From: rsbecker @ 2024-01-12 22:18 UTC (permalink / raw)
  To: 'Junio C Hamano', 'Raul Rangel'; +Cc: git

On Friday, January 12, 2024 4:37 PM, Junio C Hamano wrote:
>Raul Rangel <rrangel@google.com> writes:
>
>> I'm trying to copy my current git worktree to a new directory, while
>> including all modified and untracked files, but excluding any ignored
>> files.
>
>Curiously missing from the above is "unmodified".  You only talked about
modified,
>untracked, and ignored, but what do you want to do with them?
>
>As you are grabbing the files from the working tree, I suspect that you do
not want
>to base your decision on what is in the index, which means that ls-files
might be a
>wrong tool for the job.

Coupled with ls-files, using git status --porcelain might give some insight
into what the condition of each modified and untracked file/directory is.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Make git ls-files omit deleted files
  2024-01-12 21:37 ` Junio C Hamano
  2024-01-12 21:50   ` Raul Rangel
  2024-01-12 22:18   ` rsbecker
@ 2024-01-16 21:22   ` Raul Rangel
  2 siblings, 0 replies; 5+ messages in thread
From: Raul Rangel @ 2024-01-16 21:22 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Fri, Jan 12, 2024 at 2:37 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Raul Rangel <rrangel@google.com> writes:
>
> > I'm trying to copy my current git worktree to a new directory, while
> > including all modified and untracked files, but excluding any ignored
> > files.
>
> Curiously missing from the above is "unmodified".  You only talked
> about modified, untracked, and ignored, but what do you want to do
> with them?
>
> As you are grabbing the files from the working tree, I suspect that
> you do not want to base your decision on what is in the index, which
> means that ls-files might be a wrong tool for the job.

Thanks for this insight. I ended up using `git ls-files` and
`--ignored` to print out all the files that I want to ignore, and I
converted that into a `find` exclusion list.

Here is the final command:
$ git ls-files --others --ignored --exclude-standard --directory |
(printf "%s\n" \( -path ./.git; sed -e 's/^/.\//' -e 's/\/$//' -e
's/^/-o\n-path\n/'; printf "%s\n" \) -prune -o ! -type d -print0 ) |
xargs --exit find . | xargs -0 --max-procs 0 cp --parents
--no-dereference  -t /tmp/clone

This is actually a lot faster than I would have expected.
Parallelizing the `cp` cuts the time down dramatically.

Thanks again!

p.s., Sorry for the resend. I forgot to send a plain text to the mailing list.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-16 21:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-12 21:19 Make git ls-files omit deleted files Raul Rangel
2024-01-12 21:37 ` Junio C Hamano
2024-01-12 21:50   ` Raul Rangel
2024-01-12 22:18   ` rsbecker
2024-01-16 21:22   ` Raul Rangel

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