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

Keep ".git" file in in --cleanDestinationDir #6261

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

Conversation

g-a-c
Copy link

@g-a-c g-a-c commented Aug 24, 2019

Ignore files specifically called ".git" in order to preserve submodule information for Git post-1.7.8 (which seems to be the point things changed from having an entire “.git” directory inside the submodule to having a “.git” file pointing to a gitdir outside of the submodule)

This should restore what I believe was the intended behaviour of #3202 and fix the issue for pojebunny in #4546

See #3202 and #4546

Ignore files specifically called ".git" in order to preserve submodule information for Git post-1.7.8 (which seems to be the point things changed from having an entire “.git” directory inside the submodule to having a “.git” _file_ pointing to a gitdir outside of the submodule)

This should reproduce what I believe is the intended behaviour from gohugoio#3202 and fix the issue for pojebunny in gohugoio#4546

See gohugoio#3202 and gohugoio#4546
@stale
Copy link

stale bot commented Dec 22, 2019

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Dec 22, 2019
@g-a-c
Copy link
Author

g-a-c commented Dec 31, 2019

If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

I don't currently use Hugo but I believe this PR still adds value for other users attempting to use submodules with recent versions of Git.

@stale stale bot removed the Stale label Dec 31, 2019
@stale
Copy link

stale bot commented Apr 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Apr 29, 2020
@stale stale bot closed this May 30, 2020
@Jonathan-Ironman
Copy link

Same issue here. The .git file should be preserved imo

@g-a-c
Copy link
Author

g-a-c commented May 5, 2021

I don't remember any of the context around why I opened this. However...

edit - I see. This refers to a .git file, not a directory, which would not be covered by the existing behaviour so may still be a valid PR.

@Jonathan-Ironman
Copy link

Exactly, it leaves the dirs intact but clears .git, .gitignore, etc.
I'm having the public folder as a git submodule and it for instance also has a README.md file which would be nice to keep.
Custom regex filter settings would be ideal here I suppose, but ignoring dot-files is already a big help.

@bep bep added this to the v0.84 milestone May 5, 2021
@bep bep changed the title Ignore ".git" file in output directory Keep ".git" file in in --cleanDestinationDir May 5, 2021
@bep bep reopened this May 5, 2021
@bep
Copy link
Member

bep commented May 5, 2021

I didn't know .git could be a file -- we can check for that, but we're not making this more complicated than that.

@Jonathan-Ironman
Copy link

Jonathan-Ironman commented May 5, 2021

spf13/fsync#10
This seems related, might it already be possible?

All . files right? There's a bunch of them (i.e. .gitignore, .firebaserc)

@g-a-c
Copy link
Author

g-a-c commented May 5, 2021

I didn't know .git could be a file -- we can check for that, but we're not making this more complicated than that.

Honestly, I don't remember all the details of this. But I think it was related to me wanting to pull in a remote theme without committing it in its entirety to my Hugo repo.

That seemed (at the time at least) like a sensible thing to do because it meant updating the theme was just a change of reference, and I think the way I achieved that was by having a theme subdirectory or something similar in my output directory, which was a submodule reference (this somehow turned into a .git file inside the theme subdir, though I don't fully understand/remember why). So when the output directory was being cleared, I actually wanted that submodule reference to remain so that once the output step was finished I could pull the theme from its remote reference into my output directory and then rsync --delete the whole thing up to a webserver.

It was a very, very early exploration into rudimentary CI/CD for me at the time. It may no longer make sense, and I don't use Hugo anymore, which is why I just let the PR expire at the second time of asking instead of being an ass and trying to force a change through that I didn't need anymore.

@bep bep modified the milestones: v0.84, v0.85 Jun 18, 2021
@bep bep modified the milestones: v0.85, v0.86 Jul 5, 2021
@bep bep modified the milestones: v0.86, v0.87, v0.88 Jul 26, 2021
@bep bep removed this from the v0.88 milestone Sep 2, 2021
@bep bep added this to the v0.115.0 milestone Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@DominoPivot
Copy link
Contributor

DominoPivot commented Aug 24, 2023

This would still be pertinent, though the codebase has changed quite a bit since this PR was opened. The code now lives in /commands/hugobuilder.go. I could open my own PR if needed, though I don't have a Go environment ready and never contributed here.

		syncer.DeleteFilter = func(f os.FileInfo) bool {
-			return f.IsDir() && strings.HasPrefix(f.Name(), ".")
+			return strings.HasPrefix(f.Name(), ".")
		}

I ran into this issue when I found an old site of mine whose public folder contained a redundant clone of the same repository but with the gh-pages branch always checked out. This is precisely what a git worktree is for, I probably just didn't know at the time. I ran this command to replace the redundant clone with a worktree:

rm -rf public && git worktree add public gh-pages

This had the effect of replacing the public/.git folder with a single file. I knew --cleanDestinationDir left public/.git alone before so I was surprised when it got deleted now that it was a file instead of a folder. I believe this should be fixed for consistency, though I'm not sure if there are people who rely on the current behavior. Still, I found some workarounds for now:

  • git worktree repair public to recreate the .git file
  • git worktree lock public to avoid accidental pruning if Hugo deletes the .git file in the future
  • copy the .git file to the static folder, and make sure not to run git commands within that folder

@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 4, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep modified the milestones: v0.125.0, v0.126.0 Apr 23, 2024
@bep bep modified the milestones: v0.126.0, v0.127.0 May 15, 2024
@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants