-
-
Notifications
You must be signed in to change notification settings - Fork 244
Auto-detect remote's default branch in nb remote set
#418
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
Open
fs0414
wants to merge
4
commits into
xwmx:master
Choose a base branch
from
fs0414:feature/git-branch-remote-sync
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Required after auto-detecting remote's default branch.
Author
|
All bats tests in the local environment have passed successfully % bats test/init.bats test/notebooks-add.bats test/notebooks-init.bats test/remote-remove.bats
test/remote-set.bats test/remote.bats
init.bats
✓ _GIT_ENABLED=0 'init' exits with status 0 and creates notebook directory without .git.
✓ 'init <remote-url> <branch>' creates a clone in '$NB_NOTEBOOK_PATH' / '$NB_DIR/home'.
✓ 'init <remote-url>' creates a clone in '$NB_NOTEBOOK_PATH' / '$NB_DIR/home'.
✓ 'init --author' displays config prompt and sets email and name.
✓ 'init --email <email> --name <name>' sets the local email and name.
✓ 'init --email <email>' sets the local email.
✓ 'init --name <name>' sets the local name.
✓ 'init' exits with status 0.
✓ 'init' exits with status 1 when '$NB_DIR' exists as a file.
✓ 'init' exits with status 1 a prints error output when '$NB_NOTEBOOK_PATH' / '$NB_DIR/home' exists.
✓ 'init' creates '$NB_DIR' and '$NB_NOTEBOOK_PATH' / '$NB_DIR/home' directories.
✓ 'init' creates a git directory in '$NB_NOTEBOOK_PATH' / '$NB_DIR/home'.
✓ 'init' creates an .index '$NB_NOTEBOOK_PATH' / '$NB_DIR/home'.
✓ 'init' exits with status 0 when '$NBRC_PATH' exists.
✓ 'init' creates a .nbrc file at '$NBRC_PATH'.
✓ 'init' creates git commit.
✓ 'help init' exits with status 0.
✓ 'help init' prints help information.
notebooks-add.bats
✓ 'notebooks add' with no <name>, <remote-url>, or <branch> exits with 1 and prints help.
✓ 'notebooks add <remote-url> --all' with no existing notebooks matching branch names exits with 0 and adds notebooks for all branches.
✓ 'notebooks add <remote-url> <branch-1> <nonexistent-branch-2>' with existing <branch-1> notebook exits with 0 and adds notebook named <branch-1>.
✓ 'notebooks add <remote-url> <branch-1> <branch-2>' with no existing notebooks with those names exits with 0 and adds notebook named <branch-1> and <branch-2>.
✓ 'notebooks add <remote-url> <branch>' with reserved notebook name as branch name exits with a and prints message.
✓ 'notebooks add <remote-url> <branch>' with no existing notebook with that name exits with 0 and adds a notebook named <branch>.
✓ 'notebooks add <name> <remote-url> <branch>' exits with 0 and adds a notebook.
✓ 'notebooks add <name> <remote-url>' exits with 0 and adds a notebook.
✓ 'notebooks add <remote-url>' with multiple remote branches prompts for branch with 'All' response and notebook names with default response, and creates notebooks from branches.
✓ 'notebooks add <remote-url>' with multiple remote branches prompts for branch with 'All' response and notebook names with alpha response, and creates notebooks from branches.
✓ 'notebooks add <remote-url>' with multiple remote branches prompts for branch with numerical response and notebook name with alpha response, and creates notebook from branch.
✓ 'notebooks add <remote-url>' with multiple remote branches prompts for branch with alpha / branch name response and notebook name with <enter> response, and creates notebook from branch.
✓ 'notebooks add <remote-url>' with multiple remote branches prompts for branch with numeric response and notebook name with <enter> response, and creates notebook from branch.
✓ 'notebooks add <remote-url>' with one remote branch with uncommon default branch name uses repository name as notebook name.
✓ 'notebooks add <remote-url>' with one remote branch with common default branch name uses repository name as notebook name.
✓ 'notebooks add --author' displays config prompt and sets email and name.
✓ 'notebooks add --email <email> --name <name>' sets the local email and name.
✓ 'notebooks add --email <email>' sets the local email.
✓ 'notebooks add --name <name>' sets the local name.
✓ 'notebooks add <reserved>' exits with 1 and prints error message.
✓ 'notebooks add <existing>' exits with 1 and prints error message.
✓ 'notebooks add <name>' exits with 0 and adds a notebook.
✓ 'notebooks add <name>' creates git commit.
✓ 'notebooks a <name>' exits with 0 and adds a notebook.
✓ 'notebooks create <name>' exits with 0 and adds a notebook.
✓ 'notebooks new <name>' exits with 0 and adds a notebook.
notebooks-init.bats
✓ 'noteboos init' with uninitialized configuration initializes configuration
✓ 'notebooks init <relative path>' with nested git repositories and positive prompt response prints warning and succeeds.
✓ 'notebooks init <path> <remote-url> <branch>' exits with 0 and adds a notebook.
✓ 'notebooks init <path> <remote-url>' exits with 0 and adds a notebook.
✓ 'notebooks init --author' displays config prompt and sets email and name.
✓ 'notebooks init --email <email> --name <name>' sets the local email and name.
✓ 'notebooks init --email <email>' sets the local email.
✓ 'notebooks init --name <name>' sets the local name.
✓ 'notebooks init' with no arguments and positive prompt response initializes the current directory.
✓ 'notebooks init' with no arguments and negative prompt response exits without initialization.
✓ 'notebooks init' in existing notebook exits with 1 and prints error message.
✓ 'notebooks init' in existing git repo exits with 1 and prints error message.
✓ 'notebooks init <relative path>' with no arguments succeeds.
✓ 'notebooks init <relative path>' with existing directory and positive prompt response succeeds.
✓ 'notebooks init <relative path>' with existing directory and negative prompt response exits without initialization.
✓ 'notebooks init <relative path>' in existing notebook exits with 1.
✓ 'notebooks init <relative path>' in existing git repo exits with 1.
✓ 'notebooks init <absolute path>' with no arguments succeeds.
✓ 'notebooks init <absolute path>' with existing directory and positive prompt response succeeds.
✓ 'notebooks init <absolute path>' with existing directory and negative prompt response exits without initialization.
✓ 'notebooks init <absolute path>' in existing notebook exits with 1.
✓ 'notebooks init <absolute path>' in existing git repo exits with 1.
✓ 'notebooks init <top-level-directory>' exits with 1 and prints message.
remote-remove.bats
✓ 'unset remote' with no existing remote returns 1 and prints message.
✓ 'remote remove --skip-confirmation' with existing remote removes remote without resetting default branch and prints message.
✓ 'remote remove --skip-confirmation' with existing remote removes remote, resets default branch, and prints message.
✓ 'remote remove' with no existing remote returns 1 and prints message.
✓ 'remote remove' with existing remote removes remote without resetting default branch and prints message.
✓ 'remote remove' with existing remote removes remote, resets default branch, and prints message.
✓ 'remote unset' with existing remote removes remote, resets default branch, and prints message.
✓ 'remote remove' with existing remote as orphan removes remote, removes branch and prints message.
✓ 'remote remove' with existing remote as orphan removes remote without removing remote branch and prints message.
76 tests, 0 failures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR fixes the issue where
nb remote setdefaults tomasterbranch even when the remote repository's default branch ismain.Fixes #61
Problem
When running
nb remote set <url>without specifying a branch name, the command uses the local branch name (typicallymasterfromgit init) instead of detecting the remote repository's default branch.Before:
Solution
Detect the remote's default branch using
git ls-remote --symrefbefore falling back to the local branch name.After:
Changes
Main fix (
nbline 24485-24493)Added remote default branch detection in
_remote()function'ssetsubcommand:Test updates
Updated test files to explicitly specify branch names in
remote addandremote setcommands. This is required because the fix now auto-detects the remote's default branch, which may differ from the local branch name used in test setups.Modified test files:
test/init.batstest/notebooks-add.batstest/notebooks-init.batstest/remote-remove.batstest/remote-set.batstest/remote.batsNotes