Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Rulrn
Copy link
Contributor

@Rulrn Rulrn commented Sep 18, 2025

Resolves #260 & #271 + add cloning by branch

Create the group when using gita clone <repo> -g <group_name>.

Also, I have added the argument --path for the group path to the p_clone parser, but I don't understand what this group_path is used for. I have not found anything in the README, maybe adding some information on it could be useful ?

On cloning by branch

I have tried to implement it, but it may need some discussion on the implementation.

  1. I have added the current branch of each repo when doing a gita freeze
  2. When using gita clone -f <freeze_file> it does one of the following :
    2a. If the option --no-branch is used, it does not try to clone by branch
    2b. If the git version is prior to 1.7.10 and the option --force-branch is not used, it does not try to clone by branch, as the git option --single-branch is not yet available, and cloning by branch wil in fact clone every branch and may result in unwanted data fetching (see https://stackoverflow.com/a/1911126)
    2c. If none of the above happens, it will clone by branch using the branch name in the freeze_file generated by gita freeze

@nosarthur
Copy link
Owner

thanks @Rulrn

the group path is used to automatically determine the current context (gita context)

when context is set as auto, the group can be deduced from current directory and the paths of all group paths:

  • cwd should be under the group path
  • the group with closest group path to cwd is the current group

gita/__main__.py Outdated
Comment on lines 92 to 94
gpath = ""
if "gpath" in args:
gpath = args.gpath
Copy link
Owner

Choose a reason for hiding this comment

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

gpath is not on p_add, thus it doesn't exist

    p_add.add_argument("--group-path", dest="gpath", type=_path_name)

Copy link
Owner

Choose a reason for hiding this comment

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

it seems this check should be on group_path, from line 237

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved in 0f0d82b

Is this the kind of check you expected ?

gita/__main__.py Outdated
# TODO: add another field to distinguish regular repo or worktree or submodule
print(f"{url},{name},{path},")
branch = info.get_repo_branch(prop, info.Truncate())
print(f"{url},{name},{path},,,{branch}")
Copy link
Owner

Choose a reason for hiding this comment

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

why ,,,?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because under io.py the function that reads the freeze results expects the following values :

["url", "name", "path", "type", "flags", "branch"]

If I omit those commas, the branch value ends up under the wrong field (type or flags)

I don't know what should be set for type and flags, maybe it is related to #271

Copy link
Owner

Choose a reason for hiding this comment

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

we can leave them for the future

ideally, they should go into the freeze data too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, gita clone from a file does not add the repo to gita if there are no groups. If we want flags/type to be in freeze, then we should consider adding the repo to gita when cloning even if the repo was not in any groups, but it changes the current behavior.

I feel that it is an expected behavior, I expected gita to automatically add the repo to it's "database" when cloning with it, otherwise I would simply use git directly.

Should we make gita clone add the repo to gita the default ?

Copy link
Owner

Choose a reason for hiding this comment

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

I agree, the repos should be added even if they are not in any groups

please feel free to leave that out of this PR since you have done quite a lot of work

Copy link
Contributor Author

@Rulrn Rulrn Sep 20, 2025

Choose a reason for hiding this comment

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

Implemented in 76174e0

Repo are now automatically added to the config file, even when not part of a group.

I also added a check when cloning repo to avoid adding duplicates, I had to add the file_only option to get_repos to get repos in config even if the repository did not exist.

If we use gita clone -f <freeze_file> with multiple freeze_file, it merges repo in the same groups.

The information of type and flags are also added to the config, I omitted the branch one because I don't know if it is relevant to add it to the config for now. Maybe we can solve #285, but I think it might be trickier than just having a branch in the config file, thus I kept it blank for now.

Tests are failing for now, I wait your approval on current state before updating them.

Copy link
Owner

Choose a reason for hiding this comment

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

thanks very much!

branch should be safe to ignore, their life span is variable and it may not exist at the gita clone time. it's easy to switch to anyways

one minor point: duplicates are handled in a subtle way before: it doesn't hurt to have 2 duplicate lines in the repos.csv, when any repo gets updates, the whole repo dictionary is saved to disk, then we have unique repos in the file

@Rulrn Rulrn marked this pull request as draft September 19, 2025 08:11
@Rulrn Rulrn marked this pull request as ready for review September 19, 2025 15:28
gita/__main__.py Outdated
path = Path.cwd()
path = args.directory or Path.cwd()

current_repos_path = [r["path"] for r in utils.get_repos(file_only=True).values()]
Copy link
Owner

Choose a reason for hiding this comment

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

set instead of list?

also why do we need file_only here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed the list for a set.

The file_only is used to avoid adding duplicate in gita if the repo is already in the configuration. Before I added this argument, the get_repos function was always checking if the path exists before returning the repos (with the is_git function being called). But if for some reason, we added a repository to gita, removed it and cloned it back, gita do not find the path and therefore add it a second time (which is not so important as you said in a previous comment, gita removing duplicates automatically when updating repos).

The file_only just skip the check of path existing for the repository in the configuration.

I agree that this scenario it is a bit far-fetched, maybe it was not necessary to implement such a thing, but I still think it is better to have a clean configuration straight away if possible.

And now that I think about it, what is the reason behind checking if the repo's path exists in the get_repos function with git_url ?

Copy link
Owner

@nosarthur nosarthur Sep 24, 2025

Choose a reason for hiding this comment

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

And now that I think about it, what is the reason behind checking if the repo's path exists in the get_repos function with git_url

It's just a sanity check. repos.csv is a snapshot and its information could be invalid when gita command is triggered

Sorry I am still not sure why file_only is needed

But if for some reason, we added a repository to gita, removed it and cloned it back, gita do not find the path and therefore add it a second time

If a repo is removed from gita, then gets added back from gita clone -f xxx, why is it added twice? It seems there is only 1 line corresponding to this repo in repos.csv: the original line is removed with the gita rm command

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I should have precised "removed without using gita", like "rm -r xxx"

Copy link
Owner

Choose a reason for hiding this comment

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

i see, thanks

i would suggest a name change: skip_validation instead of file_only so that the intention is more clear

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, changed in 854d54d

@nosarthur
Copy link
Owner

would you be able to fix the unit tests? if not, i can take care of that later

https://github.com/nosarthur/gita/actions/runs/18063927896/job/51449594122?pr=288

@Rulrn
Copy link
Contributor Author

Rulrn commented Sep 29, 2025

Tests fixed in 61c5f4c

@Rulrn Rulrn closed this Sep 29, 2025
@Rulrn Rulrn reopened this Sep 29, 2025
@nosarthur nosarthur merged commit f48e7d4 into nosarthur:master Sep 29, 2025
9 of 18 checks passed
@Rulrn Rulrn deleted the clone_create_group branch October 18, 2025 12:39
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.

Gita clone -g should create group if not exists.

2 participants