All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH/RFC] Pinning of submodules
       [not found] <55E78522.1030107@gmail.com>
@ 2015-09-02 23:34 ` Anders Ro
  2015-09-04  5:02   ` Eric Sunshine
  0 siblings, 1 reply; 7+ messages in thread
From: Anders Ro @ 2015-09-02 23:34 UTC (permalink / raw)
  To: git

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

Patch to make it possible to pin submodules so that they are not
affected by the --remote option in "git submodule".

Anders Ro (2):
  git-submodule.sh: pin submodule when branch name is '@'
  t7412: add test case for pinned submodules

 Documentation/git-submodule.txt |  3 +-
 git-submodule.sh                |  9 ++++-
 t/t7412-submodule-pinning.sh    | 73
+++++++++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+), 2 deletions(-)
 create mode 100755 t/t7412-submodule-pinning.sh


[-- Attachment #2: 0001-git-submodule.sh-pin-submodule-when-branch-name-is.txt --]
[-- Type: text/plain, Size: 2422 bytes --]

From 32b25aded0c4e30c68ac3ab75f4cbb63302ca147 Mon Sep 17 00:00:00 2001
From: Anders Ro <anders.ronnbrant@gmail.com>
Date: Fri, 28 Nov 2014 01:39:37 +0100
Subject: [PATCH 1/2] git-submodule.sh: pin submodule when branch name is '@'

Setting branch name to '@' for a submodule will disable 'git submodule
update --remote' calls for that specific submodule. I.e. instead of
follow the unspecified default choice of master, nothing is being
updated. This is useful when multiple submodules exist but not all
should follow the remote branch head.

Signed-off-by: Anders Ro <anders.ronnbrant@gmail.com>
---
 Documentation/git-submodule.txt | 3 ++-
 git-submodule.sh                | 9 ++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index f17687e..bd0cced 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -289,7 +289,8 @@ OPTIONS
 	The remote branch used defaults to `master`, but the branch name may
 	be overridden by setting the `submodule.<name>.branch` option in
 	either `.gitmodules` or `.git/config` (with `.git/config` taking
-	precedence).
+	precedence). Setting the branch name to the invalid branch name '@'
+	disables this option, i.e. pins the submodule at the recorded SHA-1.
 +
 This works for any of the supported update procedures (`--checkout`,
 `--rebase`, etc.).  The only change is the source of the target SHA-1.
diff --git a/git-submodule.sh b/git-submodule.sh
index 25b1ddf..1bb2bb1 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -843,7 +843,8 @@ Maybe you want to use 'update --init'?")"
 			die "$(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")"
 		fi
 
-		if test -n "$remote"
+		# Fetch latest in remote unless branch name in config is '@'
+		if test -n "$remote" -a "$branch" != "@"
 		then
 			if test -z "$nofetch"
 			then
@@ -857,6 +858,12 @@ Maybe you want to use 'update --init'?")"
 			die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
 		fi
 
+		# Inform that the current sm is pinned and use of '--remote' ignored
+		if test -n "$remote" -a "$branch" = "@"
+		then
+			say "$(eval_gettext "Submodule path '\$displaypath' pinned, remote update ignored")"
+		fi
+
 		if test "$subsha1" != "$sha1" || test -n "$force"
 		then
 			subforce=$force
-- 
2.1.4


[-- Attachment #3: 0002-t7412-add-test-case-for-pinned-submodules.txt --]
[-- Type: text/plain, Size: 2586 bytes --]

From 98e6677325bada62301eba18b81f4884793d7c02 Mon Sep 17 00:00:00 2001
From: Anders Ro <anders.ronnbrant@gmail.com>
Date: Thu, 3 Sep 2015 00:03:15 +0200
Subject: [PATCH 2/2] t7412: add test case for pinned submodules

Signed-off-by: Anders Ro <anders.ronnbrant@gmail.com>
---
 t/t7412-submodule-pinning.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100755 t/t7412-submodule-pinning.sh

diff --git a/t/t7412-submodule-pinning.sh b/t/t7412-submodule-pinning.sh
new file mode 100755
index 0000000..2844b1e
--- /dev/null
+++ b/t/t7412-submodule-pinning.sh
@@ -0,0 +1,73 @@
+#!/bin/sh
+#
+# Copyright (c) 2015 Anders Ronnbrant
+#
+
+test_description="Branch name '@' disables submodule update --remote calls"
+
+. ./test-lib.sh
+
+get_sha() {
+  cd $1 && git rev-list --max-count=1 HEAD
+}
+
+equal_sha() {
+  test "$(get_sha $1)" = "$(get_sha $2)"
+}
+
+not_equal_sha() {
+  test "$(get_sha $1)" != "$(get_sha $2)"
+}
+
+test_expect_success 'setup submodule tree structure' '
+for i in 1 2 3; do echo file$i > file$i; git add file$i; git commit -m file$i; done &&
+test_tick &&
+git clone . super &&
+git clone . follow &&
+git clone . pinned &&
+(cd super && git submodule add -b master ../follow follow) &&
+(cd super && git submodule add           ../pinned pinned)
+'
+
+test_expect_success 'verify submodules have the same SHA' '
+equal_sha super/follow super/pinned
+'
+
+
+test_expect_success 'switch submodule pinned to HEAD~1 and commit super' '
+(cd super/pinned && git checkout master && git reset --hard HEAD~1) &&
+(cd super && git add pinned && git commit -m "Submodule pinned @ HEAD~1") &&
+(cd super && git submodule status)
+'
+
+
+test_expect_success 'verify submodules not have the same SHA anymore' '
+not_equal_sha super/follow super/pinned
+'
+
+
+test_expect_success 'set branch name to "@" for submodule pinned' '
+(cd super && git config --replace-all submodule.pinned.branch "@") &&
+test "$(cd super && git config --get submodule.pinned.branch)" = "@"
+'
+
+
+test_expect_success 'run submodule update --remote and expect no change' '
+(cd super && git submodule update --remote) &&
+not_equal_sha super/follow super/pinned
+'
+
+
+test_expect_success 'remove branch name "@" for submodule pinned (unpin)' '
+(cd super && git config --unset-all submodule.pinned.branch) &&
+(cd super && git config --list)
+'
+
+
+test_expect_success 'run submodule update --remote and expect same SHA1 again' '
+(cd super && git submodule update --remote) &&
+equal_sha super/follow super/pinned
+'
+
+
+test_done
-- 
2.1.4


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

* Re: [PATCH/RFC] Pinning of submodules
  2015-09-02 23:34 ` [PATCH/RFC] Pinning of submodules Anders Ro
@ 2015-09-04  5:02   ` Eric Sunshine
  2015-09-06 22:08     ` Anders Ro
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Sunshine @ 2015-09-04  5:02 UTC (permalink / raw)
  To: Anders Ro; +Cc: Git List

On Wed, Sep 2, 2015 at 7:34 PM, Anders Ro <anders.ronnbrant@gmail.com> wrote:
> Patch to make it possible to pin submodules so that they are not
> affected by the --remote option in "git submodule".

Thanks for the patches. I don't use submodules, so I can't comment
specifically on this change, however, I can offer some general
comments on the patches. But first, a piece of advice...

Use git-send-email to post the patches as proper emails, one email
per patch, rather than as attachments. Reviewers are going to want to
write inline comments on the patches, and they can't do so when the
patches are attachments, so attaching patches discourages reviewers
from responding.

> git-submodule.sh: pin submodule when branch name is '@'
>
> Setting branch name to '@' for a submodule will disable 'git submodule
> update --remote' calls for that specific submodule. I.e. instead of
> follow the unspecified default choice of master, nothing is being
> updated. This is useful when multiple submodules exist but not all
> should follow the remote branch head.

With the disclaimer that I'm not a submodule user (to which the
answer might be obvious): What benefit is there in using a magic
value like this ("@") over, say, an explicit configuration setting?

> Signed-off-by: Anders Ro <anders.ronnbrant@gmail.com>
> ---
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 25b1ddf..1bb2bb1 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -843,7 +843,8 @@ Maybe you want to use 'update --init'?")"
>   die "$(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")"
>   fi
>
> - if test -n "$remote"
> + # Fetch latest in remote unless branch name in config is '@'
> + if test -n "$remote" -a "$branch" != "@"

The -a option to 'test' is not portable[1] and is considered obsolete
by POSIX[2]. Use "test foo && test bar" instead.

[1]: http://www.gnu.org/software/autoconf/manual/autoconf.html#index-g_t_0040command_007btest_007d-1793
[2]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html

>   then
>   if test -z "$nofetch"
>   then
> @@ -857,6 +858,12 @@ Maybe you want to use 'update --init'?")"
>   die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
>   fi
>
> + # Inform that the current sm is pinned and use of '--remote' ignored
> + if test -n "$remote" -a "$branch" = "@"

Ditto.

> + then
> + say "$(eval_gettext "Submodule path '\$displaypath' pinned, remote update ignored")"
> + fi
> +

> Subject: [PATCH 2/2] t7412: add test case for pinned submodules
>
> Signed-off-by: Anders Ro <anders.ronnbrant@gmail.com>
> ---
> diff --git a/t/t7412-submodule-pinning.sh b/t/t7412-submodule-pinning.sh
> new file mode 100755
> index 0000000..2844b1e
> --- /dev/null
> +++ b/t/t7412-submodule-pinning.sh
> @@ -0,0 +1,73 @@
> +#!/bin/sh
> +#
> +# Copyright (c) 2015 Anders Ronnbrant
> +#
> +
> +test_description="Branch name '@' disables submodule update --remote calls"
> +
> +. ./test-lib.sh
> +
> +get_sha() {
> +  cd $1 && git rev-list --max-count=1 HEAD
> +}

A few issues:

Indent with tabs (width 8), not spaces. (This comment applies to the
entire patch).

Style for shell scripts on this project is to have a space before
"()".

Taking a hint from t/test-lib-functions.sh:test_cmp_rev(), use "git
rev-parse --verify" instead.

It's a bit ugly that this does "cd $1" without ever balancing it with
a return to the original directory. If someone later comes along and
writes:

    get_sha1 fiddle >fiddle-id

in a new test, then that person will be surprised to find that the
current working directory changed out from under him. The current
patch doesn't experience this problem since it always invokes it as
$(get_sha1 fiddle), but it could be made more robust by either
wrapping it in a subshell so that the 'cd' is undone when the
subshell exits, or by using "-C $1".

Taking the above comments into account:

    get_sha () {
        git -C "$1" rev-parse --verify HEAD
    }

> +equal_sha() {
> +  test "$(get_sha $1)" = "$(get_sha $2)"
> +}
> +
> +not_equal_sha() {
> +  test "$(get_sha $1)" != "$(get_sha $2)"
> +}

Style: space before "()" on these two function declarations

> +test_expect_success 'setup submodule tree structure' '
> +for i in 1 2 3; do echo file$i > file$i; git add file$i; git commit -m file$i; done &&

Style: write each command of the 'for' loop on its own line,
including 'do', don't use semi-colons

Style: no space after redirection operator: >file$i

Keep the &&-chain intact, and end the chain with "|| return $?" so
that the 'for' loop correctly exits if any contained command fails.

    for i in 1 2 3
    do
        echo file$i >file$i &&
        git add file$i &&
        git commit -m file$i || return $?
    done

> +test_tick &&

Why is this needed? There doesn't seem to be any obvious reason for
its presence, and the test still passes without it.

> +git clone . super &&
> +git clone . follow &&
> +git clone . pinned &&
> +(cd super && git submodule add -b master ../follow follow) &&
> +(cd super && git submodule add           ../pinned pinned)

Style: it's probably better to avoid aligning columns like this since
it can end up being a maintenance headache, and because the line with
the extensive blank span can be difficult to read in isolation.

Since both of these execute in directory 'super', this could be
stated more concisely as:

    (
    cd super &&
    git submodule add ... &&
    git submodule add ...
    ) &&

Placement of the subshell parentheses is intentional.

> +'
> +
> +test_expect_success 'verify submodules have the same SHA' '
> +equal_sha super/follow super/pinned
> +'

Style: indent the test body (using tab); this comment applies to the
entire patch

> +
> +

Style: one blank line between tests, not two

> +test_expect_success 'switch submodule pinned to HEAD~1 and commit super' '
> +(cd super/pinned && git checkout master && git reset --hard HEAD~1) &&
> +(cd super && git add pinned && git commit -m "Submodule pinned @ HEAD~1") &&
> +(cd super && git submodule status)
> +'

Style: one command per line; format subshell as shown in above
example

You can combine the two 'cd super' bits into a single subshell.

> +
> +
> +test_expect_success 'verify submodules not have the same SHA anymore' '
> +not_equal_sha super/follow super/pinned
> +'

Each test should be a logical unit. In prose, you might describe a
test as "set condition A, make change B, and verify that A and B
resulted in some expected state".

This test is the "verify A and B" part, and the preceding test is the
"set condition A, make change B" part, however, splitting them up
like this makes it difficult for the reader to understand how they
are related. Worse, someone may come along and insert a new test
between the two, not realizing that these two tests are logically
one, possibly breaking them.

Consequently, this test should be combined with the one preceding it.

> +
> +
> +test_expect_success 'set branch name to "@" for submodule pinned' '
> +(cd super && git config --replace-all submodule.pinned.branch "@") &&
> +test "$(cd super && git config --get submodule.pinned.branch)" = "@"

What is the last line testing? It appears to be testing the behavior
of git-config, which is outside the scope of this test script.

> +'
> +
> +
> +test_expect_success 'run submodule update --remote and expect no change' '
> +(cd super && git submodule update --remote) &&
> +not_equal_sha super/follow super/pinned
> +'

All the above comments apply here too. These two tests are logically
one, thus should be combined.

Once combined, you can use test_config rather than git-config, since
test_config will ensure that the config setting is undone when the
test exits.

> +
> +
> +test_expect_success 'remove branch name "@" for submodule pinned (unpin)' '
> +(cd super && git config --unset-all submodule.pinned.branch) &&

If you take the above advice and use test_config in the previous
test, then this won't be needed.

> +(cd super && git config --list)

This isn't testing anything at all, but is instead merely cluttering
the output (when --verbose is enabled). It looks like debugging code
which should have been removed before committing.

> +'
> +
> +
> +test_expect_success 'run submodule update --remote and expect same SHA1 again' '
> +(cd super && git submodule update --remote) &&

For these one-line subshells, "-C super" is easier and reads
better. (This comment also applies to the rest of the patch.)

> +equal_sha super/follow super/pinned
> +'

This test should be combined with the previous one (although, if you
follow the advice regarding the previous test, then that test will
collapse to nothing...).

> +
> +
> +test_done
> --
> 2.1.4

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

* Re: [PATCH/RFC] Pinning of submodules
  2015-09-04  5:02   ` Eric Sunshine
@ 2015-09-06 22:08     ` Anders Ro
  2015-09-06 23:43       ` Eric Sunshine
  0 siblings, 1 reply; 7+ messages in thread
From: Anders Ro @ 2015-09-06 22:08 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List

On 04/09/15 07:02, Eric Sunshine wrote:
> On Wed, Sep 2, 2015 at 7:34 PM, Anders Ro <anders.ronnbrant@gmail.com> wrote:
>> Patch to make it possible to pin submodules so that they are not
>> affected by the --remote option in "git submodule".
> 
> Thanks for the patches. I don't use submodules, so I can't comment
> specifically on this change, however, I can offer some general
> comments on the patches. But first, a piece of advice...
> 
> Use git-send-email to post the patches as proper emails, one email
> per patch, rather than as attachments. Reviewers are going to want to
> write inline comments on the patches, and they can't do so when the
> patches are attachments, so attaching patches discourages reviewers
> from responding.

Thanks for the advice and the code comments, I knew I would get it wrong
somehow :). I did try to follow an IMAP Gmail guide in a hurry. I'll fix
the code and make sure git send-mail works the next time.

