Access files from different git repository - gitlab

I want to separate out some files to a another git repository so that different projects can use it. These files contains some common functions that can be used by different projects in gitlab.
How can I access the newly created 'common' repository in my existing project?
Sample code:
file generate.py contents: *import common_xyz
def using_common_xyz: do something...*
I have now moved the file containing common_xyz to a different repository. I read that we can use "Include" keyword in .gitlab-ci.yml to access files in other repository. Or should I treat them as library? Can anyone suggest what is the best way?

Git submodules would be the way to go.
From git-scm.com:
Submodules allow you to keep a Git repository as a subdirectory of
another Git repository. This lets you clone another repository into
your project and keep your commits separate.
Here's a cool guide (theserverside.com) to get started using both GitHub and GitLab.
Here's another, on git-scm.com

Related

being in one GIT repository, is it possible to add/commit/push files to another GIT repository using nodejs

I have lot of files coming from S3 and I want to add/commit/push those files to one new GIT repository using nodejs. Being in one repository can we push files to another repository? if possible, please let me know how to do that.

Share one file across multiple git repo to be updated by multiple users

I am working on automating the markdown spell check for all the documents on my website which involves multiple git repo. I have a .spelling file that contains all the word to be excluded from the documents. I would like to keep it one file and updated across the entire website. I can get it to work for one repo. I looked into the npm package method. Is there a way to configure package.json to share this file to many repo? Or is there a better way to do it without npm? Thanks!
Make a separate spell-check repository with the .spelling file and script in it, then include it as a submodule in each of your docs repos. You can then reference it from each repository separately, and pull its latest updates into each one.
This could be cumbersome if you have a large number of docs repos, so another alternative is to centralize the spelling check script by making a separate repository for it and adding a configuration file to tell your script which Github repositories to spellcheck. This way, you can selectively apply the spell check process to any number of repositories in your organization.

Use JGit to rename the repository

I'm developing a tool that has 3 functions as follows:
Create a Git repository.
Delete a Git repository.
Rename a Git repository.
I must use JGit to implement this tool. But I did not find a way to rename of the repository by using JGit.
Does anyone know how to use JGit to rename the repository?
A Git repository does not have a name in itself, hence JGit does not provide an API for renaming.
Usually the last segment of the directly in which the repository is located is used to name it when necessary. For example a repository in /foo/bar/.git will be named bar.
In order to rename a repository, simply move its location by using the Java file API.

Create git history, blob and tree objects, in parallel

our company have decided to migrate our source code from clearcase to git, that's great :-)
I know that clearcase and git are completely different source code management systems.
But we developer, would have only one SCM that containing the complete history.
My colleague found the following tool, which importing our clearcase history into git: https://github.com/charleso/git-cc
Unfortunately our code has more than 46000 source code files and the history to import is more than 10 years.
I analyzed this tool and in my opinion there are two bottlenecks.
The first is the import of files from clearcase server. This is easy to solve by doing this in multiple threads.
The second is the workflow of git-cc itself.
Get history of master-branch via cleartool lshistory
Create changesets of files and group them to comit's
Get specified version of file(s) from cc server and copy to working directory
git add .
git commit
pick next group and start with 3. again
I think I could improve it by using low level git commands and using multiple threads.
Each commit-group queries its changes from server and creating a blob object within git database, so this could run for multiple groups in multiple threads.
Additional I have one thread which create the history in git from just now created blob objects.
My question is now, does this make sense to you or do you think I'm naive?
Have I forget any git locking mechanism?
Have you any other ideas?
Using multiple thread for importing commits in the same branch of a Git repo is risky (unless, as you put it, you create "blob object", that is patches that you can replay).
But using multiple thread for commits on different branches is possible: you create different repo, each one for a branch import, and then you can fetch those repos into one common repo and reattach them with git replace or grafts.
But remember: each Git repo is a component, so if your giant ClearCase Vob includes several components (group of files), it would be best to separate them in multiple Git repo rather than attempting to create a giant Git one.
I detail that in "ClearCase to Git migration".

Is it possible to remove nested directories "/runner_id/0/company_name" from a Gitlab CI build path?

I have an existing directory structure on a machine and want to configure Gitlab CI to clone/fetch repos to specific paths.
I've managed to change the builds_dir property in the config.toml file to start in the correct place, but Gitlab adds extra nested folders by default.
So I set:
builds_dir = "/Users/myUser/Development/projName"
and when Gitlab CI clones the repo, it adds
"/555555bb/0/orgName"
so I end up with:
"/Users/myUser/Development/projName/555555bb/0/orgName/projName"
Is there a way in the Gitlab config file to remove the extra sub-directories, or is my only option to move the files around after the clone/fetch is complete?
Because of how Gitlab runners work you need to copy the files to the appropriate locations.
Since runners can handle multiple projects, they need to differentiate them in some way and this is where /555555bb/0/orgName part comes in.
You can define in your project-specific runner config where those files need to be copied to (a simple copy command will suffice).
I solved it by creating a symbolic link between the repository used by the gitlab runner and the repository I am wishing to use for the deployment of the application.

Resources