{"thread":{"id":"60738","subject":"Make git ls-files omit deleted files","startedAt":"2024-01-12T21:19:48Z","lastAt":"2024-01-16T21:23:09Z","messageCount":5,"participants":["Raul Rangel","Junio C Hamano","rsbecker@nexbridge.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"486734","messageId":"CAHQZ30Ad6+YM9qnCOeNNy8e2k-AbYR_bBXTups-7z6=ioyqS5Q@mail.gmail.com","threadId":"60738","inReplyTo":null,"subject":"Make git ls-files omit deleted files","fromName":"Raul Rangel","fromEmail":"rrangel@google.com","sentAt":"2024-01-12T21:19:34Z","receivedAt":"2024-01-12T21:19:48Z","isPatch":false,"sender":{"key":"rrangel@google.com","avatar":null},"body":"Hello,\nI'm trying to copy my current git worktree to a new directory, while\nincluding all modified and untracked files, but excluding any ignored\nfiles. I essentially want a copy of the tree assuming someone ran `git\nadd --all && git commit` and cloned that commit into a different\ndirectory.\n\nI got pretty close with the following command:\n\n    $ git ls-files --cached --modified --others --exclude-standard\n--deduplicate | xargs cp --parents --no-dereference\n--target-directory=/tmp/clone/\n\nThe problem is that if I have an unstaged delete, `ls-files` will\nprint it out as a modification and `cp` will print an error saying\nthat it failed to copy the non-existing file.\n\nThe man page states this behavior:\n\n> --modified: Show files with an unstaged modification (note that an unstaged deletion also counts as an unstaged modification)\n\nIs there another way to achieve what I'm doing that's not too\nexpensive? If not, could a `--no-deleted-as-modified` flag be added?\n\nThanks,\nRaul\n"},{"id":"486736","messageId":"xmqqply68c87.fsf@gitster.g","threadId":"60738","inReplyTo":"CAHQZ30Ad6+YM9qnCOeNNy8e2k-AbYR_bBXTups-7z6=ioyqS5Q@mail.gmail.com","subject":"Re: Make git ls-files omit deleted files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-01-12T21:37:28Z","receivedAt":"2024-01-12T21:37:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Raul Rangel <rrangel@google.com> writes:\n\n> I'm trying to copy my current git worktree to a new directory, while\n> including all modified and untracked files, but excluding any ignored\n> files.\n\nCuriously missing from the above is \"unmodified\".  You only talked\nabout modified, untracked, and ignored, but what do you want to do\nwith them?\n\nAs you are grabbing the files from the working tree, I suspect that\nyou do not want to base your decision on what is in the index, which\nmeans that ls-files might be a wrong tool for the job.\n"},{"id":"486741","messageId":"CAHQZ30AZjqC9t9xDo407FEo3sDUDOSApOwMP_3Pm2nv7itttQQ@mail.gmail.com","threadId":"60738","inReplyTo":"xmqqply68c87.fsf@gitster.g","subject":"Re: Make git ls-files omit deleted files","fromName":"Raul Rangel","fromEmail":"rrangel@google.com","sentAt":"2024-01-12T21:50:57Z","receivedAt":"2024-01-12T21:51:11Z","isPatch":false,"sender":{"key":"rrangel@google.com","avatar":null},"body":"On Fri, Jan 12, 2024 at 2:37 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Raul Rangel <rrangel@google.com> writes:\n>\n> > I'm trying to copy my current git worktree to a new directory, while\n> > including all modified and untracked files, but excluding any ignored\n> > files.\n>\n> Curiously missing from the above is \"unmodified\".  You only talked\n> about modified, untracked, and ignored, but what do you want to do\n> with them?\n\nI guess another way of saying it is, I want to make a copy of the\nworktree while honoring .gitignore. i.e., I don't want my copied work\ntree to contain any ignored files.\n\n>\n> As you are grabbing the files from the working tree, I suspect that\n> you do not want to base your decision on what is in the index, which\n> means that ls-files might be a wrong tool for the job.\n\nHrmm, that makes sense. Do you have any recommendations?\n"},{"id":"486742","messageId":"038a01da45a5$47faf380$d7f0da80$@nexbridge.com","threadId":"60738","inReplyTo":"xmqqply68c87.fsf@gitster.g","subject":"RE: Make git ls-files omit deleted files","fromName":"","fromEmail":"rsbecker@nexbridge.com","sentAt":"2024-01-12T22:18:28Z","receivedAt":"2024-01-12T22:18:42Z","isPatch":false,"sender":{"key":"randall.becker@nexbridge.ca","avatar":"https://avatars.githubusercontent.com/u/28956764?v=4"},"body":"On Friday, January 12, 2024 4:37 PM, Junio C Hamano wrote:\n>Raul Rangel <rrangel@google.com> writes:\n>\n>> I'm trying to copy my current git worktree to a new directory, while\n>> including all modified and untracked files, but excluding any ignored\n>> files.\n>\n>Curiously missing from the above is \"unmodified\".  You only talked about\nmodified,\n>untracked, and ignored, but what do you want to do with them?\n>\n>As you are grabbing the files from the working tree, I suspect that you do\nnot want\n>to base your decision on what is in the index, which means that ls-files\nmight be a\n>wrong tool for the job.\n\nCoupled with ls-files, using git status --porcelain might give some insight\ninto what the condition of each modified and untracked file/directory is.\n\n"},{"id":"486867","messageId":"CAHQZ30DmMYgTkKhWzK+H-TJN0dj2B-1Fhutu_=eRQd7vJCdjZQ@mail.gmail.com","threadId":"60738","inReplyTo":"xmqqply68c87.fsf@gitster.g","subject":"Re: Make git ls-files omit deleted files","fromName":"Raul Rangel","fromEmail":"rrangel@google.com","sentAt":"2024-01-16T21:22:57Z","receivedAt":"2024-01-16T21:23:09Z","isPatch":false,"sender":{"key":"rrangel@google.com","avatar":null},"body":"On Fri, Jan 12, 2024 at 2:37 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Raul Rangel <rrangel@google.com> writes:\n>\n> > I'm trying to copy my current git worktree to a new directory, while\n> > including all modified and untracked files, but excluding any ignored\n> > files.\n>\n> Curiously missing from the above is \"unmodified\".  You only talked\n> about modified, untracked, and ignored, but what do you want to do\n> with them?\n>\n> As you are grabbing the files from the working tree, I suspect that\n> you do not want to base your decision on what is in the index, which\n> means that ls-files might be a wrong tool for the job.\n\nThanks for this insight. I ended up using `git ls-files` and\n`--ignored` to print out all the files that I want to ignore, and I\nconverted that into a `find` exclusion list.\n\nHere is the final command:\n$ git ls-files --others --ignored --exclude-standard --directory |\n(printf \"%s\\n\" \\( -path ./.git; sed -e 's/^/.\\//' -e 's/\\/$//' -e\n's/^/-o\\n-path\\n/'; printf \"%s\\n\" \\) -prune -o ! -type d -print0 ) |\nxargs --exit find . | xargs -0 --max-procs 0 cp --parents\n--no-dereference  -t /tmp/clone\n\nThis is actually a lot faster than I would have expected.\nParallelizing the `cp` cuts the time down dramatically.\n\nThanks again!\n\np.s., Sorry for the resend. I forgot to send a plain text to the mailing list.\n"}]}