Add more robust work directory parsing #511
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 towardsStaying out of the way and letting Git do what it’s good at
by relying less on the manual setting of thecore.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:
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.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.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 thecore.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 thecore.worktree
value written by git would be../../../.secrets
. Given those examples we could combine the$YADM_REPO
value with thecore.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 theyadm 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.