1

I have 2 repositories at github: 1st is for a cURL library, 2nd is for a project I'm writing. I'm trying to add my library as submodule to my project:

cd /www/fifa14api/CI-FIFA14-API/
git submodule add [email protected]:ctepeo/CI-cURL.git

My project based on CodeIgniter, so file structure looks like

/application/
/system/
index.php

My library at repo have prepared for CodeIgniter structure:

/application/
     /libraries/
         curl.php

When I add submodule, I want to "merge" them (to put my curl.php at right directory in project), but it creates CI-cURL (repo name) folder at root, so I got

/application/
/system/
/CI-cURL/
    /application/
        curl.php
index.php

How can I (and is it possible?) to exclude repository's name when adding submodule?

1
  • Since 2014 quite a lot of things changed and nowadays I'd recommend to use package managers for libraries (like i needed cURL one) and keep it into two different repos for sources. And then just to add a package with cURL into the project (via composer for php in this specific question) Commented Dec 15, 2023 at 8:57

2 Answers 2

1

Git submodules are fully-fledged git repositories, so you can't check out just part of a git repo using submodules: it needs to have its own folder. You can, however, name that folder whatever you like: git submodule add git@hostname:location.git path/to/module clones the submodule to path/to/module in your git repo.

Sign up to request clarification or add additional context in comments.

3 Comments

So there's no way to implement library from one github repo to another project? I don't think so.
No, that's not what I said: you can't just get one file from a github repo. You could mount the submodule's git repository in application/libraries/CI-cURL/ just fine. You could also mount it in application/libraries/ but then you won't be able to add other libraries: dropping them in application/libraries would add them to the CI-cURL repo.
Oh, ok, thanks for explanation, I do not understand correctly first. I'll restructure my lib and put it directly to my libraries' folder with CI-cURL folder. Thanks!
0

With Git 2.44 (Q1 2024), "git add"(man) and git stash(man) learned to support the ":(attr:...)" magic pathspec.

That means your scenario (submodules without a repo name) is supported:

git add . ':(exclude,attr:submodule)'

See commit 1164c72 (03 Nov 2023) by Joanna Wang (joannajw).
(Merged by Junio C Hamano -- gitster -- in commit d8b0ec4, 09 Dec 2023)

attr: enable attr pathspec magic for git-add and git-stash

Signed-off-by: Joanna Wang

Allow users to limit or exclude files based on file attributes during git-add(man) and git-stash.

For example, the chromium project would like to use

$ git add . ':(exclude,attr:submodule)'

as submodules are managed by an external tool, forbidding end users to record changes with git add.
Allowing "git add" to often records changes that users do not want in their commits.

This commit does not change any attr magic implementation.
It is only adding attr as an allowed pathspec in git-add and git-stash, which was previously blocked by GUARD_PATHSPEC and a pathspec mask in parse_pathspec()).

However, we fix a bug in prefix_magic() where attr values were unintentionally removed.
This was triggerable when parse_pathspec() is called with PATHSPEC_PREFIX_ORIGIN as a flag, which was the case for git-stash (Bug originally filed here)

Furthermore, while other commands hit this code path it did not result in unexpected behavior because this bug only impacts the pathspec->items->original field which is NOT used to filter paths.
However, git-stash(man) does use pathspec->items->original when building args used to call other git commands.
(See add_pathspecs() usage and implementation in stash.c)

It is possible that when the attr pathspec feature was first added in b0db704 ("pathspec: allow querying for attributes", 2017-03-13, Git v2.13.0-rc0 -- merge listed in batch #5), "PATHSPEC_ATTR" was just unintentionally left out of a few GUARD_PATHSPEC() invocations.

Later, to get a more user-friendly error message when attr was used with git-add, PATHSPEC_ATTR was added as a mask to git-add's invocation of parse_pathspec() 84d938b ("add: do not accept pathspec magic 'attr'", 2018-09-18, Git v2.20.0-rc0 -- merge listed in batch #2).
However, this user-friendly error message was never added for git-stash.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.