>> git-submodule.sh: pin submodule when branch name is '@'
>>
>> Setting branch name to '@' for a submodule will disable 'git submodule
>> update --remote' calls for that specific submodule. I.e. instead of
>> follow the unspecified default choice of master, nothing is being
>> updated. This is useful when multiple submodules exist but not all
>> should follow the remote branch head.
> 
> With the disclaimer that I'm not a submodule user (to which the
> answer might be obvious): What benefit is there in using a magic
> value like this ("@") over, say, an explicit configuration setting?

>From what I have understood (not a submodule expert yet) the '@' is an
invalid branch name and should therefore not collide with any current
branches. My idea was to disable the '--remote' option when the user
have explicitly set an invalid branch name to not modify any current
behaviour. Though having an explicit option is of course more
clarifying. The current behaviour though is that empty branch name means
"follow master" which is somewhat unintuitive.

>> Signed-off-by: Anders Ro <anders.ronnbrant@gmail.com>
>> ---
>> diff --git a/git-submodule.sh b/git-submodule.sh
>> index 25b1ddf..1bb2bb1 100755
>> --- a/git-submodule.sh
>> +++ b/git-submodule.sh
>> @@ -843,7 +843,8 @@ Maybe you want to use 'update --init'?")"
>>   die "$(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")"
>>   fi
>>
>> - if test -n "$remote"
>> + # Fetch latest in remote unless branch name in config is '@'
>> + if test -n "$remote" -a "$branch" != "@"
> 
> The -a option to 'test' is not portable[1] and is considered obsolete
> by POSIX[2]. Use "test foo && test bar" instead.
> 
> [1]: http://www.gnu.org/software/autoconf/manual/autoconf.html#index-g_t_0040command_007btest_007d-1793
> [2]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
> 
>>   then
>>   if test -z "$nofetch"
>>   then
>> @@ -857,6 +858,12 @@ Maybe you want to use 'update --init'?")"
>>   die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
>>   fi
>>
>> + # Inform that the current sm is pinned and use of '--remote' ignored
>> + if test -n "$remote" -a "$branch" = "@"
> 
> Ditto.
> 
>> + then
>> + say "$(eval_gettext "Submodule path '\$displaypath' pinned, remote update ignored")"
>> + fi
>> +
> 
>> Subject: [PATCH 2/2] t7412: add test case for pinned submodules
>>
>> Signed-off-by: Anders Ro <anders.ronnbrant@gmail.com>
>> ---
>> diff --git a/t/t7412-submodule-pinning.sh b/t/t7412-submodule-pinning.sh
>> new file mode 100755
>> index 0000000..2844b1e
>> --- /dev/null
>> +++ b/t/t7412-submodule-pinning.sh
>> @@ -0,0 +1,73 @@
>> +#!/bin/sh
>> +#
>> +# Copyright (c) 2015 Anders Ronnbrant
>> +#
>> +
>> +test_description="Branch name '@' disables submodule update --remote calls"
>> +
>> +. ./test-lib.sh
>> +
>> +get_sha() {
>> +  cd $1 && git rev-list --max-count=1 HEAD
>> +}
> 
> A few issues:
> 
> Indent with tabs (width 8), not spaces. (This comment applies to the
> entire patch).
> 
> Style for shell scripts on this project is to have a space before
> "()".
> 
> Taking a hint from t/test-lib-functions.sh:test_cmp_rev(), use "git
> rev-parse --verify" instead.
> 
> It's a bit ugly that this does "cd $1" without ever balancing it with
> a return to the original directory. If someone later comes along and
> writes:
> 
>     get_sha1 fiddle >fiddle-id
> 
> in a new test, then that person will be surprised to find that the
> current working directory changed out from under him. The current
> patch doesn't experience this problem since it always invokes it as
> $(get_sha1 fiddle), but it could be made more robust by either
> wrapping it in a subshell so that the 'cd' is undone when the
> subshell exits, or by using "-C $1".
> 
> Taking the above comments into account:
> 
>     get_sha () {
>         git -C "$1" rev-parse --verify HEAD
>     }
> 
>> +equal_sha() {
>> +  test "$(get_sha $1)" = "$(get_sha $2)"
>> +}
>> +
>> +not_equal_sha() {
>> +  test "$(get_sha $1)" != "$(get_sha $2)"
>> +}
> 
> Style: space before "()" on these two function declarations
> 
>> +test_expect_success 'setup submodule tree structure' '
>> +for i in 1 2 3; do echo file$i > file$i; git add file$i; git commit -m file$i; done &&
> 
> Style: write each command of the 'for' loop on its own line,
> including 'do', don't use semi-colons
> 
> Style: no space after redirection operator: >file$i
> 
> Keep the &&-chain intact, and end the chain with "|| return $?" so
> that the 'for' loop correctly exits if any contained command fails.
> 
>     for i in 1 2 3
>     do
>         echo file$i >file$i &&
>         git add file$i &&
>         git commit -m file$i || return $?
>     done
> 
>> +test_tick &&
> 
> Why is this needed? There doesn't seem to be any obvious reason for
> its presence, and the test still passes without it.
> 
>> +git clone . super &&
>> +git clone . follow &&
>> +git clone . pinned &&
>> +(cd super && git submodule add -b master ../follow follow) &&
>> +(cd super && git submodule add           ../pinned pinned)
> 
> Style: it's probably better to avoid aligning columns like this since
> it can end up being a maintenance headache, and because the line with
> the extensive blank span can be difficult to read in isolation.
> 
> Since both of these execute in directory 'super', this could be
> stated more concisely as:
> 
>     (
>     cd super &&
>     git submodule add ... &&
>     git submodule add ...
>     ) &&
> 
> Placement of the subshell parentheses is intentional.
> 
>> +'
>> +
>> +test_expect_success 'verify submodules have the same SHA' '
>> +equal_sha super/follow super/pinned
>> +'
> 
> Style: indent the test body (using tab); this comment applies to the
> entire patch
> 
>> +
>> +
> 
> Style: one blank line between tests, not two
> 
>> +test_expect_success 'switch submodule pinned to HEAD~1 and commit super' '
>> +(cd super/pinned && git checkout master && git reset --hard HEAD~1) &&
>> +(cd super && git add pinned && git commit -m "Submodule pinned @ HEAD~1") &&
>> +(cd super && git submodule status)
>> +'
> 
> Style: one command per line; format subshell as shown in above
> example
> 
> You can combine the two 'cd super' bits into a single subshell.
> 
>> +
>> +
>> +test_expect_success 'verify submodules not have the same SHA anymore' '
>> +not_equal_sha super/follow super/pinned
>> +'
> 
> Each test should be a logical unit. In prose, you might describe a
> test as "set condition A, make change B, and verify that A and B
> resulted in some expected state".
> 
> This test is the "verify A and B" part, and the preceding test is the
> "set condition A, make change B" part, however, splitting them up
> like this makes it difficult for the reader to understand how they
> are related. Worse, someone may come along and insert a new test
> between the two, not realizing that these two tests are logically
> one, possibly breaking them.
> 
> Consequently, this test should be combined with the one preceding it.
> 
>> +
>> +
>> +test_expect_success 'set branch name to "@" for submodule pinned' '
>> +(cd super && git config --replace-all submodule.pinned.branch "@") &&
>> +test "$(cd super && git config --get submodule.pinned.branch)" = "@"
> 
> What is the last line testing? It appears to be testing the behavior
> of git-config, which is outside the scope of this test script.
> 
>> +'
>> +
>> +
>> +test_expect_success 'run submodule update --remote and expect no change' '
>> +(cd super && git submodule update --remote) &&
>> +not_equal_sha super/follow super/pinned
>> +'
> 
> All the above comments apply here too. These two tests are logically
> one, thus should be combined.
> 
> Once combined, you can use test_config rather than git-config, since
> test_config will ensure that the config setting is undone when the
> test exits.
> 
>> +
>> +
>> +test_expect_success 'remove branch name "@" for submodule pinned (unpin)' '
>> +(cd super && git config --unset-all submodule.pinned.branch) &&
> 
> If you take the above advice and use test_config in the previous
> test, then this won't be needed.
> 
>> +(cd super && git config --list)
> 
> This isn't testing anything at all, but is instead merely cluttering
> the output (when --verbose is enabled). It looks like debugging code
> which should have been removed before committing.
> 
>> +'
>> +
>> +
>> +test_expect_success 'run submodule update --remote and expect same SHA1 again' '
>> +(cd super && git submodule update --remote) &&
> 
> For these one-line subshells, "-C super" is easier and reads
> better. (This comment also applies to the rest of the patch.)
> 
>> +equal_sha super/follow super/pinned
>> +'
> 
> This test should be combined with the previous one (although, if you
> follow the advice regarding the previous test, then that test will
> collapse to nothing...).
> 
>> +
>> +
>> +test_done
>> --
>> 2.1.4

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

