Giter Club home page Giter Club logo

Comments (7)

m1nkeh avatar m1nkeh commented on July 18, 2024

urghh, figured it out!

git filter-repo --path 'new folder/' --path-rename 'new folder/:' --force --dry-run

i must say this in slight contrary to the comment here: https://github.com/newren/git-filter-repo#solving-this-with-filter-repo

"the single quotes are unnecessary, but make it clearer to a human"

d'oh! 🍺

from git-filter-repo.

newren avatar newren commented on July 18, 2024

Indeed, this isn't a python issue at all but one of how the shell passes arguments to programs. For example, let's say you had a repository with the following three files, one of them oddly named:

README.md
foo.py
README.md --path foo.py

Then the command

git filter-repo --path README.md --path foo.py

would clearly be passing two --path arguments and asking for those two paths to be kept, while the command

git filter-repo --path 'README.md --path foo.py'

would be passing just one --path argument and asking for the funnily named path to be kept.

Also, this isn't contrary to the documentation comment at all as the example didn't have any spaces or special characters that needed to be quoted to keep the shell from interpreting the characters in a funny way.

Anyway, glad you figured it out.

from git-filter-repo.

m1nkeh avatar m1nkeh commented on July 18, 2024

sorry, maybe contrary was not the right word... but i didn't want to go so far as 'confusing'.. perhaps, unclear?

i.e. the example on that page cannot be extended to:
git filter-repo --path 'some path/' --path-rename 'some path/:'''

this also does not work:
git filter-repo --path "some path/" --path-rename "some path/:''"

nor this:
git filter-repo --path 'some path/' --path-rename 'some path/:""'

essentially i couldn't take the example of adding '' for human readability, and extend it in some way that was immediately obvious..

so, i guess to close this out properly what is the right way to escape this please? 🙂

from git-filter-repo.

newren avatar newren commented on July 18, 2024

The most straightforward translation is

git filter-repo --path 'some path/' --rename-path 'some path/':''

although this also works:

git filter-repo --path 'some path/' --rename-path 'some path/:'

The first of your examples is actually fine, though dropping the two final quotes is perhaps clearer since it literally ends up with filter-repo getting the exact same arguments. The other two of your examples try to replace
some path/
with either of the following two literal strings
''
or
""
i.e. it'd rename a path like
some path/foo.c
to
''foo.c
with the literal quotes as part of the filename.

None of this is a filter-repo issue, but one of understanding how shells work. It may be instructive with a simple helper program named arguments.py with the following contents:

#!/usr/bin/env python3

import sys
print("Arguments (1 per line):\n  :" + ":\n  :".join(sys.argv) + ":")

Now, if we try that program with the last two examples you provided, you can what filter-repo was actually told by the shell:

$ ./arguments.py git filter-repo --path 'some path/' --rename-path "some path/:''"
Arguments (1 per line):
  :./arguments.py:
  :git:
  :filter-repo:
  :--path:
  :some path/:
  :--rename-path:
  :some path/:'':
$ ./arguments.py git filter-repo --path 'some path/' --rename-path 'some path/:""'
Arguments (1 per line):
  :./arguments.py:
  :git:
  :filter-repo:
  :--path:
  :some path/:
  :--rename-path:
  :some path/:"":

which shows why filter-repo believes it was told to replace 'some path/' with '""'. In contrast, with either of the versions I specified:

$ ./arguments.py git filter-repo --path 'some path/' --rename-path 'some path/':''
Arguments (1 per line):
  :./arguments.py:
  :git:
  :filter-repo:
  :--path:
  :some path/:
  :--rename-path:
  :some path/::
$ ./arguments.py git filter-repo --path 'some path/' --rename-path 'some path/':
Arguments (1 per line):
  :./arguments.py:
  :git:
  :filter-repo:
  :--path:
  :some path/:
  :--rename-path:
  :some path/::

which shows that 'some path/' should be replaced by nothing. Also, we can run your original example both with three trailing quotes or just one to show that they result in the filter-repo getting the exact same input arguments:

$ ./arguments.py git filter-repo --path 'some path/' --rename-path 'some path/:'''
Arguments (1 per line):
  :./arguments.py:
  :git:
  :filter-repo:
  :--path:
  :some path/:
  :--rename-path:
  :some path/::
$ ./arguments.py git filter-repo --path 'some path/' --rename-path 'some path/:'
Arguments (1 per line):
  :./arguments.py:
  :git:
  :filter-repo:
  :--path:
  :some path/:
  :--rename-path:
  :some path/::

from git-filter-repo.

newren avatar newren commented on July 18, 2024

Oh, also, as this is entirely a shell issue, I should point out that quotes aren't necessary at all, even with spaces; The following:

  git filter-repo --path some\ path/ --rename-path some\ path/:

would have also worked. The whole problem is how do you prevent the shell from breaking arguments at the space character; so that you can pass a simple OLDPREFIX:NEWPREFIX string as a single argument to filter-repo.

from git-filter-repo.

m1nkeh avatar m1nkeh commented on July 18, 2024

Oooookkkkay. So, the issue all along was that my Git client of choice, PowerShell for Git (https://github.com/dahlbyk/posh-git), seems to not be respecting any of this!!

Your last comment, something which i had explicitly tried to do earlier today made me suddenly think it could be the client. And of course, in the vanilla Git Bash.. it works le sigh 😕.

Honestly thought i was going mad with you saying it worked, and me literally copy+pasting the command it not working!

Thanks for your patience 🙂.

🤦

from git-filter-repo.

newren avatar newren commented on July 18, 2024

Ah, PowerShell has even funnier quoting rules/requirements than posix shells, eh? Good to know, thanks for the heads up.

from git-filter-repo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.