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

2165 push to private submodule #192

Merged
merged 4 commits into from
Feb 27, 2024
Merged

2165 push to private submodule #192

merged 4 commits into from
Feb 27, 2024

Conversation

TylerZeroMaster
Copy link
Contributor

@TylerZeroMaster TylerZeroMaster commented Feb 19, 2024

fixes openstax/ce#2165

Changes are backward compatible

GIVEN

  • A book repository that does not have a private submodule
  • This version of POET

WHEN

  • POET is activated (by opening its interface or opening a cnxml document)

THEN

  • It works as usual (private submodule is not required)
  • Can push changes
  • No errors on startup

Push to private submodule and book repo

NOTE: It may be best to use the private-submodule branch of osbooks-playground which has a private submodule preconfigured and ready to go.

GIVEN

  • A book repository contains a properly configured private submodule is opened in gitpod
  • This version of POET

WHEN (order is important)

  1. You have read and write access to the private submodule
  2. POET is activated (by opening its interface or opening a cnxml document)
  3. You make a change to a file in the private submodule

THEN

  • The private submodule is checked out to the correct branch (defined in the .gitmodules file)

    • You can check this by running git -C private branch --show-current in the terminal
Screenshot 2024-02-27 at 11 30 48 AM
  • You can push changes to public and private submodule

Making private submodule changes before POET is activted

NOTE: It may be best to use the private-submodule branch of osbooks-playground which has a private submodule preconfigured and ready to go.

GIVEN

  • A book repository contains a properly configured private submodule is opened in gitpod
  • This version of POET

WHEN (order is important)

  1. You have read and write access to the private submodule
  2. You make a change to a file in the private submodule
  3. POET is activated (by opening its interface or opening a cnxml document)

THEN

  • The private submodule is checked out to the correct branch (defined in the .gitmodules file)
    • You can check this by running git -C private branch --show-current in the terminal or looking in the git SCM panel
Screenshot 2024-02-27 at 11 30 48 AM
  • You can push changes to public and private submodule

Error message when submodule is not initialized

BACKGROUND: These steps are supposed to create an uninitialized submodule in gitpod. Normally when you open gitpod, it does something like git clone --recursive which clones the repository and all submodules. When you start on a branch that does not contain submodules and then switch to one that does, however, the submodules are not cloned/initialized.

GIVEN

WHEN (order is important)

  1. You switch to the private-submodule branch of osbooks-playground
  2. POET is activated (by opening its interface or opening a cnxml document)

THEN

  • An error message appears warning you that your changes will not be pushed because the private submodule is not initialized
  • Trying to push causes the error message to appear again
  • If there are changes in the book repository, these are still pushed

Summary of Changes

Unfortunately, the git extension does not surface the branch property of .gitmodules. It parses the file in nearly the exact same way, but branch is omitted for some reason.

The only alternative was to try to guess the edition of the book and construct the branch name using the guessed edition and workspace root directory name. Parsing the configuration seemed like the better of the two options since it makes fewer assumptions and is less reliant on repository file structure.

Making a PR to vscode to include the branch might be a good thing to do in the long-term.

@TylerZeroMaster TylerZeroMaster requested a review from a team February 19, 2024 16:12
@TylerZeroMaster TylerZeroMaster self-assigned this Feb 19, 2024
Copy link
Member

@philschatz philschatz left a comment

Choose a reason for hiding this comment

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

Nice!

@@ -35,6 +36,15 @@ export function bundleGenerateReadme(): (request: BundleGenerateReadme) => Promi
}
}

export function bundleGetSubmoduleConfig(): (request: BundleGetSubmoduleConfigParams) => Promise<Record<string, string> | null> {
Copy link
Member

Choose a reason for hiding this comment

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

Wow, nice. If the git extension included the branch information could all this LanguageServer code disappear?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, 💯

const propertyPattern = /^\s*(\w+)\s*=\s*"?([^"]+)"?$/
const sectionPattern = /^\s*\[\s*([^\]]+?)\s*("[^"]+")*\]\s*$/

export function parseGitConfig(config: string): Record<string, string> {
Copy link
Member

Choose a reason for hiding this comment

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

😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@philschatz I share your frustration. The only other option I could surmise was to try to reconstruct the branch name based on the repository directory name and the currently checked out branch. That approach seemed more likely to cause unexpected issues later on. Moreover, I thought it was be better to use an existing git standard than to try to develop a proprietary one.

client: LanguageClient,
privateSubmodule: Repository
): Promise<void> => {
// TODO: What if submodule needs to be initialized? (not a problem in gitpod)
Copy link
Member

@philschatz philschatz Feb 21, 2024

Choose a reason for hiding this comment

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

I'm probably just confused but isn't this TO-DONE by the code below?

Copy link
Contributor Author

@TylerZeroMaster TylerZeroMaster Feb 23, 2024

Choose a reason for hiding this comment

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

No, initially when you clone a repository that contains submodules, the submodules are not initialized unless you add the --recursive option to the clone command. Submodules do not contain a .git directory until you run something like git submodule update --init. Since they do not contain a .git directory, they are not considered git repositories and git commands like fetch fail.

Gitpod automatically initializes submodules when you open a workspace (recursive clone). This TODO is specifically for making it work locally. I was exploring ways to make it work. One possible way to get it to work right now would be to use the git.clone command. Since it works in Gitpod and you can workaround the issue locally with by initializing submodules manually, it seemed like something that could wait until later.

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 tried making this more clear by adding an error that is thrown if the private submodule is unexpectedly missing. This would happen when the submodule is defined in the .gitmodules and:

  1. The directory is missing
  2. The directory is empty
  3. Any other situation where the git extension does not think it is a valid git repository

Show a more clear error when the submodule is unexpectedly missing
@TylerZeroMaster TylerZeroMaster merged commit 7543eb4 into main Feb 27, 2024
3 checks passed
@TylerZeroMaster TylerZeroMaster deleted the 2165-push-submodules branch February 27, 2024 17:35
@omehes
Copy link
Contributor

omehes commented Jul 22, 2024

verified in poet ext 7.0.0

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.

3 participants