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

feat: update clones if they're present #61

Merged
merged 3 commits into from
Sep 11, 2023
Merged

feat: update clones if they're present #61

merged 3 commits into from
Sep 11, 2023

Conversation

mortenpi
Copy link
Member

So if you are cloning the remotes to a local directory, it updates the local remotes. Not a 100% sure about this, but it would be good to have something like this.

It does slow things down a bit (not as bad as full clones, but still). So maybe we want to guard this with an environment variable or something?

@mortenpi mortenpi requested a review from pfitzseb August 25, 2023 02:00
elseif isempty(current_branch)
@error "current_branch was empty"
end
run(`$(git()) -C $(doc.upstream) reset --hard origin/$(doc.branch)`)
Copy link
Member Author

Choose a reason for hiding this comment

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

I am also not super comfortable with the reset --hard here. Especially if doc.upstream is pointing into a subdirectory of a real directory. Actually, instead of -C, should probably use --git-dir..

Copy link
Member

Choose a reason for hiding this comment

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

Is there ever any harm in hard-resetting a remote branch?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think if everything is normal, then it doesn't do anything wrong. But the cases I'm concerned about:

  1. Something has gone horribly wrong, and doc.upstream is not actually a separate Git repo anymore, and then this command nukes changes on your main repository.
  2. The user has actually gone into the cloned directories and modified stuff, and then we nuke their updates.

So I am wondering if something like a git merge --ff-only would be the better option here. I didn't want to do a simple git pull, since that, I believe, would fetch all branches.

Copy link
Member

Choose a reason for hiding this comment

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

What I meant is that reset --hard origin/mybranch can't ever nuke any local changes, because those are in mybranch instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I might be mistaken, but I believe reset --hard will change the commit your current branch points to origina/mybranch (any commit not on other branches/repos will become lost-ish), and it will also nuke all uncommitted working tree changes.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, doh! Yeah, I just misread the command here :P

Ok, so how about we just checkout remote/mybranch for the build?

@mortenpi
Copy link
Member Author

mortenpi commented Sep 11, 2023

I updated this, making it git checkout --detach origin/$branch when it updates the branch, and also added a check to see if the local directory has any changes. And I am also passing -C and --git-dir to all the git commands, so I think they should all run only when the clone is a valid, functioning Git clone, and not accidentally run the commands on some parent directory.

Unrelatedly, I also added --no-tags to the original clone command. It seems like --single-branch does not actually imply that.

@mortenpi mortenpi merged commit 20093b5 into main Sep 11, 2023
@delete-merged-branch delete-merged-branch bot deleted the mp/update-clones branch September 11, 2023 10:14
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.

2 participants