Skip to content

Conversation

@bicschneider
Copy link
Collaborator

@bicschneider bicschneider commented Aug 13, 2025

Summary by CodeRabbit

  • New Features

    • Added git-artifact command "add-as-submodule" (add repo as submodule by URL+path).
    • CLI options: -d/--debug and -t/--testcase to enable debug mode and run a single test.
  • Bug Fixes

    • More robust tag discovery/fetch/checkout and improved argument handling/quoting.
  • Documentation

    • Updated help/usage to include the new command and options.
  • Tests

    • Modernized test runner with dynamic discovery, centralized per-test logs, per-test failure handling, consolidated summary, and a new end-to-end submodule test.

@coderabbitai
Copy link

coderabbitai bot commented Aug 13, 2025

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between 234a042 and 955ee6d.

📒 Files selected for processing (1)
  • git-artifact (5 hunks)
 ___________________________________________________________________________________________________________________________________
< Don't use manual procedures. A shell script or batch file will execute the same instructions, in the same order, time after time. >
 -----------------------------------------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

Walkthrough

Adds a new git-artifact command add-as-submodule and related tag/fetch refinements; overhauls the test harness for numeric test discovery, per-test logging under root_folder/${test}, single-test execution, adds test 10 (submodule) and updates test 9, and consolidates run summaries with failure log dumping.

Changes

Cohort / File(s) Summary
Test harness modernization & new tests
_tests.sh
Adds -d/--debug alias and -t/--testcase to run a single numeric test; implements dynamic discovery/execution of numbered test functions with per-test run logs under root_folder/${test} and non-aborting failure capture; updates test 9 prune/fetch flow; adds test 10 (add-as-submodule); consolidates end-of-run summary, failed-log dumping, stricter shell options, PATH setup, and single-test validation.
New command and CLI routing in git-artifact
git-artifact
Introduces cmd_add-as-submodule() and add-as-submodule in OPTS_SPEC; validates --url/--path; prepares .git/modules/${path}, clones the remote into the path using a separate GIT_DIR (single-branch, no-tags) and registers via git submodule add --force; rewrites read_remote_tags_to_map() to parse git ls-remote line-by-line; improves tag/fetch quoting and cmd_fetch-tags robustness; extends main() routing and help text.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant git-artifact
  participant Git

  User->>git-artifact: git-artifact add-as-submodule --url U --path P
  git-artifact->>git-artifact: validate args, ensure work-tree
  git-artifact->>git-artifact: abort if path P exists
  git-artifact->>Git: prepare .git/modules for P
  git-artifact->>Git: clone U into P (separate GIT_DIR, single-branch, no-tags)
  git-artifact->>Git: git submodule add --force U P
  git-artifact-->>User: print remote/status hints (ready to commit)
Loading
sequenceDiagram
  participant Dev
  participant _tests.sh
  participant TestFn as Numeric Test Functions
  participant FS as Logs/Filesystem

  Dev->>_tests.sh: run (optional -t <#>, -d)
  alt single testcase provided
    _tests.sh->>TestFn: validate existence, invoke selected test
  else run all
    _tests.sh->>_tests.sh: discover numeric test functions
    loop for each test
      _tests.sh->>TestFn: execute with per-test guard
      TestFn->>FS: write root_folder/${test}/run.log and git-test.log
      _tests.sh->>_tests.sh: capture failure, mark global exit code
    end
  end
  _tests.sh-->>Dev: consolidated summary, dump failed logs if any, exit code
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Poem

I dig through branches, nibble bytes and logs,
I tuck submodules safe in mossy cogs.
Ten tests drum softly, one added today,
Prune, fetch, commit — we hop on our way. 🥕

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 6-add-function-to-add-repos-as-submodules-without-clone-the-whole-repo-but-only-the-default-branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
git-artifact (1)

72-85: Fix inconsistent spacing in command descriptions

Line 77 has inconsistent tab/space usage that should be fixed for better readability.

-fetch-co   	     Fetch tag from remote and checkout it out
+fetch-co         Fetch tag from remote and checkout it out
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb2c48d and 4447fa1.

⛔ Files ignored due to path filters (1)
  • .test/10/git-reference.log is excluded by !**/*.log
📒 Files selected for processing (2)
  • _tests.sh (4 hunks)
  • git-artifact (3 hunks)
🔇 Additional comments (11)
_tests.sh (8)

2-3: LGTM!

Adding shellcheck suppressions at the global level is appropriate. SC2317 (unreachable code) and SC2329 (unset variable check) are often false positives in test scripts with dynamic function invocation.


12-14: LGTM!

The updated option handling for debug mode and the new test case selector option enhance the test framework's flexibility and usability.


177-177: LGTM! Consistent use of absolute logging paths

The update to use absolute paths (${root_folder}/${test}/run.log) across all test functions ensures consistent logging behavior and prevents issues when changing directories during test execution.

Also applies to: 191-191, 206-206, 219-219, 236-236, 271-271


287-287: LGTM! Enhanced logging structure

The consistent pattern of redirecting logs to absolute paths and improving error handling across test cases makes debugging much easier. The addition of appropriate error handling with log output on failure is particularly valuable.

Also applies to: 331-331, 365-365, 392-401, 426-427


439-442: Good addition of error handling in the test runner

The error handling for individual test failures with proper exit code propagation improves the robustness of the test suite.


455-478: Excellent comprehensive test reporting

The post-run reporting block provides excellent visibility into test failures by:

  • Showing a clear summary header
  • Displaying contents of failed test logs
  • Listing all failing log files for easy reference

This greatly improves the debugging experience.


110-111: Absolute paths validated
The root_folder variable is initialized at the top of _tests.sh (line 86) before any calls to generate_git_test_log, so all invocations use a correctly set absolute path. No further action required.


404-431: Confirmed add-as-submodule implementation

I’ve verified that:

• The cmd_add-as-submodule() function is defined in git-artifact at line 397 and implements the clone + git submodule add.
• The flags --url (lines 523–526) and --path (lines 535–538) are parsed and required.
• It’s wired into the dispatcher under the add-as-submodule) case (around line 658).

The new test invokes git artifact add-as-submodule --url … --path …, commits, pushes, fetches, and captures .gitmodules, exercising the full flow. Everything looks correct—approving these changes.

git-artifact (3)

95-97: LGTM! CLI integration for add-as-submodule command

The command is properly integrated into the help text and options specification.


397-429: Review the add-as-submodule implementation logic

The function implementation looks correct with proper validation and clear user guidance. However, there's a potential issue with the arg_remoteurl variable name used on line 411.

Line 411 uses ${arg_remoteurl} but line 667 suggests it should be ${arg_path}. Please verify the correct variable names:

-    git clone --single-branch --no-tags --separate-git-dir="./.git/modules/${arg_path}" "${arg_remoteurl}" "${arg_path}"
+    git clone --single-branch --no-tags --separate-git-dir="./.git/modules/${arg_path}" "${arg_remoteurl}" "${arg_path}"

Likely an incorrect or invalid review comment.


658-670: Validation error messages consistent across commands

I verified that the add-as-submodule command’s error messages:

  • ERROR: --url <url> required for $arg_command
  • ERROR: --arg_path <path> required for $arg_command

match the same “ERROR: … required for $arg_command” pattern used elsewhere. No changes required.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
git-artifact (1)

95-97: Clarify option usage in help text.

The help text for options shows 'init', 'clone' and 'add-as-submodule' but the actual option parsing logic expects different parameter names for add-as-submodule.

Apply this diff to clarify the help text:

- options for 'init', 'clone' and 'add-as-submodule' 
+ options for 'init', 'clone' and 'add-as-submodule'
 u,url=          the remote url
-p,path=         the optional path for init and clone 
+p,path=         the optional path for init and clone, required path for add-as-submodule
_tests.sh (1)

2-3: Remove unnecessary shellcheck disables.

The summary mentions that per-function shellcheck disable markers were removed, but these global disables remain. Consider if these are still necessary.

Verify if these shellcheck disables are still needed:

#!/bin/bash
# Check what shellcheck issues these disables are suppressing
shellcheck _tests.sh --format=gcc | grep -E "(SC2317|SC2329)"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb2c48d and 4447fa1.

⛔ Files ignored due to path filters (1)
  • .test/10/git-reference.log is excluded by !**/*.log
📒 Files selected for processing (2)
  • _tests.sh (4 hunks)
  • git-artifact (3 hunks)
🔇 Additional comments (7)
git-artifact (2)

72-85: Update option specifications for the new command.

The OPTS_SPEC section correctly adds the new add-as-submodule command to the help text. The formatting and descriptions are consistent with existing commands.


397-429: LGTM! Well-structured implementation of add-as-submodule command.

The function correctly implements the special submodule addition workflow:

  • Validates that the target path doesn't exist
  • Creates the Git modules directory structure
  • Clones with appropriate flags (single-branch, no-tags, separate-git-dir)
  • Registers as a submodule with force flag
  • Provides helpful user guidance

The implementation addresses the performance concern mentioned in comments about avoiding large clones.

_tests.sh (5)

12-14: LGTM! Consistent option additions.

The debug option and single test case selector are well-implemented and follow the existing pattern.


391-402: Improve test robustness with better output handling.

The test correctly implements the dry-run and actual prune workflow. The logging structure is well-organized with per-test logs.


404-431: LGTM! Comprehensive test for the new add-as-submodule functionality.

The test thoroughly exercises the new command:

  • Sets up a base repository
  • Adds it as a submodule using relative path
  • Commits and pushes the changes
  • Verifies the state including .gitmodules content

The test structure follows the established pattern and includes proper logging.


439-443: Improve error handling in test execution.

The current error handling captures test failures but continues execution. This is good for getting a complete test report.


461-480: LGTM! Excellent test result reporting.

The final summary provides comprehensive information about test results, including:

  • Success/failure status
  • Contents of failed test logs for debugging
  • List of all failed log files
  • Proper exit code handling

This makes debugging test failures much easier.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
git-artifact (1)

72-116: Polish help text: fix typos, grammar, and consistency in OPTS_SPEC

Several descriptions contain typos and inconsistent phrasing. Tightening these improves UX and keeps help output professional.

Apply this diff:

- init             Inititialize a new repository
- clone            Clone and existing repository from the remote
- add-n-tag        Add and commit files to repo abd leave workspace on tag/untouched
- push             push a tag
- add-n-push       Add and commit files to repo and then push them
- fetch-co         Fetch tag from remote and checkout it out
- reset            Reset workspace and branches
- list             List all tags in the repo given a glob pattern
- summary          Print a summary of the tags in the repo
- prune            Prune tags in the repo given a glob pattern and keep amount of tags
- find-latest      Find the latest tags from reqex and print it
- fetch-co-latest  Get latest tag form remote using grep reg-ex and reset hard to it
- fetch-tags       Fetch all tags that points to a sha1 or HEAD - Useful in relation to detached HEAD and submodules
- add-as-submodule Add a submodule in a clever way to the current consuming repository. Special operation to avoid big clones .
+ init             Initialize a new repository
+ clone            Clone an existing repository from a remote
+ add-n-tag        Add and commit files to the repo and leave the workspace at the tag (detached)
+ push             Push a tag
+ add-n-push       Add and commit files to the repo and then push them
+ fetch-co         Fetch a tag from the remote and check it out
+ reset            Reset the workspace and branches
+ list             List tags matching a glob pattern
+ summary          Print a summary of tags in the repo
+ prune            Prune tags matching a glob pattern, keeping a fixed number
+ find-latest      Find the latest tag matching a glob and print it
+ fetch-co-latest  Fetch and check out the latest tag matching a glob
+ fetch-tags       Fetch all tags that point to a SHA-1 or HEAD (useful for detached HEAD and submodules)
+ add-as-submodule Add a repository as a submodule to the current repo (clones with --no-tags and --single-branch)
@@
- h                show the help
- q                quiet
- v,verbose        verbose
- d                show debug messages
+ h                show help
+ q                quiet output
+ v,verbose        verbose output
+ d                show debug messages
@@
- options for 'init', 'clone' and 'add-as-submodule' 
- u,url=          the remote url
- p,path=         the optional path for init and clone, mandatory for add-as-submodule 
+ options for 'init', 'clone', and 'add-as-submodule'
+ u,url=           The remote URL
+ p,path=          Optional path for init and clone; mandatory for add-as-submodule
@@
- b,branch=       use branch for local changes and pushes
+ b,branch=        Use the branch for local changes and pushes
@@
- t,tag=          the tag to be created
+ t,tag=           The tag to create
@@
- g,glob=         the glob pattern search remote for tags
+ g,glob=          Glob pattern to match remote tags
@@
- s,sha1=         The sha1 of which to get tags from from 
+ s,sha1=          SHA-1 for which to fetch matching tags
@@
- k,keep=         The amount of tags to keep - default is 20 
+ k,keep=          Number of tags to keep (default: 20)
@@
- delimiter=      The delimiter to use for the summary - default is '/'
+ delimiter=       Delimiter used in the summary (default: '/')
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 10baa80 and df67af1.

📒 Files selected for processing (1)
  • git-artifact (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-14T08:57:11.148Z
Learnt from: bicschneider
PR: Praqma/git-artifact#33
File: git-artifact:397-429
Timestamp: 2025-08-14T08:57:11.148Z
Learning: When reviewing AI summaries that mention multiple new functions, verify they are actually in the same file before flagging duplicate definitions. Test functions and command functions can have similar naming patterns but serve different purposes.

Applied to files:

  • git-artifact
🔇 Additional comments (3)
git-artifact (3)

179-182: Quoting fix in fetch/reset is correct

Using a quoted ref for the default remote branch in fetch/reset is safer and avoids word-splitting/globbing surprises. LGTM.


470-472: Safer quoting when fetching and checking out latest tag

Quoting the refnames is a good hardening step and avoids edge cases with unusual tag names. LGTM.


659-671: Good argument validation for add-as-submodule

Requiring a work tree and validating both --url and --path matches the contract described in the help. Consistent error messaging.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
git-artifact (1)

477-479: Improve variable scoping and error messaging.

Based on past review feedback, this section could benefit from better variable scoping and more informative error messages.

The variable should be declared as local and the error message should include the queried SHA-1 for better debugging.

🧹 Nitpick comments (1)
git-artifact (1)

397-429: Enhance robustness for nested paths and persistent configuration.

The implementation is functionally correct but could benefit from several robustness improvements:

  1. Nested path support: The current mkdir -p "./.git/modules/" won't create intermediate directories for nested submodule paths
  2. Persistent no-tags configuration: The --no-tags option only applies to the initial clone, not future fetches
  3. Gitdir absorption: Should ensure the submodule's gitdir is properly absorbed under the superproject
  4. Enhanced user feedback: Could show both superproject and submodule remotes for better visibility

Apply this diff to enhance the function:

     if [[ -d ${arg_path} ]]; then
         echo "ERROR: Directory '${arg_path}' already exists"
         exit 1
     fi
 
-    mkdir -p "./.git/modules/"
-    echo "Cloning repo into .git/modules/${arg_path} but working tree is: ${arg_path}"
-    git clone --single-branch --no-tags --separate-git-dir="./.git/modules/${arg_path}" "${arg_remoteurl}" "${arg_path}"
-    
-    echo "Adding the repo as submodule"
-    git submodule add --force "${arg_remoteurl}" "${arg_path}"
-    echo
+    # Ensure parent dir for the submodule gitdir exists (supports nested paths)
+    local modules_gitdir=".git/modules/${arg_path}"
+    mkdir -p "$(dirname "$modules_gitdir")"
+    echo "Cloning repo into ${modules_gitdir} with working tree: ${arg_path}"
+    git clone --single-branch --no-tags --separate-git-dir="${modules_gitdir}" "${arg_remoteurl}" "${arg_path}"
+
+    # Persist 'no-tags' for subsequent fetches performed in the submodule
+    git -C "${arg_path}" config remote.origin.tagOpt --no-tags
+
+    echo "Adding the repo as submodule"
+    git submodule add --force "${arg_remoteurl}" "${arg_path}"
+    # Ensure submodule gitdir is absorbed under the superproject (idempotent)
+    git submodule absorbgitdirs -- "${arg_path}"
+    echo
 
-    git remote -v
-    echo
+    echo "Superproject remotes:"
+    git remote -v
+    echo
+    echo "Submodule remotes for ${arg_path}:"
+    git -C "${arg_path}" remote -v
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between df67af1 and fdbf1c5.

📒 Files selected for processing (1)
  • git-artifact (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-14T08:57:11.148Z
Learnt from: bicschneider
PR: Praqma/git-artifact#33
File: git-artifact:397-429
Timestamp: 2025-08-14T08:57:11.148Z
Learning: When reviewing AI summaries that mention multiple new functions, verify they are actually in the same file before flagging duplicate definitions. Test functions and command functions can have similar naming patterns but serve different purposes.

Applied to files:

  • git-artifact
🧬 Code Graph Analysis (1)
git-artifact (1)
_tests.sh (1)
  • generate_base_repo (66-83)
🔇 Additional comments (5)
git-artifact (5)

72-85: LGTM! Good command addition with clear documentation.

The addition of the add-as-submodule command to the OPTS_SPEC is well-integrated with appropriate documentation describing its purpose as a "clever way" to avoid big clones.


95-97: LGTM! Appropriate option specification.

The option specification correctly includes add-as-submodule for the --url option and appropriately specifies that --path is required for this command while being optional for init and clone.


179-179: LGTM! Consistent quoting improvement.

Good improvement to consistently quote the remote reference in the fetch command.


470-471: LGTM! Consistent quoting improvements.

Good improvements to consistently quote variables in the git operations.


659-671: LGTM! Proper argument validation for the new command.

The argument validation correctly:

  • Sources git-sh-setup and requires a work tree
  • Validates that both --url and --path are provided
  • Uses consistent error message formatting
  • Provides appropriate exit codes

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
git-artifact (1)

481-483: Consider refactoring for better maintainability and error reporting.

The current implementation has some areas for improvement:

  1. The tags variable should be declared as local
  2. The pipeline could be more readable and efficient
  3. The error message should include which SHA-1 was queried for better debugging
🧹 Nitpick comments (1)
git-artifact (1)

397-433: Function implementation is solid, but consider robustness enhancements.

The add-as-submodule function implements the core logic correctly with proper directory existence checks and appropriate git operations. The user guidance messages are helpful.

However, there are opportunities to improve robustness for production use:

  1. Nested path support: For paths like vendor/tools/artifact, the parent directory of .git/modules/${arg_path} may not exist
  2. Tag persistence: The --no-tags option only applies to the initial clone, but future fetches in the submodule won't inherit this behavior
  3. Gitdir absorption: Ensuring the submodule's gitdir is properly absorbed under the superproject
  4. Enhanced feedback: Showing both superproject and submodule remotes for better visibility

Apply this diff for enhanced robustness:

     if [[ -d ${arg_path} ]]; then
         echo "ERROR: Directory '${arg_path}' already exists"
         exit 1
     fi
 
-    # Ensure parent dir for the submodule gitdir exists (supports nested paths)
-    local modules_gitdir=".git/modules/${arg_path}"
-    mkdir -p "$(dirname "$modules_gitdir")"
-    echo "Cloning repo into ${modules_gitdir} with working tree: ${arg_path}"
-    git clone --single-branch --no-tags --separate-git-dir="${modules_gitdir}" "${arg_remoteurl}" "${arg_path}"
+    # Ensure parent dir for the submodule gitdir exists (supports nested paths)
+    local modules_gitdir=".git/modules/${arg_path}"
+    mkdir -p "$(dirname "$modules_gitdir")"
+    echo "Cloning repo into ${modules_gitdir} with working tree: ${arg_path}"
+    git clone --single-branch --no-tags --separate-git-dir="${modules_gitdir}" "${arg_remoteurl}" "${arg_path}"
+
+    # Persist 'no-tags' for subsequent fetches performed in the submodule
+    git -C "${arg_path}" config remote.origin.tagOpt --no-tags
 
     echo "Adding the repo as submodule"
     git submodule add --force "${arg_remoteurl}" "${arg_path}"
+    # Ensure submodule gitdir is absorbed under the superproject (idempotent)
+    git submodule absorbgitdirs -- "${arg_path}"
     echo
     
     echo "#############################################################################"
     echo "# HINT: You can use the ../ notation in submodule path to avoid the full url," 
     echo "#       if your remote server is the same as the submodule server            "
     echo "#       .. to ensure portability of the repositories                         "
     echo "#############################################################################"
     echo
-    echo "Superproject remotes:"
-    git remote -v
-    echo
-    echo "${arg_path} : ${arg_remoteurl}"
-    echo 
+    echo "Superproject remotes:"
+    git remote -v
+    echo
+    echo "Submodule remotes for ${arg_path}:"
+    git -C "${arg_path}" remote -v
+    echo
     echo "You are now ready to commit ..."
     git status
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between fdbf1c5 and 04f633d.

📒 Files selected for processing (2)
  • _tests.sh (4 hunks)
  • git-artifact (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-14T08:57:11.148Z
Learnt from: bicschneider
PR: Praqma/git-artifact#33
File: git-artifact:397-429
Timestamp: 2025-08-14T08:57:11.148Z
Learning: When reviewing AI summaries that mention multiple new functions, verify they are actually in the same file before flagging duplicate definitions. Test functions and command functions can have similar naming patterns but serve different purposes.

Applied to files:

  • git-artifact
🔇 Additional comments (9)
git-artifact (4)

72-85: LGTM! Well-structured command specification update.

The OPTS_SPEC updates correctly integrate the new add-as-submodule command with appropriate option groupings and help text. The command description clearly explains its purpose.


179-179: LGTM! Improved remote reference quoting.

Good improvement to properly quote the remote branch reference for consistency and robustness.


474-475: LGTM! Improved fetch command with proper quoting.

The quoting of the tag reference in both the fetch and checkout commands improves consistency and handles edge cases better.


663-675: LGTM! Proper validation for the new command.

The parameter validation correctly requires both --url and --path for the add-as-submodule command, with appropriate error messages and git setup requirements.

_tests.sh (5)

2-3: LGTM! Appropriate shellcheck disables for test script.

The shellcheck disables (SC2317 for unreachable code and SC2329 for function parsing) are appropriate for a test script where functions are called dynamically.


12-14: LGTM! Clear CLI enhancements.

The addition of -d/--debug and -t/--testcase options with clear documentation improves the test script's usability for development and debugging.


391-402: LGTM! Enhanced test 9 with comprehensive prune workflow.

The test correctly implements the full prune workflow: dry-run first, actual prune, fetch to sync, and then list to verify results. The logging captures the complete sequence for validation.


404-429: LGTM! Well-structured submodule test.

Test 10 properly validates the new add-as-submodule functionality by:

  1. Setting up a base repository
  2. Adding it as a submodule with a relative path
  3. Committing and pushing the changes
  4. Capturing the .gitmodules content and git status for verification

The test integrates well with the existing test framework and logging structure.


437-441: LGTM! Improved error handling for test execution.

The error handling correctly captures test failures without aborting the entire test run, maintaining the global exit code for final reporting.

@bicschneider bicschneider merged commit f2e2d06 into main Aug 14, 2025
6 checks passed
@bicschneider bicschneider deleted the 6-add-function-to-add-repos-as-submodules-without-clone-the-whole-repo-but-only-the-default-branch branch August 14, 2025 12:16
@bicschneider bicschneider self-assigned this Aug 14, 2025
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.

Add function to add repos as submodules without clone the whole repo but only the default branch

2 participants