[PATCH v2] fetch: make --prune configurable

2013-07-13 Thread Michael Schubert
Without git fetch --prune, remote-tracking branches for a branch
the other side already has removed will stay forever.  Some people
want to always run git fetch --prune.

To accommodate users who want to either prune always or when fetching
from a particular remote, add two new configuration variables
fetch.prune and remote.name.prune:

 - fetch.prune allows to enable prune for all fetch operations.

 - remote.name.prune allows to change the behaviour per remote.

The latter will naturally override the former, and the --[no-]prune
option from the command line will override the configured default.

Since --prune is a potentially destructive operation (Git doesn't
keep reflogs for deleted references yet), we don't want to prune
without users consent, so this configuration will not be on by
default.

Helped-by: Junio C Hamano gits...@pobox.com
Signed-off-by: Michael Schubert msc...@elegosoft.com
Signed-off-by: Junio C Hamano gits...@pobox.com
---

Junio, thank you for your detailed feedback and writing the patch.

I didn't find time during the week to write a v2 and I don't feel I
should take any credit here, so please feel free to take authorship
completely.

Thanks.


 Documentation/config.txt | 10 ++
 builtin/fetch.c  | 39 ---
 remote.c |  3 ++
 remote.h |  1 +
 t/t5510-fetch.sh | 82 
 5 files changed, 130 insertions(+), 5 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 6e53fc5..e4ce7c4 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1049,6 +1049,10 @@ fetch.unpackLimit::
especially on slow filesystems.  If not set, the value of
`transfer.unpackLimit` is used instead.
 
+fetch.prune::
+   If true, fetch will automatically behave as if the `--prune`
+   option was given on the command line.  See also `remote.name.prune`.
+
 format.attach::
Enable multipart/mixed attachments as the default for
'format-patch'.  The value can also be a double quoted string
@@ -1984,6 +1988,12 @@ remote.name.vcs::
Setting this to a value vcs will cause Git to interact with
the remote with the git-remote-vcs helper.
 
+remote.name.prune::
+   When set to true, fetching from this remote by default will also
+   remove any remote-tracking branches which no longer exist on the
+   remote (as if the `--prune` option was give on the command line).
+   Overrides `fetch.prune` settings, if any.
+
 remotes.group::
The list of remotes which are fetched by git remote update
group.  See linkgit:git-remote[1].
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 4b6b1df..08ab948 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -30,7 +30,11 @@ enum {
TAGS_SET = 2
 };
 
-static int all, append, dry_run, force, keep, multiple, prune, update_head_ok, 
verbosity;
+static int fetch_prune_config = -1; /* unspecified */
+static int prune = -1; /* unspecified */
+#define PRUNE_BY_DEFAULT 0 /* do we prune by default? */
+
+static int all, append, dry_run, force, keep, multiple, update_head_ok, 
verbosity;
 static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
 static int tags = TAGS_DEFAULT, unshallow;
 static const char *depth;
@@ -54,6 +58,15 @@ static int option_parse_recurse_submodules(const struct 
option *opt,
return 0;
 }
 
+static int git_fetch_config(const char *k, const char *v, void *cb)
+{
+   if (!strcmp(k, fetch.prune)) {
+   fetch_prune_config = git_config_bool(k, v);
+   return 0;
+   }
+   return 0;
+}
+
 static struct option builtin_fetch_options[] = {
OPT__VERBOSITY(verbosity),
OPT_BOOLEAN(0, all, all,
@@ -69,8 +82,8 @@ static struct option builtin_fetch_options[] = {
N_(fetch all tags and associated objects), TAGS_SET),
OPT_SET_INT('n', NULL, tags,
N_(do not fetch all tags (--no-tags)), TAGS_UNSET),
-   OPT_BOOLEAN('p', prune, prune,
-   N_(prune remote-tracking branches no longer on remote)),
+   OPT_BOOL('p', prune, prune,
+N_(prune remote-tracking branches no longer on remote)),
{ OPTION_CALLBACK, 0, recurse-submodules, NULL, N_(on-demand),
N_(control recursive fetching of submodules),
PARSE_OPT_OPTARG, option_parse_recurse_submodules },
@@ -739,7 +752,10 @@ static int do_fetch(struct transport *transport,
return 1;
}
if (prune) {
-   /* If --tags was specified, pretend the user gave us the 
canonical tags refspec */
+   /*
+* If --tags was specified, pretend that the user gave us
+* the canonical tags refspec
+*/
if (tags == TAGS_SET) {
const char *tags_str = refs/tags/*:refs/tags

[RFC/PATCH] fetch: make --prune configurable

2013-07-08 Thread Michael Schubert
$gmane/201715 brought up the idea to fetch --prune by default.
Since --prune is a potentially destructive operation (Git doesn't
keep reflogs for deleted references yet), we don't want to prune
without users consent.

To accommodate users who want to either prune always or when fetching
from a particular remote, add two new configuration variables
fetch.prune and remote.name.prune:

 - fetch.prune allows to enable prune for all fetch operations.

 - remote.name.prune allows to change the behaviour per remote.

Signed-off-by: Michael Schubert msc...@elegosoft.com
---

http://thread.gmane.org/gmane.comp.version-control.git/201715


 Documentation/config.txt |  9 +
 builtin/fetch.c  | 28 +---
 remote.c |  2 ++
 remote.h |  1 +
 t/t5510-fetch.sh | 38 ++
 5 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index b4d4887..74e8026 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1067,6 +1067,10 @@ fetch.unpackLimit::
especially on slow filesystems.  If not set, the value of
`transfer.unpackLimit` is used instead.
 
+fetch.prune::
+   If true, fetch will automatically behave as if the `--prune`
+   option was given on the command line.
+
 format.attach::
Enable multipart/mixed attachments as the default for
'format-patch'.  The value can also be a double quoted string
@@ -2010,6 +2014,11 @@ remote.name.vcs::
Setting this to a value vcs will cause Git to interact with
the remote with the git-remote-vcs helper.
 
+remote.name.prune::
+   When set to true, fetching from this remote by default will also
+   remove any remote-tracking branches which no longer exist on the
+   remote (as if the `--prune` option was give on the command line).
+
 remotes.group::
The list of remotes which are fetched by git remote update
group.  See linkgit:git-remote[1].
diff --git a/builtin/fetch.c b/builtin/fetch.c
index d784b2e..3953317 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -30,7 +30,14 @@ enum {
TAGS_SET = 2
 };
 
-static int all, append, dry_run, force, keep, multiple, prune, update_head_ok, 
verbosity;
+enum {
+   PRUNE_UNSET = 0,
+   PRUNE_DEFAULT = 1,
+   PRUNE_FORCE = 2
+};
+
+static int prune = PRUNE_DEFAULT;
+static int all, append, dry_run, force, keep, multiple, update_head_ok, 
verbosity;
 static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
 static int tags = TAGS_DEFAULT, unshallow;
 static const char *depth;
@@ -54,6 +61,17 @@ static int option_parse_recurse_submodules(const struct 
option *opt,
return 0;
 }
 
+static int git_fetch_config(const char *k, const char *v, void *cb)
+{
+   if (!strcmp(k, fetch.prune)) {
+   int boolval = git_config_bool(k, v);
+   if (boolval)
+   prune = PRUNE_FORCE;
+   return 0;
+   }
+   return git_default_config(k, v, cb);
+}
+
 static struct option builtin_fetch_options[] = {
OPT__VERBOSITY(verbosity),
OPT_BOOLEAN(0, all, all,
@@ -770,7 +788,7 @@ static int do_fetch(struct transport *transport,
retcode = 1;
goto cleanup;
}
-   if (prune) {
+   if (prune == PRUNE_FORCE || (transport-remote-prune  prune)) {
/* If --tags was specified, pretend the user gave us the 
canonical tags refspec */
if (tags == TAGS_SET) {
const char *tags_str = refs/tags/*:refs/tags/*;
@@ -882,8 +900,10 @@ static void add_options_to_argv(struct argv_array *argv)
 {
if (dry_run)
argv_array_push(argv, --dry-run);
-   if (prune)
+   if (prune == PRUNE_FORCE)
argv_array_push(argv, --prune);
+   else if (prune == PRUNE_UNSET)
+   argv_array_push(argv, --no-prune);
if (update_head_ok)
argv_array_push(argv, --update-head-ok);
if (force)
@@ -1007,6 +1027,8 @@ int cmd_fetch(int argc, const char **argv, const char 
*prefix)
for (i = 1; i  argc; i++)
strbuf_addf(default_rla,  %s, argv[i]);
 
+   git_config(git_fetch_config, NULL);
+
argc = parse_options(argc, argv, prefix,
 builtin_fetch_options, builtin_fetch_usage, 0);
 
diff --git a/remote.c b/remote.c
index 6f57830..e6f2acb 100644
--- a/remote.c
+++ b/remote.c
@@ -404,6 +404,8 @@ static int handle_config(const char *key, const char 
*value, void *cb)
remote-skip_default_update = git_config_bool(key, value);
else if (!strcmp(subkey, .skipfetchall))
remote-skip_default_update = git_config_bool(key, value);
+   else if (!strcmp(subkey, .prune))
+   remote-prune = git_config_bool(key, value);
else if (!strcmp(subkey, .url

Re: [PATCH] Change remote tracking to remote-tracking

2013-07-04 Thread Michael Schubert
On Wed, Jul 03, 2013 at 11:38:51AM -0700, Jonathan Nieder wrote:
 Michael Schubert wrote:
 
  --- a/Documentation/git-p4.txt
  +++ b/Documentation/git-p4.txt
  @@ -180,7 +180,7 @@ subsequent 'sync' operations.
  Import changes into given branch.  If the branch starts with
  'refs/', it will be used as is.  Otherwise if it does not start
  with 'p4/', that prefix is added.  The branch is assumed to
  -   name a remote tracking, but this can be modified using
  +   name a remote-tracking, but this can be modified using
  '--import-local', or by giving a full ref name.  The default
  branch is 'master'.
 
 This is confusing both before and after the patch.  What is a remote
 tracking?
 
 Perhaps:
 
   --branch ref::
   Import changes into ref instead of refs/remotes/p4/master.
   If ref starts with refs/, it is used as is.  Otherwise, if
   it does not start with p4/, that prefix is added.
   +
   By default a ref not starting with refs/ is treated as the
   name of a remote-tracking branch (under refs/remotes/).  This
   behavior can be modified using the --import-local option.
   +
   The default ref is master.

Thanks.
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Change remote tracking to remote-tracking

2013-07-03 Thread Michael Schubert
Fix a typo (remote remote-tracking) going back to the big cleanup
in 2010 (8b3f3f84 etc). Also, remove some more occurrences of
tracking and remote tracking in favor of remote-tracking.

Signed-off-by: Michael Schubert msc...@elegosoft.com
---
 Documentation/git-p4.txt   | 2 +-
 Documentation/git-submodule.txt| 2 +-
 Documentation/glossary-content.txt | 4 ++--
 builtin/clone.c| 2 +-
 builtin/merge.c| 4 ++--
 t/t5505-remote.sh  | 2 +-
 6 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/Documentation/git-p4.txt b/Documentation/git-p4.txt
index c579fbc..609c1d2 100644
--- a/Documentation/git-p4.txt
+++ b/Documentation/git-p4.txt
@@ -180,7 +180,7 @@ subsequent 'sync' operations.
Import changes into given branch.  If the branch starts with
'refs/', it will be used as is.  Otherwise if it does not start
with 'p4/', that prefix is added.  The branch is assumed to
-   name a remote tracking, but this can be modified using
+   name a remote-tracking, but this can be modified using
'--import-local', or by giving a full ref name.  The default
branch is 'master'.
 +
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index e576713..bfff090 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -262,7 +262,7 @@ OPTIONS
 --remote::
This option is only valid for the update command.  Instead of using
the superproject's recorded SHA-1 to update the submodule, use the
-   status of the submodule's remote tracking branch.  The remote used
+   status of the submodule's remote-tracking branch.  The remote used
is branch's remote (`branch.name.remote`), defaulting to `origin`.
The remote branch used defaults to `master`, but the branch name may
be overridden by setting the `submodule.name.branch` option in
diff --git a/Documentation/glossary-content.txt 
b/Documentation/glossary-content.txt
index db2a74d..dba5062 100644
--- a/Documentation/glossary-content.txt
+++ b/Documentation/glossary-content.txt
@@ -113,7 +113,7 @@ Note that commands that operate on the history of the 
current branch
 while the HEAD is detached. They update the HEAD to point at the tip
 of the updated history without affecting any branch.  Commands that
 update or inquire information _about_ the current branch (e.g. `git
-branch --set-upstream-to` that sets what remote tracking branch the
+branch --set-upstream-to` that sets what remote-tracking branch the
 current branch integrates with) obviously do not work, as there is no
 (real) current branch to ask about in this state.
 
@@ -267,7 +267,7 @@ This commit is referred to as a merge commit, or 
sometimes just a
The default upstream def_repository,repository. Most projects have
at least one upstream project which they track. By default
'origin' is used for that purpose. New upstream updates
-   will be fetched into remote 
def_remote_tracking_branch,remote-tracking branches named
+   will be fetched into def_remote_tracking_branch,remote-tracking 
branches named
origin/name-of-upstream-branch, which you can see using
`git branch -r`.
 
diff --git a/builtin/clone.c b/builtin/clone.c
index 14b1323..17f57cd 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -701,7 +701,7 @@ static void write_refspec_config(const char* src_ref_prefix,
/*
 * otherwise, the next git fetch will
 * simply fetch from HEAD without updating
-* any remote tracking branch, which is what
+* any remote-tracking branch, which is what
 * we want.
 */
} else {
diff --git a/builtin/merge.c b/builtin/merge.c
index 2ebe732..bad4536 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -948,7 +948,7 @@ static int evaluate_result(void)
 }
 
 /*
- * Pretend as if the user told us to merge with the tracking
+ * Pretend as if the user told us to merge with the remote-tracking
  * branch we have for the upstream of the current branch
  */
 static int setup_with_upstream(const char ***argv)
@@ -967,7 +967,7 @@ static int setup_with_upstream(const char ***argv)
args = xcalloc(branch-merge_nr + 1, sizeof(char *));
for (i = 0; i  branch-merge_nr; i++) {
if (!branch-merge[i]-dst)
-   die(_(No remote tracking branch for %s from %s),
+   die(_(No remote-tracking branch for %s from %s),
branch-merge[i]-src, branch-remote_name);
args[i] = branch-merge[i]-dst;
}
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index ee5d65d..8f6e392 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -74,7 +74,7 @@ test_expect_success 'add another remote

Re: Google Summer of Code 2013 (GSoC13)

2013-02-20 Thread Michael Schubert
On 02/18/2013 06:42 PM, Jeff King wrote:
 
 I will do it again, if people feel strongly about Git being a part of
 it. However, I have gotten a little soured on the GSoC experience. Not
 because of anything Google has done; it's a good idea, and I think they
 do a fine of administering the program. But I have noticed that the work
 that comes out of GSoC the last few years has quite often not been
 merged, or not made a big impact in the codebase, and nor have the
 participants necessarily stuck around.
 
 And I do not want to blame the students here (some of whom are on the cc
 list :) ). They are certainly under no obligation to stick around after
 GSoC ends, and I know they have many demands on their time. But I am
 also thinking about what Git wants to get out of GSoC (and to my mind,
 the most important thing is contributors).

Speaking of libgit2:

Git provided the libgit2 project with a slot each of the last three GSOC.
The contributions made by the former students (Disclaimer: one of them
speaking) have been quite important for libgit2 and all three students
are still involved. Each project was an important push towards building
a new, feature complete Git library.

Thank you!

http://libgit2.github.com
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Proposal: branch.name.remotepush

2013-02-07 Thread Michael Schubert
On 02/07/2013 05:14 PM, Ramkumar Ramachandra wrote:

 This has been annoying me for a really long time, but I never really
 got around to scratching this particular itch.  I have a very common
 scenario where I fork a project on GitHub.  I have two configured
 remotes: origin which points to git://upstream and mine which points
 to ssh://mine.  By default, I always want to pull `master` from
 origin and push to mine.  Unfortunately, there's only a
 branch.name.remote which specifies which remote to use for both
 pulling and pushing.  There's also a remote.name.pushurl, but I get
 the feeling that this exists for an entirely different reason: when I
 have a server with a highly-available read-only mirror of the
 repository at git://anongit.*, and a less-available committer-only
 mirror at ssh://*.
 
 How about a branch.name.remotepush that specifies a special remote
 for pushing, falling back to branch.name.remote?

Additionally, it would be nice to have branch.name.push or similar
to configure a default destination branch for push. Gerrit users usually
want to track refs/heads/master but push to refs/for/master for example.





--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Verify Content-Type from smart HTTP servers

2013-02-06 Thread Michael Schubert
On 01/31/2013 11:09 PM, Junio C Hamano wrote:

  
 -static int http_request_reauth(const char *url, void *result, int target,
 +static int http_request_reauth(const char *url,
 +struct strbuf *type,
 +void *result, int target,
  int options)
  {
 - int ret = http_request(url, result, target, options);
 + int ret = http_request(url, type, result, target, options);
   if (ret != HTTP_REAUTH)
   return ret;
 - return http_request(url, result, target, options);
 + return http_request(url, type, result, target, options);
  }

This needs something like

diff --git a/http.c b/http.c
index d868d8b..da43be3 100644
--- a/http.c
+++ b/http.c
@@ -860,6 +860,8 @@ static int http_request_reauth(const char *url,
int ret = http_request(url, type, result, target, options);
if (ret != HTTP_REAUTH)
return ret;
+   if (type)
+   strbuf_reset(type);
return http_request(url, type, result, target, options);
 }

on top. Otherwise we get

text/plainapplication/x-git-receive-pack-advertisement

when doing HTTP auth.

Thanks.

 -int http_get_strbuf(const char *url, struct strbuf *result, int options)
 +int http_get_strbuf(const char *url,
 + struct strbuf *type,
 + struct strbuf *result, int options)
  {
 - return http_request_reauth(url, result, HTTP_REQUEST_STRBUF, options);
 + return http_request_reauth(url, type, result,
 +HTTP_REQUEST_STRBUF, options);
  }
  
  /*
 @@ -878,7 +891,7 @@ static int http_get_file(const char *url, const char 
 *filename, int options)
   goto cleanup;
   }
  
 - ret = http_request_reauth(url, result, HTTP_REQUEST_FILE, options);
 + ret = http_request_reauth(url, NULL, result, HTTP_REQUEST_FILE, 
 options);
   fclose(result);
  
   if ((ret == HTTP_OK)  move_temp_to_file(tmpfile.buf, filename))
 @@ -904,7 +917,7 @@ int http_fetch_ref(const char *base, struct ref *ref)
   int ret = -1;
  
   url = quote_ref_url(base, ref-name);
 - if (http_get_strbuf(url, buffer, HTTP_NO_CACHE) == HTTP_OK) {
 + if (http_get_strbuf(url, NULL, buffer, HTTP_NO_CACHE) == HTTP_OK) {
   strbuf_rtrim(buffer);
   if (buffer.len == 40)
   ret = get_sha1_hex(buffer.buf, ref-old_sha1);
 @@ -997,7 +1010,7 @@ int http_get_info_packs(const char *base_url, struct 
 packed_git **packs_head)
   strbuf_addstr(buf, objects/info/packs);
   url = strbuf_detach(buf, NULL);
  
 - ret = http_get_strbuf(url, buf, HTTP_NO_CACHE);
 + ret = http_get_strbuf(url, NULL, buf, HTTP_NO_CACHE);
   if (ret != HTTP_OK)
   goto cleanup;
  
 diff --git a/http.h b/http.h
 index 0a80d30..25d1931 100644
 --- a/http.h
 +++ b/http.h
 @@ -132,7 +132,7 @@ extern char *get_remote_object_url(const char *url, const 
 char *hex,
   *
   * If the result pointer is NULL, a HTTP HEAD request is made instead of GET.
   */
 -int http_get_strbuf(const char *url, struct strbuf *result, int options);
 +int http_get_strbuf(const char *url, struct strbuf *content_type, struct 
 strbuf *result, int options);
  
  /*
   * Prints an error message using error() containing url and curl_errorstr,
 diff --git a/remote-curl.c b/remote-curl.c
 index 9a8b123..e6f3b63 100644
 --- a/remote-curl.c
 +++ b/remote-curl.c
 @@ -92,6 +92,8 @@ static void free_discovery(struct discovery *d)
  
  static struct discovery* discover_refs(const char *service)
  {
 + struct strbuf exp = STRBUF_INIT;
 + struct strbuf type = STRBUF_INIT;
   struct strbuf buffer = STRBUF_INIT;
   struct discovery *last = last_discovery;
   char *refs_url;
 @@ -113,7 +115,7 @@ static struct discovery* discover_refs(const char 
 *service)
   }
   refs_url = strbuf_detach(buffer, NULL);
  
 - http_ret = http_get_strbuf(refs_url, buffer, HTTP_NO_CACHE);
 + http_ret = http_get_strbuf(refs_url, type, buffer, HTTP_NO_CACHE);
   switch (http_ret) {
   case HTTP_OK:
   break;
 @@ -133,16 +135,19 @@ static struct discovery* discover_refs(const char 
 *service)
   last-buf = last-buf_alloc;
  
   if (maybe_smart  5 = last-len  last-buf[4] == '#') {
 - /* smart HTTP response; validate that the service
 + /*
 +  * smart HTTP response; validate that the service
* pkt-line matches our request.
*/
 - struct strbuf exp = STRBUF_INIT;
 -
 + strbuf_addf(exp, application/x-%s-advertisement, service);
 + if (strbuf_cmp(exp, type))
 + die(invalid content-type %s, type.buf);
   if (packet_get_line(buffer, last-buf, last-len) = 0)
   die(%s has invalid packet header, refs_url);
   if (buffer.len  buffer.buf[buffer.len - 1] == '\n')
   

[PATCH] git-subtree: ignore git-subtree executable

2012-12-22 Thread Michael Schubert
Signed-off-by: Michael Schubert msc...@elegosoft.com
---
 contrib/subtree/.gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/subtree/.gitignore b/contrib/subtree/.gitignore
index 7e77c9d..91360a3 100644
--- a/contrib/subtree/.gitignore
+++ b/contrib/subtree/.gitignore
@@ -1,4 +1,5 @@
 *~
+git-subtree
 git-subtree.xml
 git-subtree.1
 mainline
-- 
1.8.1.rc2.333.g912e06f.dirty
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] git-subtree: fix typo in manpage

2012-12-22 Thread Michael Schubert
Signed-off-by: Michael Schubert msc...@elegosoft.com
---
 contrib/subtree/git-subtree.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/subtree/git-subtree.txt b/contrib/subtree/git-subtree.txt
index 0c44fda..c5bce41 100644
--- a/contrib/subtree/git-subtree.txt
+++ b/contrib/subtree/git-subtree.txt
@@ -93,7 +93,7 @@ pull::
repository.

 push::
-   Does a 'split' (see above) using the prefix supplied
+   Does a 'split' (see below) using the prefix supplied
and then does a 'git push' to push the result to the 
repository and refspec. This can be used to push your
subtree to different branches of the remote repository.
-- 
1.8.1.rc2.333.g912e06f.dirty
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] refname format cleanup

2012-07-16 Thread Michael Schubert
Previous discussion:

 http://thread.gmane.org/gmane.comp.version-control.git/200129/focus=200146

I'm not sure if I've drawn the right conclusions from the previous
thread, so please let me know in case that's the wrong way to go..

 * refs: disallow ref components starting with hyphen
 * symbolic-ref: check format of given refname

 builtin/symbolic-ref.c  |  4 +++-
 builtin/tag.c   |  3 ---
 refs.c  |  2 ++
 sha1_name.c |  2 --
 t/t1401-symbolic-ref.sh | 10 ++
 5 files changed, 15 insertions(+), 6 deletions(-)
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] refs: disallow ref components starting with hyphen

2012-07-16 Thread Michael Schubert
Currently, we allow refname components to start with a hyphen. There's
no good reason to do so and it troubles the parseopt infrastructure.
Explicitly refuse refname components starting with a hyphen inside
check_refname_component().

Revert 63486240, which is obsolete now.

Signed-off-by: Michael Schubert msc...@elegosoft.com
---
 builtin/tag.c | 3 ---
 refs.c| 2 ++
 sha1_name.c   | 2 --
 3 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/builtin/tag.c b/builtin/tag.c
index 7b1be85..c99fb42 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -403,9 +403,6 @@ static int parse_msg_arg(const struct option *opt, const 
char *arg, int unset)
 
 static int strbuf_check_tag_ref(struct strbuf *sb, const char *name)
 {
-   if (name[0] == '-')
-   return -1;
-
strbuf_reset(sb);
strbuf_addf(sb, refs/tags/%s, name);
 
diff --git a/refs.c b/refs.c
index da74a2b..5714681 100644
--- a/refs.c
+++ b/refs.c
@@ -62,6 +62,8 @@ static int check_refname_component(const char *refname, int 
flags)
if (refname[1] == '\0')
return -1; /* Component equals .. */
}
+   if (refname[0] == '-')
+   return -1; /* Component starts with '-'. */
if (cp - refname = 5  !memcmp(cp - 5, .lock, 5))
return -1; /* Refname ends with .lock. */
return cp - refname;
diff --git a/sha1_name.c b/sha1_name.c
index 5d81ea0..132d369 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -892,8 +892,6 @@ int strbuf_branchname(struct strbuf *sb, const char *name)
 int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
 {
strbuf_branchname(sb, name);
-   if (name[0] == '-')
-   return -1;
strbuf_splice(sb, 0, 0, refs/heads/, 11);
return check_refname_format(sb-buf, 0);
 }
-- 
1.7.11.2.196.ga22866b

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] symbolic-ref: check format of given refname

2012-07-16 Thread Michael Schubert
Currently, it's possible to update HEAD with a nonsense reference since
no strict validation ist performed. Example:

$ git symbolic-ref HEAD 'refs/heads/master


 '

Fix this by checking the given reference with check_refname_format().

Signed-off-by: Michael Schubert msc...@elegosoft.com
---
 builtin/symbolic-ref.c  |  4 +++-
 t/t1401-symbolic-ref.sh | 10 ++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 801d62e..a529541 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -44,13 +44,15 @@ int cmd_symbolic_ref(int argc, const char **argv, const 
char *prefix)
git_config(git_default_config, NULL);
argc = parse_options(argc, argv, prefix, options,
 git_symbolic_ref_usage, 0);
-   if (msg !*msg)
+   if (msg  !*msg)
die(Refusing to perform update with empty message);
switch (argc) {
case 1:
check_symref(argv[0], quiet);
break;
case 2:
+   if (check_refname_format(argv[1], 0))
+   die(No valid reference format: '%s', argv[1]);
if (!strcmp(argv[0], HEAD) 
prefixcmp(argv[1], refs/))
die(Refusing to point HEAD outside of refs/);
diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh
index 2c96551..b1cd508 100755
--- a/t/t1401-symbolic-ref.sh
+++ b/t/t1401-symbolic-ref.sh
@@ -27,6 +27,16 @@ test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
 '
 reset_to_sane
 
+test_expect_success 'symbolic-ref refuses ref with leading dot' '
+   test_must_fail git symbolic-ref HEAD refs/heads/.foo
+'
+reset_to_sane
+
+test_expect_success 'symbolic-ref refuses ref with leading dash' '
+   test_must_fail git symbolic-ref HEAD refs/heads/-foo
+'
+reset_to_sane
+
 test_expect_success 'symbolic-ref refuses bare sha1' '
echo content file  git add file  git commit -m one 
test_must_fail git symbolic-ref HEAD `git rev-parse HEAD`
-- 
1.7.11.2.196.ga22866b

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html