Skip to content
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

Add more robust work directory parsing #511

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

SymbionicNigel
Copy link

@SymbionicNigel SymbionicNigel commented Dec 18, 2024

What does this PR do?

This PR removed the requirement for the user to provide the -w and the associated file path when dealing with git submodules. As described in the issue I had created (#501) where git operations were not working correctly even though the --yadm-data, --yadm-dir, --yadm-repo arguments were being supplied to yadm, I see this as a way in which yadm can take a step towards Staying out of the way and letting Git do what it’s good at by relying less on the manual setting of the core.worktree git config value and requiring fewer configuration values past the three arguments I mentioned above.

There are 3 situations which this new function handles:

  1. When core.worktree is not filled: This means that the user is working with or initializing a top level git repository in yadm which has not been initialized through yadm before. This is the first branch of the if statement, where I am either returning $YADM_REPO defaulting to $HOME if $YADM_REPO is not valid.
  2. When core.worktree is an absolute path: This means that we are dealing with a top level git repository or a git submodule which has been initialized through yadm. This branch will handle the situations dealing with all correctly configured yadm repositories.
  3. When core.worktree is a relative path: This means that we are dealing with a submodule which has not been initialized through yadm. Git, when dealing with submodules naturally, will populate the core.worktree config with a relative path that points to the submodule it is managing in relation to the top level repositories location in which it stores the submodules git config.

An example for situation 3 would be if I had a top level repository located at ~/test with a submodule in a directory at ~/test/.secrets. If only configured through git, the $YADM_REPO value that I would supply would be ~/test/.git/modules/.secrets and the core.worktree value written by git would be ../../../.secrets. Given those examples we could combine the $YADM_REPO value with the core.worktree output to get an absolute path to the actual location of the directory we are working with.

What issues does this PR fix or reference?

#501

Previous Behavior

Previously yadm would require the user to supply the -w <path to workdir> argument with the yadm init command when working with submodules, otherwise git commands would not function. This still works with that method of initialization.

New Behavior

The new behavior would allow for the user to just initialize the repo through git and not yadm. Either method would work now.

Have tests been written for this change?

No, but I can add them if requested.

Have these commits been signed with GnuPG?

Yes.


Please review yadm's Contributing Guide for best practices.

@SymbionicNigel SymbionicNigel changed the base branch from master to develop December 18, 2024 05:56
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.

1 participant