Add a submodule with Gitpython - gitpython

How can I add a submodule with Gitpython?
I know how I add it the normal way but I do not find any help in the docs from Gitpython how I can add it with the lib.
many thanks

You can refer to Gitpython API,
As it said, you can do:
from git import Repo, Submodule
repo = Repo(ROOT_REPO_PATH)
Submodule.add(repo, SUBMODULE_NAME, SUBMODULE_PATH, SUBMODULE_URL)

Related

Modify underlying Go sub dependency on the package I am using

I am getting this error from go mod tidy when I am trying to update my dependancies. I am primarily developing a webhook service to use with cert-manager and I cannot figure out how to resolve this dependency isssue since the packages I am dependent on are created by other developers and I cannot control those "sub dependency".
This is my output:
go.opentelemetry.io/otel/semconv: module go.opentelemetry.io/otel#latest found (v1.9.0), but does not contain package go.opentelemetry.io/otel/semconv
I looked the package up here: https://pkg.go.dev/go.opentelemetry.io/otel/semconv
and the problem for me seems like that the package have been restructured like this:
go.opentelemetry.io/otel/semconv/v1.9.0
as a subdirectory instead of package version.
Is there a way I can manipulate the underlying dependancy of the packages that my service is depending on?
Please leave a comment if you need addictional information.
Take a look at the accepted solution's comments
You may want to use a local copy of the module where you can fix the issue and use it. Steps for that
Clone the module repository git clone https://github.com/open-telemetry/opentelemetry-go.git
If needed, checkout to a branch/tag git checkout branch_name
In the go.mod file of your module, add the following lines
replace (
go.opentelemetry.io => /path/where/cloned/opentelemetry-go
)
Now you should be able to modify code in the cloned opentelemetry-go repo and use it in your module

Upload Go project to GitHub Repository

How can i successfully upload my Go project to existing github repository? Here is how my $GOPATH looks like: /home/user/go.
There I have created the following directories: src/github.com/StefanCepa/ . And inside that directory I have 2x directories which represent two different projects. I would like each of those projects to be posted on seperate github repository.
Any ideas how can I do that? Commiting stuff written in Go on github is kinda confusing to me.
This is done the same way that you would initialize and commit a new repository regardless of the language.
Go just makes it a little easier to find your other Go projects thanks to the $GOPATH and the standards of the language. Simple example below.
Within project 1:
$ cd ~/go/src/github.com/StefanCepa/projectOne/
$ git init
$ git add .
$ git commit -m 'init'
$ git remote add origin https://github.com/StefanCepa/projectOne.git
$ git push -u origin master
Within project 2:
*same process as above

Using GitPython to download a specific version

How can I clone a repository but just using the branch,
the tag or the exact commit?
REPO = git.Repo.clone_from(url, tmpdirname, branch=branch
Something like above download all the repository...

What to do if I want to make changes to a forked repository only to find that I can not because the forked package import itself

Like this github repository, I forked the repository and made some changes to the code. When I run it, my changes are not in effect because the original code imports itself. I could simply just change the import library to mine like "import github.com/brucewangno1/ytdl". But is there any other clean way to avoid this?
Another easy way is to use go get instead:
$ go get github.com/original/a_library
$ cd $GOPATH/src/github.com/original/a_library
$ git remote add my_origin https://github.com/myaccount/a_library
In your case it will be
$ go get github.com/rylio/ytdl
$ cd $GOPATH/src/github.com/rylio/ytdl
$ git remote add my_origin https://github.com/brucewangno1/ytdl
Once you are done with changes, commit them and push using below:
$ git push my_origin my_branch
When working with golang forks of a repo, try and work in the import path of the original repo, and update the tooling to use your forked repo.
What I mean is, if you have forked the project github.com/rylio/ytdl/ to your own github account github.com/brucewangno1/ytdl
Then you might have a gopath such as:
$GOPATH/src/github.com
├── rylio
│   └── ytdl
└── brucewangno1
└── ytdl
You should make changes in the directory $GOPATH/src/github.com/rylio/ytdl.
To add the changes to your forked repo, you can set another origin in git, inside your local clone of rylio/ytdl
git remote add fork git#github.brucewangno1/tydl.git
If you do not plan on merging changes back into the upstream repo, you can use tools such as dep to ensure that you pull your own fork of that project instead of the upstream one. Something like:
[[constraint]]
name = "github.com/c/d
source = "https://github.com/myusername/d.git"
This answer assumes that you forked repository
https://github.com/rylio/ytdl/ to https://github.com/brucewangno1/ytdl
You need to create directory named rylio in your $GOPATH and clone your fork into that directory.
mkdir $GOPATH/src/github.com/rylio
cd $GOPATH/src/github.com/rylio
git clone https://github.com/brucewangno1/ytdl
Now, you will not face any issues related to the imports.

GIT Fetching Multiple Repository's

I have a user github.com/userName that has 50+ Repositories that I would like to clone into a single dir on my Windows PC. What would be the best way to do this?
One way would be to create one more repo in which you declare your 50+ repos as submodules.
That way, you would be able to initialize/clone your 50 repos with a
git clone --recursive your_main_parent_repo
(See "How to git clone including submodules?")
Don't forget to commit and push your main_repo when you have committed and push any of your submodules though.

Resources