Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: change master branch to main branch #50

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

Conversation

jackblk
Copy link

@jackblk jackblk commented May 29, 2021

@codecov-commenter
Copy link

codecov-commenter commented May 29, 2021

Codecov Report

Merging #50 (6d7c630) into master (877f923) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #50   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          183       183           
=========================================
  Hits           183       183           
Impacted Files Coverage Δ
tldr/cli.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f8065a...6d7c630. Read the comment docs.

@lord63 lord63 changed the base branch from master to dev July 17, 2021 02:56
@lord63
Copy link
Owner

lord63 commented Jul 17, 2021

Is it compatible if someone download the repo before master renamed to main? Because main branch may not exist and you can't checkout to it.

@lord63
Copy link
Owner

lord63 commented Jul 17, 2021

How about this:

	main_branch = "master"
	if subprocess.call('git rev-parse --verify main'.split()) == 0: # check if main branch exist
        main_branch = "main"
    local = subprocess.check_output('git rev-parse {0}'.format(main_branch).split()).strip()
    remote = subprocess.check_output(
        'git ls-remote https://github.com/tldr-pages/tldr/ HEAD'.split()
    ).split()[0]
    if local != remote:
        click.echo("Updating...")
        subprocess.check_call('git checkout {0}'.format(main_branch).split())

@jackblk
Copy link
Author

jackblk commented Jul 17, 2021

Is it compatible if someone download the repo before master renamed to main? Because main branch may not exist and you can't checkout to it.

I missed this case, thanks for mentioning it.

About git rev-parse --verify main, the argument --verify does not seem to verify if the branch is there or not.

--verify
Verify that exactly one parameter is provided, and that it can be turned into a raw 20-byte SHA-1 that can
be used to access the object database. If so, emit it to the standard output; otherwise, error out.

Also, in your example, if main does not exist then it will still use master, but this branch will be deleted in the future.

How about this?

def update():
    """Update to the latest pages."""
    repo_directory = get_config()["repo_directory"]
    os.chdir(repo_directory)
    click.echo("Check for updates...")

    try:
        local = subprocess.check_output("git rev-parse main".split()).strip()
    except subprocess.CalledProcessError:
        subprocess.check_call("git fetch -p".split())
        subprocess.check_call("git checkout main".split())
        local = subprocess.check_output("git rev-parse main".split()).strip()

    remote = subprocess.check_output(
        "git ls-remote https://github.com/tldr-pages/tldr/ HEAD".split()
    ).split()[0]
    if local != remote:
        click.echo("Updating...")
        subprocess.check_call("git checkout main".split())
        subprocess.check_call("git pull --rebase".split())
        build_index()
        click.echo("Update to the latest and rebuild the index.")
    else:
        click.echo("No need for updates.")

@kbdharun
Copy link

kbdharun commented Apr 9, 2023

Hi, any updates on this PR?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants