Question about JM9 (Create a commit)

I am getting the following error:

remote: Debug = true
remote:
remote: [tester::#JM9] Running tests for Stage #JM9 (Create a commit)
remote: [tester::#JM9] Running git init
remote: [tester::#JM9] Creating some files & directories
remote: [tester::#JM9] Running git commit --all
remote: [tester::#JM9] Creating another file
remote: [tester::#JM9] $ ./your_program.sh commit-tree <tree_sha> -p <commit_sha> -m <message>
remote: [your_program] 8b7cd243b177aca80d692db82606d1a9f370ad1c
remote: [tester::#JM9] Running git cat-file commit <sha>
remote: [tester::#JM9] Expected "9cecd1eb9c8bf8ffb7a2a1809243531850a51e85" as tree, got: "0000000000000000000000000000000000000000"
remote: [tester::#JM9] Test failed

I coded the logic for creating a commit log file and reading from it, and for me it gets the right tree hash. There might be a mistake in my understanding of the commit log file format. However, I followed the information in the link carefully: What is the file format of a git commit object data structure? - Stack Overflow

So - before I start posting my multiple code files - is there any way to get a more indicative error? This is very confusing. There isn’t a sequence of zeroes in my log file, so I suspect this indicates some error in reading the log and I can’t get information as to what causes it.

Hi

Can you share the content of your commit file?

Maybe you’ve not formatted it properly since the test reads the tree sha as only zeros…

The stack overflow post you shared is good, I remember using the answer from Ciro Santilli to figure out the proper formatting.

1 Like

@ikarsh Just took a look at your code, and it’s nearly perfect! Just a small tweak is needed at the end of _generate_log_content.

- let res = body.into_inner();
- eprintln!("{res:?}");
- Vec::new()
+ body.into_inner()

@andy1li oh, I made it return an empty vector for debugging. The exact same bug happened when I returned the correct value. (thanks for reading it though!)

1 Like

@ikarsh My bad. I took another closer look:

  • The main issue is that the hashes shouldn’t be raw bytes (20 bytes long), but rather their hexadecimal representation (40 characters long).
  • Additionally, there are some missing newline characters.

The correct commit content should look like this:

@andy1li thanks a lot!!
Wow, the error message was bad. I didn’t realize the mistake was because of different encoding conventions :slight_smile:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.