* Re: [PATCH/RFC] Pinning of submodules
  2015-09-06 22:08     ` Anders Ro
@ 2015-09-06 23:43       ` Eric Sunshine
  2015-09-07 20:13         ` Jens Lehmann
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Sunshine @ 2015-09-06 23:43 UTC (permalink / raw)
  To: Anders Ro
  Cc: Git List, Jens Lehmann, Heiko Voigt, Johan Herland, Mark Levedahl

On Sun, Sep 6, 2015 at 6:08 PM, Anders Ro <anders.ronnbrant@gmail.com> wrote:
> On 04/09/15 07:02, Eric Sunshine wrote:
>> On Wed, Sep 2, 2015 at 7:34 PM, Anders Ro <anders.ronnbrant@gmail.com> wrote:
>>> git-submodule.sh: pin submodule when branch name is '@'
>>>
>>> Setting branch name to '@' for a submodule will disable 'git submodule
>>> update --remote' calls for that specific submodule. I.e. instead of
>>> follow the unspecified default choice of master, nothing is being
>>> updated. This is useful when multiple submodules exist but not all
>>> should follow the remote branch head.
>>
>> With the disclaimer that I'm not a submodule user (to which the
>> answer might be obvious): What benefit is there in using a magic
>> value like this ("@") over, say, an explicit configuration setting?
>
> From what I have understood (not a submodule expert yet) the '@' is an
> invalid branch name and should therefore not collide with any current
> branches. My idea was to disable the '--remote' option when the user
> have explicitly set an invalid branch name to not modify any current
> behaviour. Though having an explicit option is of course more
> clarifying. The current behaviour though is that empty branch name means
> "follow master" which is somewhat unintuitive.

My concern in asking was that some future person might come up with
another scenario which also wants to use a "magic value" and would
have to invent / arrive at another "illegal" representation. Hence, an
explicit setting might be more appropriate. However, as stated, I
don't even use submodules, so I may be far off the mark. I've cc'd a
few of the submodule maintainers with the hope that they will chime
in.

>>> +test_expect_success 'set branch name to "@" for submodule pinned' '
>>> +(cd super && git config --replace-all submodule.pinned.branch "@") &&
>>> +test "$(cd super && git config --get submodule.pinned.branch)" = "@"
>>
>> What is the last line testing? It appears to be testing the behavior
>> of git-config, which is outside the scope of this test script.
>>
>> Once combined, you can use test_config rather than git-config, since
>> test_config will ensure that the config setting is undone when the
>> test exits.

In light of this recent thread[1] which shows that
test_when_finished() and, consequently, test_config() are
non-functional in subshells, I have to retract the advice to use
test_config() in this situation. Instead, at this time, it probably
would be best to continue using "git-config" as you do here...

>>> +test_expect_success 'remove branch name "@" for submodule pinned (unpin)' '
>>> +(cd super && git config --unset-all submodule.pinned.branch) &&
>>
>> If you take the above advice and use test_config in the previous
>> test, then this won't be needed.

and "git-config --unset-all" here.

Later, once [1] has landed in "master" (or perhaps "next"), this can
be revisited and updated to use "test_config -C"[2].

[1]: http://thread.gmane.org/gmane.comp.version-control.git/277323/focus=277370
[2]: http://thread.gmane.org/gmane.comp.version-control.git/277323/focus=277372

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

* Re: [PATCH/RFC] Pinning of submodules
  2015-09-06 23:43       ` Eric Sunshine
@ 2015-09-07 20:13         ` Jens Lehmann
  2015-09-07 23:27           ` Anders Ro
  2015-09-08 16:55           ` Junio C Hamano
  0 siblings, 2 replies; 7+ messages in thread
From: Jens Lehmann @ 2015-09-07 20:13 UTC (permalink / raw)
  To: Eric Sunshine, Anders Ro
  Cc: Git List, Heiko Voigt, Johan Herland, Mark Levedahl, W. Trevor King

Am 07.09.2015 um 01:43 schrieb Eric Sunshine:
> On Sun, Sep 6, 2015 at 6:08 PM, Anders Ro <anders.ronnbrant@gmail.com> wrote:
>> On 04/09/15 07:02, Eric Sunshine wrote:
>>> On Wed, Sep 2, 2015 at 7:34 PM, Anders Ro <anders.ronnbrant@gmail.com> wrote:
>>>> git-submodule.sh: pin submodule when branch name is '@'
>>>>
>>>> Setting branch name to '@' for a submodule will disable 'git submodule
>>>> update --remote' calls for that specific submodule. I.e. instead of
>>>> follow the unspecified default choice of master, nothing is being
>>>> updated. This is useful when multiple submodules exist but not all
>>>> should follow the remote branch head.
>>>
>>> With the disclaimer that I'm not a submodule user (to which the
>>> answer might be obvious): What benefit is there in using a magic
>>> value like this ("@") over, say, an explicit configuration setting?
>>
>>  From what I have understood (not a submodule expert yet) the '@' is an
>> invalid branch name and should therefore not collide with any current
>> branches. My idea was to disable the '--remote' option when the user
>> have explicitly set an invalid branch name to not modify any current
>> behaviour. Though having an explicit option is of course more
>> clarifying. The current behaviour though is that empty branch name means
>> "follow master" which is somewhat unintuitive.
>
> My concern in asking was that some future person might come up with
> another scenario which also wants to use a "magic value" and would
> have to invent / arrive at another "illegal" representation. Hence, an
> explicit setting might be more appropriate. However, as stated, I
> don't even use submodules, so I may be far off the mark. I've cc'd a
> few of the submodule maintainers with the hope that they will chime
> in.

Added Trevor to the CC, who is the original author of --remote (see
06b1abb5b).

While I believe that adding such functionality makes perfect sense,
I do not find it terribly obvious that setting the branch to '@' will
make --remote skip this submodule. I wouldn't care so much if we'd
only use this value internally, but this is user visible (and has to
be set by the user if she wants to skip a submodule in --remote).

Setting the branch to an empty value feels a bit more natural, but
I'm not so sure our config handling supports that well (we seem to
assume in quite some places that empty equals unset). So I tend to
prefer a new option for that.

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

* Re: [PATCH/RFC] Pinning of submodules
  2015-09-07 20:13         ` Jens Lehmann
