git-extras icon indicating copy to clipboard operation
git-extras copied to clipboard

git sync exclude folders from clean

Open JaKXz opened this issue 7 years ago • 11 comments

Hi, I've taken a look at the git sync command and was wondering if it would be possible to prevent some folders from being cleaned out.

node_modules or .idea/ are good examples of important folders that I would need to keep locally. A simple first step might be to have an extra read that asks for a full clean or just clean without the -d.

I would make a PR, but I want to gauge interest in this, and I apologize if I'm duplicating but I didn't find any similar issues in my search.

JaKXz avatar Jun 19 '17 21:06 JaKXz

@JaKXz This new feature looks reasonable. Looking forward for your PR!

spacewander avatar Jun 20 '17 08:06 spacewander

I'd recommend not running git clean at the end of git sync, it seems unnecessarily cruel.

I think usually people just want to do a simple git reset --hard upstream/[branch] on their local branch, and there's no need to git clean.

on the other hand, how would you approach this? @JaKXz I imagine you'll have to put your favorite ignored directories inside some sort of .gitsyncignore config, or specify them in the git sync arguments, which looks tiring.

what's your take on this? @spacewander

timfeirg avatar Jun 28 '18 06:06 timfeirg

Or I can make a new command that does the same thing as git sync, but without the git clean part, but that'd be quite confusing.

timfeirg avatar Jun 28 '18 07:06 timfeirg

@timfeirg I would probably write a safe-sync command that didn't have the -d option on git clean.

JaKXz avatar Jun 28 '18 18:06 JaKXz

@timfeirg @JaKXz We could assume the "ignore but important" patterns are limited, so specifying them in arguments like git clean -e 'xxx' -e 'yyy' is still acceptable.

BTW, I don't think add a new command for the minor change is a good idea, since the new command is almost the same with the old one. There is not namespace for git-* command and there is not standard way to share code betweem mutiple shell scripts.

spacewander avatar Jun 29 '18 02:06 spacewander

How about not doing git clean at all? I really don't see any reason for that. IMHO git sync should do the sync part, if people wanted to clean, we can add extra flags for that, or just expect user manually run git clean afterwards.

I really believe git clean is not preferred in most cases.

I'm good with adding -e 'vendor' -e 'node_modules', but this hurts software transparency, as this require users to understand that there's this little thing going on with git sync command, and if they don't, this would easily cause confusion.

But I'm happy with whatever solutions you prefer, @spacewander, and I'm happy to raise a PR for this.

timfeirg avatar Jun 29 '18 07:06 timfeirg

@timfeirg Doing git clean is good for the people who want to sync the repo up to date and don't want to be bitten by compiled files or caches unexpectedly.


as this require users to understand that there's this little thing going on with git sync command, and if they don't, this would easily cause confusion.

I think this behavior is documented: https://github.com/tj/git-extras/blob/master/man/git-sync.md#description

All changes and untracked files and directories will be removed.

It is reasonable to require the user to read the document before running the command. The document of git sync is short, so please don't say TL; DR.


Anyway, if you insist adding a new argument to skip the git clean, it is OK.

spacewander avatar Jun 29 '18 08:06 spacewander

I mean if we hard-code -e vendor -e node_modules parameters into the underlying git clean command, we'll be making assumptions that everybody thinks these folders should be preserved when doing git sync, which can cause trouble for those who don't agree with this, and also fail to catch up with the development of git-extras.

I'll work on this extra flag and see if I can manage to create a PR.

timfeirg avatar Jun 29 '18 10:06 timfeirg

OK, it looks like that I have not expressed my idea clearly. To say "specifying them in arguments like git clean -e 'xxx' -e 'yyy' ", I just gave out an example that we could write something like git sync --clean-exclude 'xxx', not hard coded with git clean -e 'xxx' -e 'yyy'.

spacewander avatar Jun 29 '18 12:06 spacewander

I would be lovely it the clean was without -x then command would be perfect :)

ghost avatar Aug 27 '18 11:08 ghost

@lpiotrowski-espeo You could add a new option for it. Pull request is welcome!

spacewander avatar Aug 27 '18 12:08 spacewander