dulwich
dulwich copied to clipboard
porcelain diff does not support uncommitted changes
I can create a new repo with Git, git add
a change, then add another change, and git diff
the index with worktree:
> git init
> 'hello world' > hello.txt
> git add hello.txt
> 'world hello' >> hello.txt
> git diff
diff --git a/hello.txt b/hello.txt
index f35d3e6..d87f0a5 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1 +1,2 @@
hello world
+world hello
but Dulwich fails on the diff:
> dulwich diff
Traceback (most recent call last):
File "runpy.py", line 196, in _run_module_as_main
File "runpy.py", line 86, in _run_code
File "C:\python\Scripts\dulwich.exe\__main__.py", line 7, in <module>
File "C:\python\lib\site-packages\dulwich\cli.py", line 811, in main
return cmd_kls().run(argv[1:])
File "C:\python\lib\site-packages\dulwich\cli.py", line 180, in run
commit = parse_commit(r, commit_id)
File "C:\python\lib\site-packages\dulwich\objectspec.py", line 239, in parse_commit
raise KeyError(committish)
KeyError: b'HEAD'
ISn't this a dupe of #1147?
the page you linked says 404 for me
On Tue, Mar 07, 2023 at 01:47:41PM -0800, Steven Penny wrote:
the page you linked says 404 for me
Ah, I've got an email that says you created a similar bug (with id #1147) in February. Did you delete that by any chance?
If you look at how Dulwich's diff works, you can see that unlike Git's diff it can only compare commits, not uncommitted changes. Since the repo in your example doesn't contain any commit, Dulwich throws an error.
https://github.com/jelmer/dulwich/blob/06337ba383a260963a5e3a2547e349e6f69bd541/dulwich/cli.py#L172-L184
FWIW dulwich.cli is by no means compatible with C Git at the moment. Very happy to merge PRs that address this sort of issue and make it behave more like C Git.
Hey there, trying to catch up here...I got some questions. (btw, thanks for the this library it's pure :fire:)
-
Is there any advancement on the ability to get a diff on unstaged changes?
-
What are any/all users of this library doing in this scenario? What's their use-cases that don't need a 'git diff' of sorts?
-
Is there a technical reason this cannot be done [easily/straightforwardly]?
-
What would the effort look like if we wanted to take a stab at helping implement this?
Is there any advancement on the ability to get a diff on unstaged changes?
I don't believe anybody has worked on this recently; I definitely haven't. PRs very welcome :)
What are any/all users of this library doing in this scenario? What's their use-cases that don't need a 'git diff' of sorts?
There's lots of ways of interacting with git; personally I don't have a use for diffs, for example.
Is there a technical reason this cannot be done [easily/straightforwardly]? What would the effort look like if we wanted to take a stab at helping implement this?
It's probably quite a different codepath from what exists in the diff implementation today. Today, everything is based on existing Git objects and walking merkle trees. For diffing an an uncommitted tree, you'd probably want to either create those objects on the fly or (more efficient) compare them directly against what's in the repository.
It might make most sense to just create a separate porcelain_diff_worktree or something like that, rather than adding support to the existing code.
Let me know if I can provide more pointers.