-
-
Notifications
You must be signed in to change notification settings - Fork 81
Create group if not exists when cloning repo #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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:
|
gita/__main__.py
Outdated
| gpath = "" | ||
| if "gpath" in args: | ||
| gpath = args.gpath |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why ,,,?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Save type and flasg attribute when using gita freeze
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()] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
|
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 |
|
Tests fixed in 61c5f4c |
Resolves #260 & #271 + add cloning by branch
Create the group when using
gita clone <repo> -g <group_name>.Also, I have added the argument
--pathfor the group path to thep_cloneparser, but I don't understand what thisgroup_pathis 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.
gita freezegita clone -f <freeze_file>it does one of the following :2a. If the option
--no-branchis used, it does not try to clone by branch2b. If the git version is prior to 1.7.10 and the option
--force-branchis not used, it does not try to clone by branch, as the git option--single-branchis 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