@ 2015-09-07 23:27           ` Anders Ro
  2015-09-08 16:55           ` Junio C Hamano
  1 sibling, 0 replies; 7+ messages in thread
From: Anders Ro @ 2015-09-07 23:27 UTC (permalink / raw)
  To: Jens Lehmann, Eric Sunshine
  Cc: Git List, Heiko Voigt, Johan Herland, Mark Levedahl, W. Trevor King

On 07/09/15 22:13, Jens Lehmann wrote:
> Am 07.09.2015 um 01:43 schrieb Eric Sunshine:
>> On Sun, Sep 6, 2015 at 6:08 PM, Anders Ro <anders.ronnbrant@gmail.com>
>> wrote:
>>> On 04/09/15 07:02, Eric Sunshine wrote:
>>>> On Wed, Sep 2, 2015 at 7:34 PM, Anders Ro
>>>> <anders.ronnbrant@gmail.com> wrote:
>>>>> git-submodule.sh: pin submodule when branch name is '@'
>>>>>
>>>>> Setting branch name to '@' for a submodule will disable 'git submodule
>>>>> update --remote' calls for that specific submodule. I.e. instead of
>>>>> follow the unspecified default choice of master, nothing is being
>>>>> updated. This is useful when multiple submodules exist but not all
>>>>> should follow the remote branch head.
>>>>
>>>> With the disclaimer that I'm not a submodule user (to which the
>>>> answer might be obvious): What benefit is there in using a magic
>>>> value like this ("@") over, say, an explicit configuration setting?
>>>
>>>  From what I have understood (not a submodule expert yet) the '@' is an
>>> invalid branch name and should therefore not collide with any current
>>> branches. My idea was to disable the '--remote' option when the user
>>> have explicitly set an invalid branch name to not modify any current
>>> behaviour. Though having an explicit option is of course more
>>> clarifying. The current behaviour though is that empty branch name means
>>> "follow master" which is somewhat unintuitive.
>>
>> My concern in asking was that some future person might come up with
>> another scenario which also wants to use a "magic value" and would
>> have to invent / arrive at another "illegal" representation. Hence, an
>> explicit setting might be more appropriate. However, as stated, I
>> don't even use submodules, so I may be far off the mark. I've cc'd a
>> few of the submodule maintainers with the hope that they will chime
>> in.

Agree this is not a "future proof" solution. Though faily a quick one. I
started with a setting but realized it involved a bit more changes since
you should be able to tell the submodule command to pin a submodule
right from the start etc.

> 
> Added Trevor to the CC, who is the original author of --remote (see
> 06b1abb5b).
> 
> While I believe that adding such functionality makes perfect sense,
> I do not find it terribly obvious that setting the branch to '@' will
> make --remote skip this submodule. I wouldn't care so much if we'd
> only use this value internally, but this is user visible (and has to
> be set by the user if she wants to skip a submodule in --remote).
> 
> Setting the branch to an empty value feels a bit more natural, but
> I'm not so sure our config handling supports that well (we seem to
> assume in quite some places that empty equals unset). So I tend to
> prefer a new option for that.

I started out that way, thinking that would solve my initial problem of
having 4 submodules which should follow branch 'develop' and one
submodule that should stay put until explicitly changed. Instead having
empty an branch name gave me 'master' on that module, which was way off
current status of the code to say the least. This was all executed by
Jenkins which either gives you "update remote branches" or "not update
remote branches". Thus no other choice than to change the code.

The current 'git submodule add' takes option '-b' as branch and last
time I tried providing '@' as branch name it did not work. That
indicates that there should be a '-p' option for pinning the submodule
from the start. Having to fiddle with the .gitmodules file after the
fact is not really user friendly (though it have worked for me for a
while). I will have a go at an explicit setting in a week or two and get
back for comments on that. Perhaps some maintainers can give some hints
on adding a new option etc meanwhile. How about option '-p, ---pinned'
and setting 'submodule.<branch>.pinned = true|false'?

Cleaned-up the test code according to Eric's comments, looks a bit more
stylish actually :).

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

* Re: [PATCH/RFC] Pinning of submodules
  2015-09-07 20:13         ` Jens Lehmann
  2015-09-07 23:27           ` Anders Ro
@ 2015-09-08 16:55           ` Junio C Hamano
  1 sibling, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2015-09-08 16:55 UTC (permalink / raw)
  To: Jens Lehmann
  Cc: Eric Sunshine, Anders Ro, Git List, Heiko Voigt, Johan Herland,
	Mark Levedahl, W. Trevor King

Jens Lehmann <Jens.Lehmann@web.de> writes:

> Am 07.09.2015 um 01:43 schrieb Eric Sunshine:
>
>> My concern in asking was that some future person might come up with
>> another scenario which also wants to use a "magic value" and would
>> have to invent / arrive at another "illegal" representation. Hence, an
>> explicit setting might be more appropriate. However, as stated, I
>> don't even use submodules, so I may be far off the mark. I've cc'd a
>> few of the submodule maintainers with the hope that they will chime
>> in.
>
> Added Trevor to the CC, who is the original author of --remote (see
> 06b1abb5b).
>
> While I believe that adding such functionality makes perfect sense,
> I do not find it terribly obvious that setting the branch to '@' will
> make --remote skip this submodule. I wouldn't care so much if we'd
> only use this value internally, but this is user visible (and has to
> be set by the user if she wants to skip a submodule in --remote).
>
> Setting the branch to an empty value feels a bit more natural, but
> I'm not so sure our config handling supports that well (we seem to
> assume in quite some places that empty equals unset). So I tend to
> prefer a new option for that.

As I stare at both the code change and log message of 06b1abb5
(submodule update: add --remote for submodule's upstream changes,
2012-12-19), I cannot shake this feeling that the change to default
submodule.$name.branch to 'master' is doubly misdesigned.

The stated goal of users of --remote is to declare "This submodule
does not care what the top-level integrator happened to have seen at
the tip when the integration of the history of submodule.  It always
follows the tip of a specific branch at the upstream."

If we were to use any default, the only justification would be "the
users of --remote would want this mode of update to happen for all
submodules, and having to specify which specific branch to be
followed is too cumbersome".  But if that is the case, defaulting to
'master' does not make any sense---if it defaulted to 'HEAD' for
each submodule, it may have made some sense, as that is the usual
convention to denote which branch is the default branch in a
repository.

Also Anders' proposal refutes that "when --remote is used, all
submodules should behave that way" assumption.

I wonder if it is a sensible way forward to introduce a new
configuration variable 'submodule.remoteFallBackBranch' so that the
users can customize this line (near l.800 in git-submodule.sh)

     branch=$(get_submodule_config "$name" branch master)

The possible values for that new configuration value would be:

   - an empty string: disable "update --remote" for any submodule
     '$name' for which submodule.$name.branch is not set.

   - 'master': behave the same way as the current code; we can make
     this the default, when submodule.remoteFallBackBranch is unset,
     to ease transition.

   - any user-chosen branch name. On notable example may be 'HEAD',
     which 06b1abb5 (submodule update: add --remote for submodule's
     upstream changes, 2012-12-19) should have chosen as the
     default.

But I am not the target audience of "update --remote", so let's hear
what the real-world use cases are.

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

end of thread, other threads:[~2015-09-08 16:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <55E78522.1030107@gmail.com>
2015-09-02 23:34 ` [PATCH/RFC] Pinning of submodules Anders Ro
2015-09-04  5:02   ` Eric Sunshine
2015-09-06 22:08     ` Anders Ro
2015-09-06 23:43       ` Eric Sunshine
2015-09-07 20:13         ` Jens Lehmann
2015-09-07 23:27           ` Anders Ro
2015-09-08 16:55           ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.