Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store exact submodule commit for --treeish #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

KSR-Yasuda
Copy link

@KSR-Yasuda KSR-Yasuda commented Feb 7, 2024

Fix for #30.

For the target main repository commit,
check the bound submodule commit by git ls-tree.

@KSR-Yasuda
Copy link
Author

KSR-Yasuda commented Feb 7, 2024

Although, there still exist some other issues:

  1. not working if submodule structure is different between the current worktree and the target --treeish commit
    (e.g. submodules added, removed, or path changed)
    • Since it searches submodules by git submodule status for the current worktree.
      I have no idea to fix this without git checkout the target commit.
  2. probably not supporting sub-submodules

@KSR-Yasuda KSR-Yasuda marked this pull request as draft February 8, 2024 01:45
@KSR-Yasuda KSR-Yasuda force-pushed the bugfix/SubmoduleTreeish branch from f44d5d0 to a41f294 Compare February 8, 2024 01:49
@KSR-Yasuda
Copy link
Author

KSR-Yasuda commented Feb 8, 2024

  1. probably not supporting sub-submodules

It has failed to check sub-submodule hash by git ls-tree.

Instead, git submodule --recursive --cached may work.

@KSR-Yasuda KSR-Yasuda marked this pull request as ready for review February 8, 2024 01:52
@KSR-Yasuda
Copy link
Author

Test repository prepare script: testinit.sh

This creates repos that has submodules recursively:

a/                                  # -> a.git
|-- a.txt
`-- b/                              # -> b.git
    |-- b.txt
    `-- c/                          # -> c.git
        |-- c.txt
        `-- d/                      # -> d.git
            `-- d.txt

Each repos are created to have commits as below:

% git -C a log --oneline
f44f622 (HEAD -> master, origin/master) a2      # Add one more line into `a.txt`
abafa99 submodule b                             # Add a submodule, that points to the one-line commit
e278ee0 a                                       # One line in `a.txt`
e513e03 Initial commit

Each repos' HEAD is on X2 (2 lines in text) commit after the script called,
but pointed to X (1 line in text) commit.

So, expected archive would be as below:

% git -C a archive-all --format tar.gz --prefix a/ -t @ ../test.tar.gz
% tar -tvf test.tar.gz
drwxrwxr-x root/root         0 2024-02-08 11:04 a/
-rw-rw-r-- root/root        80 2024-02-08 11:04 a/.gitmodules
-rw-rw-r-- root/root         4 2024-02-08 11:04 a/a.txt                 # Top repo is pointing to the commit `a2`
drwxrwxr-x root/root         0 2024-02-08 11:04 a/b/
drwxrwxr-x root/root         0 2024-02-08 11:04 a/b/
-rw-rw-r-- root/root        80 2024-02-08 11:04 a/b/.gitmodules
-rw-rw-r-- root/root         2 2024-02-08 11:04 a/b/b.txt               # The workdir is the commit `b2`, though, top repo mean it to be the commit `b`
drwxrwxr-x root/root         0 2024-02-08 11:04 a/b/c/
drwxrwxr-x root/root         0 2024-02-08 11:04 a/b/c/
-rw-rw-r-- root/root        80 2024-02-08 11:04 a/b/c/.gitmodules
-rw-rw-r-- root/root         2 2024-02-08 11:04 a/b/c/c.txt             # The workdir is the commit `c2`, though, top repo mean it to be the commit `c`
drwxrwxr-x root/root         0 2024-02-08 11:04 a/b/c/d/
drwxrwxr-x root/root         0 2024-02-08 11:04 a/b/c/d/
-rw-rw-r-- root/root         2 2024-02-08 11:04 a/b/c/d/d.txt           # The workdir is the commit `d2`, though, top repo mean it to be the commit `d`

# Text files for
# `X2` (two lines) commit are 4 bytes; and
# `X`  (one line)  commit are 2 bytes.

@KSR-Yasuda KSR-Yasuda marked this pull request as draft February 8, 2024 05:35
@KSR-Yasuda
Copy link
Author

Umm..., this is still not working well.

git ls-tree TREEISH SUBMODULE_DIR can check exact submodule ref, but not supporting sub-submodules.

On the other hand, git submodule status --recursive --cached can check all descendant submodules,
but it only checks for top repo's current HEAD.
Not for given treeish commit.

<top>           <submodule>
                commitC (HEAD)
                 :
HEAD    ------> commitB
 :               :
TREEISH ------> commitA

git ls-tree TREEISH submodule returns commitA for submodule,
not the current HEAD of the submodule.

git submodule status --recursive --cached returns commitB,
since the command can't receive top repo's TREEISH id.

@KSR-Yasuda KSR-Yasuda force-pushed the bugfix/SubmoduleTreeish branch from a41f294 to 4f11a32 Compare February 8, 2024 05:59
@KSR-Yasuda KSR-Yasuda marked this pull request as ready for review February 8, 2024 06:57
@KSR-Yasuda
Copy link
Author

git ls-tree TREEISH submodule returns commitA for submodule, not the current HEAD of the submodule.

git submodule status --recursive --cached returns commitB, since the command can't receive top repo's TREEISH id.

So, use git ls-tree if available (i.e. for direct submodule),
otherwise git submodule status --recursive --cached (i.e. for sub-submodules).

Since this is not complete, output warning messages as below:

  • Warning: Submodule "sub/submodule" hash for top repo's <TOP_TREEISH> was not obtained. Use the commit for top repo's HEAD.
    • The case of git ls-tree failed.
  • Warning: Submodule "submodule" hash for top repo's HEAD was not obtained. Use the commit for the submodule's HEAD.
    • The case of git submodule status --recursive --cached failed.

Also, show used submodules' hash as the message below:

  • Submodule "submodule" commit for top repo's <TOP_TREEISH>: <TREEISH> (<TREEISH_SHORT_NAME>)

@KSR-Yasuda
Copy link
Author

KSR-Yasuda commented Feb 8, 2024

Fix submodule's git ls-tree hash finding.
Now it tries to call git ls-tree for sub-submodules in direct submodules.

@KSR-Yasuda KSR-Yasuda force-pushed the bugfix/SubmoduleTreeish branch from 207f62a to 1c522f9 Compare February 9, 2024 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant