git-parse-remote: Support dummy remote `.' in branch.<name>.remote
PATCH 1/1 git-parse-remote: Support dummy remote `.' in branch.<name>.remote
This patch adds support for a dummy remote `.' to avoid having to declare a fake remote like
[remote "local"] url = . fetch = refs/heads/*:refs/heads/*
A configuration variable is provided, "branch.forcelocalupdates", which fakes the fetch line to read "+refs/heads/*:refs/heads/*".
A subsequent patch, which will be submitted after this and the --track/--no-track patch goes in, will add support for the .' remote in git-branch --track'.
It is important to notice that the `.' remote only works in branch.<name>.remote by design.
--- Documentation/config.txt | 10 ++++++++++ git-parse-remote.sh | 15 ++++++++++++++- t/t5520-pull.sh | 13 +++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-)
Andy Parkins wrote:
> I think what you want is something that I would like too. If you specify "." > to a git-pull it means to use the local repository not a remote. It would be > great if one could have:
>
> [remote "origin"]
> url = git://git.kernel.org/pub/scm/git/git.git
> fetch = refs/heads/master:refs/remotes/origin/master
> [branch "master"]
> remote = .
> merge = refs/remotes/origin/master
>
> That way a "git pull" on master wouldn't need to make a remote connection in > order to do a merge (which is the way I like it). However, I remember there > was a reason this wouldn't work, but I don't remember what it was :-)
Documentation/config.txt +10 -0
@@ -272,6 +272,16 @@ branch.<name>.merge:: `git fetch`) to lookup the default branch for merging. Without this option, `git pull` defaults to merge the first refspec fetched. Specify multiple values to get an octopus merge. + If you wish to setup `git pull` so that it merges into <name> from + another branch in the local repository, you can point + branch.<name>.merge to the desired branch, and use the special setting + `.` (a period) for branch.<name>.remote. + +branch.forcelocalupdates:: + If set to true, merges from the local repository (i.e. when + branch.<name>.remote is the special setting `.`) are performed + even if they do not result in a fast forward update. The default + is true. color.branch:: A boolean to enable/disable color in the output of
git-parse-remote.sh +14 -1
@@ -9,6 +9,9 @@ get_data_source () { */*) echo '' ;; + .) + echo builtin + ;; *) if test "$(git-config --get "remote.$1.url")" then
@@ -31,6 +34,9 @@ get_remote_url () { '') echo "$1" ;; + builtin) + echo "$1" + ;; config) git-config --get "remote.$1.url" ;;
@@ -57,7 +63,7 @@ get_default_remote () { get_remote_default_refs_for_push () { data_source=$(get_data_source "$1") case "$data_source" in - '' | branches) + '' | branches | builtin) ;; # no default push mapping, just send matching refs. config) git-config --get-all "remote.$1.push" ;;
@@ -128,6 +134,13 @@ get_remote_default_refs_for_fetch () { case "$data_source" in '') set explicit "HEAD:" ;; + builtin) + if test $(git-config --bool "branch.forcelocalupdates" || echo true) = true + then + set $(expand_refs_wildcard . +refs/heads/*:refs/heads/*) + else + set $(expand_refs_wildcard . refs/heads/*:refs/heads/*) + fi ;; config) set $(expand_refs_wildcard "$1" \ $(git-config --get-all "remote.$1.fetch")) ;;
t/t5520-pull.sh +13 -0
@@ -29,5 +29,18 @@ test_expect_success 'checking the results' ' diff file cloned/file ' +test_expect_success 'test . as a remote' ' + + git branch copy master && + git config branch.copy.remote . && + git config branch.copy.merge refs/heads/master && + echo updated >file && + git commit -a -m updated && + git checkout copy && + test `cat file` = file && + git pull && + test `cat file` = updated +' + test_done
Quoted 6 lines · Paolo Bonzini
This patch adds support for a dummy remote `.' to avoid having to declare a fake remote like
[remote "local"] url = . fetch = refs/heads/*:refs/heads/*
For one thing, I do not think it would help Andy's original example of reusing what we already have in refs/remotes hierarchy if you faked it with refs/heads/*:refs/heads/* wildcard like the above.
Why not
[remote "local"]
url = .
fetch = refs/heads/*or even
[remote "local"]
url = .
fetch = refs/*except that we currently do not have non-storing globbing pattern defined?
I am actually Ok with the idea of built-in ".", but I really do not like it to even pretend storing the fetched results in local branches. If you stop thinking in terms of "tracking fetch" that stores the result in some local branch, you do not have to have branch.forcelocalupdates.
By the way, I do not understand the semantics of that configuration variable at all.
Documentation/config.txt branch.<name>.merge:: · line 284
Quoted 5 lines
Documentation/config.txt +5
-0+branch.forcelocalupdates:: + If set to true, merges from the local repository (i.e. when + branch.<name>.remote is the special setting `.`) are performed + even if they do not result in a fast forward update. The default + is true.
Really, when does fetching from refs/heads/<blah> into refs/heads/<blah> result in anything but "already up-to-date"?
I think you can get rid of this ridiculous "we obtain refs/heads/master from ourselves and store it in the same branch of ours". The only thing you want here is to leave FETCH_HEAD in a state that is usable by git-pull. Wouldn't that be much cleaner?
Quoted 4 lines
git-parse-remote.sh +0
-0@@ -128,6 +134,13 @@ get_remote_default_refs_for_fetch () { case "$data_source" in '') set explicit "HEAD:" ;;
git-parse-remote.sh get_remote_default_refs_for_fetch () { · line 146
Quoted 10 lines
git-parse-remote.sh +7
-0+ builtin) + if test $(git-config --bool "branch.forcelocalupdates" || echo true) = true + then + set $(expand_refs_wildcard . +refs/heads/*:refs/heads/*) + else + set $(expand_refs_wildcard . refs/heads/*:refs/heads/*) + fi ;; config) set $(expand_refs_wildcard "$1" \ $(git-config --get-all "remote.$1.fetch")) ;;
Especially this above hunk is not something I'd like to see so the patch won't be applied as-is in this round, but just for future reference...
The --bool option makes sure the git-config command either says "true", "false" or silently exit with non-zero, in which case you would let echo say "true". In that sense, it is not a problem in this particular patch, but in general it makes me worried when I see somebody feeds $() without quoting to test as its argument.
Quoted 3 lines
By the way, I do not understand the semantics of that configuration variable at all.
I think I seriously misunderstood something -- I cannot even recall what -- when I wrote that. In fact, the only thing I want to work, is the scenario for which I wrote the testcase.
I'll ponder your comments on FETCH_HEAD and see if I can write the patch in a better way.
Paolo