git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] git submodule purge
@ 2015-03-16 13:44 Patrick Steinhardt
  2015-03-16 15:55 ` Junio C Hamano
  2015-03-16 20:03 ` Jonathan Nieder
  0 siblings, 2 replies; 11+ messages in thread
From: Patrick Steinhardt @ 2015-03-16 13:44 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 2252 bytes --]

Hi,

This proposal is just for discussion. If there is any interest I
will implement the feature and send some patches.


Currently it is hard to properly remove submodules. That is when
a submodule is deinitialized and removed from a repository the
directory '.git/modules/<SM_NAME>' will still be present and
there is no way to remove it despite manually calling `rm` on it.
I think there should be a command that is able to remove those
dangling repositories if the following conditions are met:

- the submodule should not be initialized

- the submodule should not have an entry in .gitmodules in the
  currently checked out revision

- the submodule should not contain any commits that are not
  upstream

- the submodule should not contain other submodules that do not
  meet those conditions

This would ensure that it is hard to loose any commits that may
be of interest. In the case that the user knows what he is doing
we may provide a '--force' switch to override those checks.

What is problematic, though, is when there are multiple branches
under active development where one branch contains a submodule
and another one does not. Given the checks listed above, though,
an accidentally removed submodule repository should not prove
problematic as it should be possible to easily re-clone it. It
might just be cumbersome if the user accidentally removes a
submodule and has to re-initialize it after switching branches.

Regarding behavior of the command I thought about something like
`git submodule purge (<SM_NAME>|<DIRECTORY>|-a)` where 'SM_NAME'
would remove the given submodule, 'DIRECTORY' would remove all
submodules under a certain directory and '-a' would remove all
submodules that are currently inactive. It might be useful to
provide a '--dry-run' switch that lists all submodules that would
be removed without actually removing them.

Some questions that arise here:

- should those actions be recursive? E.g. if a submodule contains
  submodules itself, should those be deleted (after the
  conditions are met), as well?

- should the user be asked for consent for every submodule that
  is about to be deleted or do we assume that he knows what he is
  doing?


Some feedback on this would be appreciated.

Regards
Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] git submodule purge
  2015-03-16 13:44 [RFC] git submodule purge Patrick Steinhardt
@ 2015-03-16 15:55 ` Junio C Hamano
  2015-03-17  8:18   ` Patrick Steinhardt
  2015-03-16 20:03 ` Jonathan Nieder
  1 sibling, 1 reply; 11+ messages in thread
From: Junio C Hamano @ 2015-03-16 15:55 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: git

Patrick Steinhardt <ps@pks.im> writes:

> I think there should be a command that is able to remove those
> dangling repositories if the following conditions are met:
>
> - the submodule should not be initialized
>
> - the submodule should not have an entry in .gitmodules in the
>   currently checked out revision
>
> - the submodule should not contain any commits that are not
>   upstream
>
> - the submodule should not contain other submodules that do not
>   meet those conditions

I do not have a strong opinion on whether it is a good idea to make
it possible to remove the .git/modules/*, but should it be a
separate subcommand, or should it be an option to the 'deinit'
subcommand?

Also, how would you apply the safety to a repository without
"upstream", i.e. the authoritative copy?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] git submodule purge
  2015-03-16 13:44 [RFC] git submodule purge Patrick Steinhardt
  2015-03-16 15:55 ` Junio C Hamano
@ 2015-03-16 20:03 ` Jonathan Nieder
  2015-03-17  7:56   ` Patrick Steinhardt
  1 sibling, 1 reply; 11+ messages in thread
From: Jonathan Nieder @ 2015-03-16 20:03 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: git, Jens Lehmann, Heiko Voigt

(+cc: Jens and Heiko, submodule experts)
Hi,

Patrick Steinhardt wrote:

