Comments (10)
While lack of quotes around the blob object id is the first obvious problem, I'd say there are a few more:
- Filenames passed to the FileChange constructor should be relative to the repository root. A name like C:\MDC\MDC.7z makes no sense. But it's worse because that's not what you passed...
- backslashes within strings will be interpreted by bash and/or python as control characters and would thus need to be escaped. Since you need to escape from both bash and python, that would look really ugly. Except that you don't even want backslashes because...
- Although path names on windows use backslashes, path names in git don't. filter-repo doesn't do any \ -> / conversion for you. I suspect attempting to use backslashes will yield broken results (unless fast-import does something special I'm not aware of?)
- Everything in filter-repo is supposed to be bytestrings. Thus, you'd need
b'$(git hash-object ...)'
rather than `'$(git hash-object ...)'. - The final argument to FileChange is supposed to be a bytestring too rather than a bare integer. Thus b'100644' rather than 100644. Yeah, I know, my example in the comment in contrib/file-repo-demos/insert-beginning made this mistake; I'll fix it up.
from git-filter-repo.
This is looking better, but b'/MDC.7z' is still an absolute path (due to the leading slash). It should be the path within the repo you want the file known as. If you want it at the toplevel, then it's just b'MDC.7z'.
Does $(git hash-object -w '/C/MDC/MDC.7z') return the expected hash? Sorry, haven't used Windows in decades so I don't know how that side works.
Can you provide the output of .git/fast_import_crash_15656?
I suspect though that it's related to the "Empty path component found in input". i.e. it thinks you want the file stuck in $DIRNAME/$FILENAME (since you had one slash) where $DIRNAME is the empty string (an error) and $FILENAME is MDC.7z.
from git-filter-repo.
If you wanted /C/MDC/MDC.7z to appear within your repo in some subdirectory, let's say you wanted it under sources/archives/MDC.7z, then you'd use b'sources/archives/MDC.7z'
for the path. If you want it at the toplevel, then you'd use b'MDC.7z'
, as you did above.
Glad you've got it working. Does this answer all your questions?
from git-filter-repo.
I pushed up 4de3861 to try to avoid anyone else tripping over the same problems.
from git-filter-repo.
Yes, you can do it in the same command, but python makes it difficult to put multiple statements onto a single line so you may need some line breaks. It'd look something like:
git filter-repo --force --commit-callback "if not commit.parents:
commit.file_changes.append(FileChange(b'M', b'MDC.7z', b'$(git hash-object -w '/C/MDC MDC.7z')', b'100644'))
commit.file_changes.append(FileChange(b'M', b'some/other/file.txt', b'$(git hash-object -w '/C/Path/To/file.txt')', b'100644'))
"
or
git filter-repo --force --commit-callback "if not commit.parents: commit.file_changes += [
FileChange(b'M', b'MDC.7z', b'$(git hash-object -w '/C/MDC MDC.7z')', b'100644'),
FileChange(b'M', b'some/other/file.txt', b'$(git hash-object -w '/C/Path/To/file.txt')', b'100644')]"
The latter form could perhaps be put on one line, though it gets hard to read.
from git-filter-repo.
I'm assuming that has answered your questions, so I'll go ahead and close out. Let me know if that's not the case.
from git-filter-repo.
Discussed and fixed at https://stackoverflow.com/a/59033952/7976758. Recommend closing.
from git-filter-repo.
Hi
i tried changing the command to us bytestring also add this to the path - is that correct?
git filter-repo --force --commit-callback "if not commit.parents: commit.file_changes.append(FileChange(b'M', b'/MDC.7z', b'$(git hash-object -w '/C/MDC/MDC.7z')', b'100644'))"
Parsed 1 commitsfatal: Empty path component found in input
fast-import: dumping crash report to .git/fast_import_crash_15656
Traceback (most recent call last):
File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 3840, in <module>
filter.run()
File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 3777, in run
self._parser.run(self._input, self._output)
File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 1396, in run
self._parse_commit()
File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 1249, in _parse_commit
self._commit_callback(commit, aux_info)
File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 3335, in _tweak_commit
self._record_remapping(commit, orig_parents)
File "C:/Program Files/Git/mingw64/libexec/git-core\git-filter-repo", line 3128, in _record_remapping
self._output.flush()
OSError: [Errno 22] Invalid argument
from git-filter-repo.
thanks for your great & quick support
"b'/MDC.7z' is still an absolute path" - if i need it inside a path i use /pathname/mdc.7z?
With the following command it is running!!!!
git filter-repo --force --commit-callback "if not commit.parents: ```
commit.file_changes.append(FileChange(b'M', b'MDC.7z', b'$(git hash-object -w '/C/MDC/MDC.7z')', b'100644'))"
Parsed 8937 commits
from git-filter-repo.
If you wanted /C/MDC/MDC.7z to appear within your repo in some subdirectory, let's say you wanted it under sources/archives/MDC.7z, then you'd use
b'sources/archives/MDC.7z'
for the path. If you want it at the toplevel, then you'd useb'MDC.7z'
, as you did above.Glad you've got it working. Does this answer all your questions?
Hi
thank you very much , if i would like to add several files what would be the syntax?
Can i do it in the same command?
from git-filter-repo.
Related Issues (20)
- Update submodule hashes?
- Renaming paths into pre-existing path causes double-nested paths (sometimes)
- Keep last 3 months of package-lock.json diffs only HOT 1
- Question: prune lfs files
- remark: Pity that this tool can't run scripts/programs and it is not clearly stated HOT 1
- minor: Logic error with `_commits_referenced_but_removed` on a GitHub Gist web url in commit message 😂
- Crash when path contains emoji
- Question: Recommended way to log the usage of git filter-repo and related changes? HOT 1
- Callback that gives both filename and blob
- Breaking change in git 2.43 or 2.44 HOT 1
- lint-history: --refs argument not working at all
- Test suite succedes with Python 3.11 but has multiple failures with Python 3.12 HOT 4
- Turns out my assumption was wrong: `git lfs migrate export --everything --include="*"` does rewrite the whole history, across all branches, reinjecting all the large files' consecutive versions ([see here](https://github.com/git-lfs/git-lfs/issues/910#issuecomment-551566315)). Awesome! HOT 1
- Support for SHA256
- FR: Filter into new repo
- clean-ignore of filter-repo-demos does not handle utf-8 characters
- Trouble with Lock File HOT 1
- Really-43e2c HOT 2
- > main HOT 1
- Renaming path and then renaming it back to the original name deletes path rather than renaming it HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from git-filter-repo.