> This proposal is just for discussion. If there is any interest I
> will implement the feature and send some patches.
>
> Currently it is hard to properly remove submodules. That is when
> a submodule is deinitialized and removed from a repository the
> directory '.git/modules/<SM_NAME>' will still be present and
> there is no way to remove it despite manually calling `rm` on it.
> I think there should be a command that is able to remove those
> dangling repositories if the following conditions are met:
>
> - the submodule should not be initialized
>
> - the submodule should not have an entry in .gitmodules in the
>   currently checked out revision
>
> - the submodule should not contain any commits that are not
>   upstream
>
> - the submodule should not contain other submodules that do not
>   meet those conditions
>
> This would ensure that it is hard to loose any commits that may
> be of interest. In the case that the user knows what he is doing
> we may provide a '--force' switch to override those checks.

Those conditions look simultaneously too strong and too weak. ;-)

In principle, it should be safe to remove .git/modules/<name> as
long as

 (1) it (and its submodules, sub-sub-modules, etc) doesn't have any
     un-pushed local commits.

 (2) it is not being referred to by a .git file in the work tree of
     the parent repository.

Condition (1) can be relaxed if the user knows what they are losing
and is okay with that.  Condition (2) can be avoided by removing
(de-initing) the copy of that submodule in the worktree at the same
time.

The functionality sounds like a useful thing to have, whether as an
option to 'git submodule deinit' or as a new subcommand.  In the long
term I would like it to be possible to do everything 'git submodule'
can do using normal git commands instead of that specialized
interface.  What command do you think this would eventually belong in?
(An option to "git gc", maybe?)

Thanks,
Jonathan

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] git submodule purge
  2015-03-16 20:03 ` Jonathan Nieder
@ 2015-03-17  7:56   ` Patrick Steinhardt
  2015-03-23 21:32     ` Jens Lehmann
  0 siblings, 1 reply; 11+ messages in thread
From: Patrick Steinhardt @ 2015-03-17  7:56 UTC (permalink / raw)
  To: Jonathan Nieder; +Cc: git, Jens Lehmann, Heiko Voigt

[-- Attachment #1: Type: text/plain, Size: 3111 bytes --]

On Mon, Mar 16, 2015 at 01:03:53PM -0700, Jonathan Nieder wrote:
> (+cc: Jens and Heiko, submodule experts)
> Hi,
> 
> Patrick Steinhardt wrote:
> 
> > This proposal is just for discussion. If there is any interest I
> > will implement the feature and send some patches.
> >
> > Currently it is hard to properly remove submodules. That is when
> > a submodule is deinitialized and removed from a repository the
> > directory '.git/modules/<SM_NAME>' will still be present and
> > there is no way to remove it despite manually calling `rm` on it.
> > I think there should be a command that is able to remove those
> > dangling repositories if the following conditions are met:
> >
> > - the submodule should not be initialized
> >
> > - the submodule should not have an entry in .gitmodules in the
> >   currently checked out revision
> >
> > - the submodule should not contain any commits that are not
> >   upstream
> >
> > - the submodule should not contain other submodules that do not
> >   meet those conditions
> >
> > This would ensure that it is hard to loose any commits that may
> > be of interest. In the case that the user knows what he is doing
> > we may provide a '--force' switch to override those checks.
> 
> Those conditions look simultaneously too strong and too weak. ;-)
> 
> In principle, it should be safe to remove .git/modules/<name> as
> long as
> 
>  (1) it (and its submodules, sub-sub-modules, etc) doesn't have any
>      un-pushed local commits.
> 
>  (2) it is not being referred to by a .git file in the work tree of
>      the parent repository.
> 
> Condition (1) can be relaxed if the user knows what they are losing
> and is okay with that.  Condition (2) can be avoided by removing
> (de-initing) the copy of that submodule in the worktree at the same
> time.
> 
> The functionality sounds like a useful thing to have, whether as an
> option to 'git submodule deinit' or as a new subcommand.  In the long
> term I would like it to be possible to do everything 'git submodule'
> can do using normal git commands instead of that specialized
> interface.  What command do you think this would eventually belong in?
> (An option to "git gc", maybe?)
> 
> Thanks,
> Jonathan

Thanks for your feedback.

Considering that purging the submodule is tightly coupled with
de-initializing it, it might make sense to provide this
functionality as part of `git submodule deinit`. Maybe something
like `git submodule deinit --purge` would work for the user.
Problem is if the user first removes the submodule and does not
first deinitialize it he is not able to purge the repository
afterwards as deinit will complain about the submodule not being
matched anymore. We could just make `deinit --purge` work with
removed submodules, but that does not feel very natural to me.

`git gc` feels saner in that regard, but I don't think it would
be easy to spot for users as this command is in general not used
very frequently by them. One could argue though that it does not
need to be discoverable.

Regards
Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] git submodule purge
  2015-03-16 15:55 ` Junio C Hamano
@ 2015-03-17  8:18   ` Patrick Steinhardt
  2015-03-17  8:25     ` Fredrik Gustafsson
  0 siblings, 1 reply; 11+ messages in thread
From: Patrick Steinhardt @ 2015-03-17  8:18 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1453 bytes --]

On Mon, Mar 16, 2015 at 08:55:03AM -0700, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > I think there should be a command that is able to remove those
> > dangling repositories if the following conditions are met:
> >
> > - the submodule should not be initialized
> >
> > - the submodule should not have an entry in .gitmodules in the
> >   currently checked out revision
> >
> > - the submodule should not contain any commits that are not
> >   upstream
> >
> > - the submodule should not contain other submodules that do not
> >   meet those conditions
> 
> I do not have a strong opinion on whether it is a good idea to make
> it possible to remove the .git/modules/*, but should it be a
> separate subcommand, or should it be an option to the 'deinit'
> subcommand?

See my response to Jonathan.

> Also, how would you apply the safety to a repository without
> "upstream", i.e. the authoritative copy?

Is it even possible to create a new submodule without any
upstream repository? At least `git submodule init` does not work
without a corresponding entry in .gitmodules which the user would
have needed to create himself manually. In this case one _could_
assume that the user knows what he is doing and expect him not to
call `submodule purge` (or whatever the command will be called)
on the authoritative copy. Other than that I've got no idea how
to assure safety.

Regards
Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] git submodule purge
  2015-03-17  8:18   ` Patrick Steinhardt
@ 2015-03-17  8:25     ` Fredrik Gustafsson
  0 siblings, 0 replies; 11+ messages in thread
From: Fredrik Gustafsson @ 2015-03-17  8:25 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: Junio C Hamano, git

On Tue, Mar 17, 2015 at 09:18:26AM +0100, Patrick Steinhardt wrote:
> Is it even possible to create a new submodule without any
> upstream repository? At least `git submodule init` does not work
> without a corresponding entry in .gitmodules which the user would
> have needed to create himself manually. In this case one _could_
> assume that the user knows what he is doing and expect him not to
> call `submodule purge` (or whatever the command will be called)
> on the authoritative copy. Other than that I've got no idea how
> to assure safety.

Look at git/t/t7400-submodule-basic.sh for example at the test starting
at line 84 on how to add a submodule without any upstream.

Git has already a disadvantage against other SCM (like mercurial)
because it's "too easy to loose data with git". Meaning that we purge
unrefered commits. (Yes this is up to debate if this is good or bad, but
here's not the place).

I think we should be very carefully with adding commands that
permanently removes data. They should be really well crafted so that
there's no way to do this by mistake.

-- 
Fredrik Gustafsson

phone: +46 733-608274
e-mail: iveqy@iveqy.com
website: http://www.iveqy.com

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] git submodule purge
  2015-03-17  7:56   ` Patrick Steinhardt
@ 2015-03-23 21:32     ` Jens Lehmann
  2015-03-25  9:06       ` Patrick Steinhardt
  0 siblings, 1 reply; 11+ messages in thread
From: Jens Lehmann @ 2015-03-23 21:32 UTC (permalink / raw)
  To: Patrick Steinhardt, Jonathan Nieder; +Cc: git, Heiko Voigt

Am 17.03.2015 um 08:56 schrieb Patrick Steinhardt:
> On Mon, Mar 16, 2015 at 01:03:53PM -0700, Jonathan Nieder wrote:
>> (+cc: Jens and Heiko, submodule experts)
>> Hi,
>>
>> Patrick Steinhardt wrote:
>>
>>> This proposal is just for discussion. If there is any interest I
>>> will implement the feature and send some patches.
>>>
>>> Currently it is hard to properly remove submodules. That is when
>>> a submodule is deinitialized and removed from a repository the
>>> directory '.git/modules/<SM_NAME>' will still be present and
>>> there is no way to remove it despite manually calling `rm` on it.
>>> I think there should be a command that is able to remove those
>>> dangling repositories if the following conditions are met:
>>>
>>> - the submodule should not be initialized
>>>
>>> - the submodule should not have an entry in .gitmodules in the
>>>    currently checked out revision
>>>
>>> - the submodule should not contain any commits that are not
>>>    upstream
>>>
>>> - the submodule should not contain other submodules that do not
>>>    meet those conditions
>>>
>>> This would ensure that it is hard to loose any commits that may
>>> be of interest. In the case that the user knows what he is doing
>>> we may provide a '--force' switch to override those checks.
>>
>> Those conditions look simultaneously too strong and too weak. ;-)
>>
>> In principle, it should be safe to remove .git/modules/<name> as
>> long as
>>
>>   (1) it (and its submodules, sub-sub-modules, etc) doesn't have any
>>       un-pushed local commits.
>>
>>   (2) it is not being referred to by a .git file in the work tree of
>>       the parent repository.
>>
>> Condition (1) can be relaxed if the user knows what they are losing
>> and is okay with that.  Condition (2) can be avoided by removing
>> (de-initing) the copy of that submodule in the worktree at the same
>> time.
>>
>> The functionality sounds like a useful thing to have, whether as an
>> option to 'git submodule deinit' or as a new subcommand.  In the long
>> term I would like it to be possible to do everything 'git submodule'
>> can do using normal git commands instead of that specialized
>> interface.  What command do you think this would eventually belong in?
>> (An option to "git gc", maybe?)
>>
>> Thanks,
>> Jonathan
>
> Thanks for your feedback.
>
> Considering that purging the submodule is tightly coupled with
> de-initializing it, it might make sense to provide this
> functionality as part of `git submodule deinit`. Maybe something
> like `git submodule deinit --purge` would work for the user.
> Problem is if the user first removes the submodule and does not
> first deinitialize it he is not able to purge the repository
> afterwards as deinit will complain about the submodule not being
> matched anymore. We could just make `deinit --purge` work with
> removed submodules, but that does not feel very natural to me.

Hmm, cmd_deinit() seems to cope with submodules removed by the
user just fine (as long as they are still present in the index).
To me it feels natural to extend deinit to remove the repo from
.git/modules too when --purge is given (as long as no unpushed
commits are present or -f is given).

> `git gc` feels saner in that regard, but I don't think it would
> be easy to spot for users as this command is in general not used
> very frequently by them. One could argue though that it does not
> need to be discoverable.

The error message of "git submodule deinit --purge" for a
submodule that isn't recorded in the index anymore could point
the user to the appropriate gc command. But how do we tell gc
which submodule it should purge? "--purge=<submodule-name>"
maybe?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] git submodule purge
  2015-03-23 21:32     ` Jens Lehmann
@ 2015-03-25  9:06       ` Patrick Steinhardt
  2015-03-25 19:47         ` Jens Lehmann
  0 siblings, 1 reply; 11+ messages in thread
From: Patrick Steinhardt @ 2015-03-25  9:06 UTC (permalink / raw)
  To: Jens Lehmann; +Cc: Jonathan Nieder, git, Heiko Voigt

[-- Attachment #1: Type: text/plain, Size: 5059 bytes --]

On Mon, Mar 23, 2015 at 10:32:27PM +0100, Jens Lehmann wrote:
> Am 17.03.2015 um 08:56 schrieb Patrick Steinhardt:
> > On Mon, Mar 16, 2015 at 01:03:53PM -0700, Jonathan Nieder wrote:
> >> (+cc: Jens and Heiko, submodule experts)
> >> Hi,
> >>
> >> Patrick Steinhardt wrote:
> >>
> >>> This proposal is just for discussion. If there is any interest I
> >>> will implement the feature and send some patches.
> >>>
> >>> Currently it is hard to properly remove submodules. That is when
> >>> a submodule is deinitialized and removed from a repository the
> >>> directory '.git/modules/<SM_NAME>' will still be present and
> >>> there is no way to remove it despite manually calling `rm` on it.
> >>> I think there should be a command that is able to remove those
> >>> dangling repositories if the following conditions are met:
> >>>
> >>> - the submodule should not be initialized
> >>>
> >>> - the submodule should not have an entry in .gitmodules in the
> >>>    currently checked out revision
> >>>
> >>> - the submodule should not contain any commits that are not
> >>>    upstream
> >>>
> >>> - the submodule should not contain other submodules that do not
> >>>    meet those conditions
> >>>
> >>> This would ensure that it is hard to loose any commits that may
> >>> be of interest. In the case that the user knows what he is doing
> >>> we may provide a '--force' switch to override those checks.
> >>
> >> Those conditions look simultaneously too strong and too weak. ;-)
> >>
> >> In principle, it should be safe to remove .git/modules/<name> as
> >> long as
> >>
> >>   (1) it (and its submodules, sub-sub-modules, etc) doesn't have any
> >>       un-pushed local commits.
> >>
> >>   (2) it is not being referred to by a .git file in the work tree of
> >>       the parent repository.
> >>
> >> Condition (1) can be relaxed if the user knows what they are losing
> >> and is okay with that.  Condition (2) can be avoided by removing
> >> (de-initing) the copy of that submodule in the worktree at the same
> >> time.
> >>
> >> The functionality sounds like a useful thing to have, whether as an
> >> option to 'git submodule deinit' or as a new subcommand.  In the long
> >> term I would like it to be possible to do everything 'git submodule'
> >> can do using normal git commands instead of that specialized
> >> interface.  What command do you think this would eventually belong in?
> >> (An option to "git gc", maybe?)
> >>
> >> Thanks,
> >> Jonathan
> >
> > Thanks for your feedback.
> >
> > Considering that purging the submodule is tightly coupled with
> > de-initializing it, it might make sense to provide this
> > functionality as part of `git submodule deinit`. Maybe something
> > like `git submodule deinit --purge` would work for the user.
> > Problem is if the user first removes the submodule and does not
> > first deinitialize it he is not able to purge the repository
> > afterwards as deinit will complain about the submodule not being
> > matched anymore. We could just make `deinit --purge` work with
> > removed submodules, but that does not feel very natural to me.
> 
> Hmm, cmd_deinit() seems to cope with submodules removed by the
> user just fine (as long as they are still present in the index).
> To me it feels natural to extend deinit to remove the repo from
> .git/modules too when --purge is given (as long as no unpushed
> commits are present or -f is given).
> 
> > `git gc` feels saner in that regard, but I don't think it would
> > be easy to spot for users as this command is in general not used
> > very frequently by them. One could argue though that it does not
> > need to be discoverable.
> 
> The error message of "git submodule deinit --purge" for a
> submodule that isn't recorded in the index anymore could point
> the user to the appropriate gc command. But how do we tell gc
> which submodule it should purge? "--purge=<submodule-name>"
> maybe?

This might work, but at least the option would need to provide a
hint to the user that it has something to do with submodules. So
if the feature was implemented by `git gc` I'd rather name the
parameter "--purge-submodule=<submodule-name>" which in my
opinion clearly states its intention, even though it is longer to
type. But with working bash-completion this should be non-issue,
especially as this command would not need to be run frequently.

That said, I think by now I agree with the common (?) opinion
that the command is best placed in `git submodule deinit --purge`
and I will likely implement it there. Optionally I could
implement `git gc --purge-submodule=<submodule-name>` as a second
way to access the feature so that we have a way of purging them
without using the submodules-interface. I doubt though that this
will provide much of a benefit as the user still has to be aware
that he is working with submodules as he has to provide the
`--purge-submodule` option, so there is not much to be gained by
this.

Regards
Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] git submodule purge
  2015-03-25  9:06       ` Patrick Steinhardt
@ 2015-03-25 19:47         ` Jens Lehmann
  2015-03-26 13:30           ` Patrick Steinhardt
  0 siblings, 1 reply; 11+ messages in thread
From: Jens Lehmann @ 2015-03-25 19:47 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: Jonathan Nieder, git, Heiko Voigt

Am 25.03.2015 um 10:06 schrieb Patrick Steinhardt:
> On Mon, Mar 23, 2015 at 10:32:27PM +0100, Jens Lehmann wrote:
>> Am 17.03.2015 um 08:56 schrieb Patrick Steinhardt:
>>> On Mon, Mar 16, 2015 at 01:03:53PM -0700, Jonathan Nieder wrote:
>>>> (+cc: Jens and Heiko, submodule experts)
>>>> Hi,
>>>>
>>>> Patrick Steinhardt wrote:
>>>>
>>>>> This proposal is just for discussion. If there is any interest I
>>>>> will implement the feature and send some patches.
>>>>>
>>>>> Currently it is hard to properly remove submodules. That is when
>>>>> a submodule is deinitialized and removed from a repository the
>>>>> directory '.git/modules/<SM_NAME>' will still be present and
>>>>> there is no way to remove it despite manually calling `rm` on it.
>>>>> I think there should be a command that is able to remove those
>>>>> dangling repositories if the following conditions are met:
>>>>>
>>>>> - the submodule should not be initialized
>>>>>
>>>>> - the submodule should not have an entry in .gitmodules in the
>>>>>     currently checked out revision
>>>>>
>>>>> - the submodule should not contain any commits that are not
>>>>>     upstream
>>>>>
>>>>> - the submodule should not contain other submodules that do not
>>>>>     meet those conditions
>>>>>
>>>>> This would ensure that it is hard to loose any commits that may
>>>>> be of interest. In the case that the user knows what he is doing
>>>>> we may provide a '--force' switch to override those checks.
>>>>
>>>> Those conditions look simultaneously too strong and too weak. ;-)
>>>>
>>>> In principle, it should be safe to remove .git/modules/<name> as
>>>> long as
>>>>
>>>>    (1) it (and its submodules, sub-sub-modules, etc) doesn't have any
>>>>        un-pushed local commits.
>>>>
>>>>    (2) it is not being referred to by a .git file in the work tree of
>>>>        the parent repository.
>>>>
>>>> Condition (1) can be relaxed if the user knows what they are losing
>>>> and is okay with that.  Condition (2) can be avoided by removing
>>>> (de-initing) the copy of that submodule in the worktree at the same
>>>> time.
>>>>
>>>> The functionality sounds like a useful thing to have, whether as an
>>>> option to 'git submodule deinit' or as a new subcommand.  In the long
>>>> term I would like it to be possible to do everything 'git submodule'
>>>> can do using normal git commands instead of that specialized
>>>> interface.  What command do you think this would eventually belong in?
>>>> (An option to "git gc", maybe?)
>>>>
>>>> Thanks,
>>>> Jonathan
>>>
>>> Thanks for your feedback.
>>>
>>> Considering that purging the submodule is tightly coupled with
>>> de-initializing it, it might make sense to provide this
>>> functionality as part of `git submodule deinit`. Maybe something
>>> like `git submodule deinit --purge` would work for the user.
>>> Problem is if the user first removes the submodule and does not
>>> first deinitialize it he is not able to purge the repository
>>> afterwards as deinit will complain about the submodule not being
>>> matched anymore. We could just make `deinit --purge` work with
>>> removed submodules, but that does not feel very natural to me.
>>
>> Hmm, cmd_deinit() seems to cope with submodules removed by the
>> user just fine (as long as they are still present in the index).
>> To me it feels natural to extend deinit to remove the repo from
>> .git/modules too when --purge is given (as long as no unpushed
>> commits are present or -f is given).
>>
>>> `git gc` feels saner in that regard, but I don't think it would
>>> be easy to spot for users as this command is in general not used
>>> very frequently by them. One could argue though that it does not
>>> need to be discoverable.
>>
>> The error message of "git submodule deinit --purge" for a
>> submodule that isn't recorded in the index anymore could point
>> the user to the appropriate gc command. But how do we tell gc
>> which submodule it should purge? "--purge=<submodule-name>"
>> maybe?
>
> This might work, but at least the option would need to provide a
> hint to the user that it has something to do with submodules. So
> if the feature was implemented by `git gc` I'd rather name the
> parameter "--purge-submodule=<submodule-name>" which in my
> opinion clearly states its intention, even though it is longer to
> type. But with working bash-completion this should be non-issue,
> especially as this command would not need to be run frequently.

Agreed.

> That said, I think by now I agree with the common (?) opinion
> that the command is best placed in `git submodule deinit --purge`
> and I will likely implement it there.

Me thinks that makes sense. But be aware that this will only work
for those submodules that are still present in the current index.

> Optionally I could
> implement `git gc --purge-submodule=<submodule-name>` as a second
> way to access the feature so that we have a way of purging them
> without using the submodules-interface. I doubt though that this
> will provide much of a benefit as the user still has to be aware
> that he is working with submodules as he has to provide the
> `--purge-submodule` option, so there is not much to be gained by
> this.

Hmm, I still believe cleaning up a submodule repo which is already
deinited makes sense. Using 'rm -rf .git/modules/<submodulename>'
will work just fine, but is missing any safeguards. The deinit
command takes submodule paths, not submodule names. So it looks
to me like 'git gc --purge-submodule=<submodule-name>' would make
sense here (and this command should check that the submodule has
already been deinited and fail otherwise telling the user so).

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] git submodule purge
  2015-03-25 19:47         ` Jens Lehmann
@ 2015-03-26 13:30           ` Patrick Steinhardt
  2015-03-26 21:48             ` Jens Lehmann
  0 siblings, 1 reply; 11+ messages in thread
From: Patrick Steinhardt @ 2015-03-26 13:30 UTC (permalink / raw)
  To: Jens Lehmann; +Cc: Jonathan Nieder, git, Heiko Voigt

[-- Attachment #1: Type: text/plain, Size: 3440 bytes --]

On Wed, Mar 25, 2015 at 08:47:59PM +0100, Jens Lehmann wrote:
> Am 25.03.2015 um 10:06 schrieb Patrick Steinhardt:
> > On Mon, Mar 23, 2015 at 10:32:27PM +0100, Jens Lehmann wrote:
> >> Am 17.03.2015 um 08:56 schrieb Patrick Steinhardt:
[snip]
> >> Hmm, cmd_deinit() seems to cope with submodules removed by the
> >> user just fine (as long as they are still present in the index).
> >> To me it feels natural to extend deinit to remove the repo from
> >> .git/modules too when --purge is given (as long as no unpushed
> >> commits are present or -f is given).
> >>
> >>> `git gc` feels saner in that regard, but I don't think it would
> >>> be easy to spot for users as this command is in general not used
> >>> very frequently by them. One could argue though that it does not
> >>> need to be discoverable.
> >>
> >> The error message of "git submodule deinit --purge" for a
> >> submodule that isn't recorded in the index anymore could point
> >> the user to the appropriate gc command. But how do we tell gc
> >> which submodule it should purge? "--purge=<submodule-name>"
> >> maybe?
> >
> > This might work, but at least the option would need to provide a
> > hint to the user that it has something to do with submodules. So
> > if the feature was implemented by `git gc` I'd rather name the
> > parameter "--purge-submodule=<submodule-name>" which in my
> > opinion clearly states its intention, even though it is longer to
> > type. But with working bash-completion this should be non-issue,
> > especially as this command would not need to be run frequently.
> 
> Agreed.
> 
> > That said, I think by now I agree with the common (?) opinion
> > that the command is best placed in `git submodule deinit --purge`
> > and I will likely implement it there.
> 
> Me thinks that makes sense. But be aware that this will only work
> for those submodules that are still present in the current index.
> 
> > Optionally I could
> > implement `git gc --purge-submodule=<submodule-name>` as a second
> > way to access the feature so that we have a way of purging them
> > without using the submodules-interface. I doubt though that this
> > will provide much of a benefit as the user still has to be aware
> > that he is working with submodules as he has to provide the
> > `--purge-submodule` option, so there is not much to be gained by
> > this.
> 
> Hmm, I still believe cleaning up a submodule repo which is already
> deinited makes sense. Using 'rm -rf .git/modules/<submodulename>'
> will work just fine, but is missing any safeguards. The deinit
> command takes submodule paths, not submodule names. So it looks
> to me like 'git gc --purge-submodule=<submodule-name>' would make
> sense here (and this command should check that the submodule has
> already been deinited and fail otherwise telling the user so).

Ah, okay. I thought your intention was to provide `git gc
--purge-sm` _instead_ of `git sm deinit --purge`. Guess it makes
sense to have both available for the different use cases
(explicitly removing a submodule vs removing unreferenced ones).
I guess one could even provide another option
`--purge-submodules` in addition to `--purge-sm=<smname>` that
will remove all deinitialized submodules without local commits.
Maybe its desirable to have a `--dry-run` flag as well that would
print which repositories would be deleted by `--purge-sms`.


Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [RFC] git submodule purge
  2015-03-26 13:30           ` Patrick Steinhardt
@ 2015-03-26 21:48             ` Jens Lehmann
  0 siblings, 0 replies; 11+ messages in thread
From: Jens Lehmann @ 2015-03-26 21:48 UTC (permalink / raw)
  To: Patrick Steinhardt; +Cc: Jonathan Nieder, git, Heiko Voigt

Am 26.03.2015 um 14:30 schrieb Patrick Steinhardt:
> On Wed, Mar 25, 2015 at 08:47:59PM +0100, Jens Lehmann wrote:
>> Am 25.03.2015 um 10:06 schrieb Patrick Steinhardt:
>>> Optionally I could
>>> implement `git gc --purge-submodule=<submodule-name>` as a second
>>> way to access the feature so that we have a way of purging them
>>> without using the submodules-interface. I doubt though that this
>>> will provide much of a benefit as the user still has to be aware
>>> that he is working with submodules as he has to provide the
>>> `--purge-submodule` option, so there is not much to be gained by
>>> this.
>>
>> Hmm, I still believe cleaning up a submodule repo which is already
>> deinited makes sense. Using 'rm -rf .git/modules/<submodulename>'
>> will work just fine, but is missing any safeguards. The deinit
>> command takes submodule paths, not submodule names. So it looks
>> to me like 'git gc --purge-submodule=<submodule-name>' would make
>> sense here (and this command should check that the submodule has
>> already been deinited and fail otherwise telling the user so).
>
> Ah, okay. I thought your intention was to provide `git gc
> --purge-sm` _instead_ of `git sm deinit --purge`. Guess it makes
> sense to have both available for the different use cases
> (explicitly removing a submodule vs removing unreferenced ones).

Yup. And I wonder if `--purge` should be the default for deinit
if no unpushed commits will be lost ... but let's hear what
others think about this one.

> I guess one could even provide another option
> `--purge-submodules` in addition to `--purge-sm=<smname>` that
> will remove all deinitialized submodules without local commits.
> Maybe its desirable to have a `--dry-run` flag as well that would
> print which repositories would be deleted by `--purge-sms`.

Hmm, thinking about that some more maybe we might wanna simplify
this a bit. Adding a `--prune-submodules` option to gc which will
remove all deinitialized submodules repos that don't have any
unpushed commits should be sufficient to do the housekeeping. If
people demand to be able to prune specific submodules later we
could still add a `--prune-submodule=<name>`, but I suspect we
might not need that.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-03-26 21:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-16 13:44 [RFC] git submodule purge Patrick Steinhardt
2015-03-16 15:55 ` Junio C Hamano
2015-03-17  8:18   ` Patrick Steinhardt
2015-03-17  8:25     ` Fredrik Gustafsson
2015-03-16 20:03 ` Jonathan Nieder
2015-03-17  7:56   ` Patrick Steinhardt
2015-03-23 21:32     ` Jens Lehmann
2015-03-25  9:06       ` Patrick Steinhardt
2015-03-25 19:47         ` Jens Lehmann
2015-03-26 13:30           ` Patrick Steinhardt
2015-03-26 21:48             ` Jens Lehmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).