Merge branch 'js/bs-is-a-dir-sep-on-windows' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 5 Jun 2017 00:03:15 +0000 (09:03 +0900)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Jun 2017 00:03:15 +0000 (09:03 +0900)
"foo\bar\baz" in "git fetch foo\bar\baz", even though there is no
slashes in it, cannot be a nickname for a remote on Windows, as
that is likely to be a pathname on a local filesystem.

* js/bs-is-a-dir-sep-on-windows:
Windows: do not treat a path with backslashes as a remote's nick name
mingw.h: permit arguments with side effects for is_dir_sep

1  2 
compat/mingw.h
remote.c
diff --combined compat/mingw.h
index 33501695550accdb08368aa867b9addb25c90d5f,d2168c1e5eeecb4f680881486288829aaba2fa5d..e03aecfe2e6556e1ef513922104557373eaa9260
@@@ -384,9 -384,6 +384,9 @@@ int mingw_raise(int sig)
   * ANSI emulation wrappers
   */
  
 +int winansi_isatty(int fd);
 +#define isatty winansi_isatty
 +
  void winansi_init(void);
  HANDLE winansi_get_osfhandle(int fd);
  
        (isalpha(*(path)) && (path)[1] == ':' ? 2 : 0)
  int mingw_skip_dos_drive_prefix(char **path);
  #define skip_dos_drive_prefix mingw_skip_dos_drive_prefix
- #define is_dir_sep(c) ((c) == '/' || (c) == '\\')
+ static inline int mingw_is_dir_sep(int c)
+ {
+       return c == '/' || c == '\\';
+ }
+ #define is_dir_sep mingw_is_dir_sep
  static inline char *mingw_find_last_dir_sep(const char *path)
  {
        char *ret = NULL;
diff --combined remote.c
index 72b4591b98363a83693db82d670a16f05c1e2192,1949882c10a05a1f53b711f6cd3f3e083ca27393..32f137e96643b04ed70693b6d4367ea7618904c4
+++ b/remote.c
@@@ -255,7 -255,6 +255,7 @@@ static void read_remotes_file(struct re
  
        if (!f)
                return;
 +      remote->configured_in_repo = 1;
        remote->origin = REMOTE_REMOTES;
        while (strbuf_getline(&buf, f) != EOF) {
                const char *v;
@@@ -290,7 -289,6 +290,7 @@@ static void read_branches_file(struct r
                return;
        }
  
 +      remote->configured_in_repo = 1;
        remote->origin = REMOTE_BRANCHES;
  
        /*
@@@ -373,8 -371,6 +373,8 @@@ static int handle_config(const char *ke
        }
        remote = make_remote(name, namelen);
        remote->origin = REMOTE_CONFIG;
 +      if (current_config_scope() == CONFIG_SCOPE_REPO)
 +              remote->configured_in_repo = 1;
        if (!strcmp(subkey, "mirror"))
                remote->mirror = git_config_bool(key, value);
        else if (!strcmp(subkey, "skipdefaultupdate"))
@@@ -630,7 -626,7 +630,7 @@@ struct refspec *parse_fetch_refspec(in
        return parse_refspec_internal(nr_refspec, refspec, 1, 0);
  }
  
 -static struct refspec *parse_push_refspec(int nr_refspec, const char **refspec)
 +struct refspec *parse_push_refspec(int nr_refspec, const char **refspec)
  {
        return parse_refspec_internal(nr_refspec, refspec, 0, 0);
  }
@@@ -649,7 -645,12 +649,12 @@@ static int valid_remote_nick(const cha
  {
        if (!name[0] || is_dot_or_dotdot(name))
                return 0;
-       return !strchr(name, '/'); /* no slash */
+       /* remote nicknames cannot contain slashes */
+       while (*name)
+               if (is_dir_sep(*name++))
+                       return 0;
+       return 1;
  }
  
  const char *remote_for_branch(struct branch *branch, int *explicit)
@@@ -693,7 -694,7 +698,7 @@@ static struct remote *remote_get_1(cons
                name = get_default(current_branch, &name_given);
  
        ret = make_remote(name, 0);
 -      if (valid_remote_nick(name)) {
 +      if (valid_remote_nick(name) && have_git_dir()) {
                if (!valid_remote(ret))
                        read_remotes_file(ret);
                if (!valid_remote(ret))
@@@ -718,13 -719,9 +723,13 @@@ struct remote *pushremote_get(const cha
        return remote_get_1(name, pushremote_for_branch);
  }
  
 -int remote_is_configured(struct remote *remote)
 +int remote_is_configured(struct remote *remote, int in_repo)
  {
 -      return remote && remote->origin;
 +      if (!remote)
 +              return 0;
 +      if (in_repo)
 +              return remote->configured_in_repo;
 +      return !!remote->origin;
  }
  
  int for_each_remote(each_remote_fn fn, void *priv)
@@@ -1191,10 -1188,9 +1196,10 @@@ static int match_explicit(struct ref *s
                else if (is_null_oid(&matched_src->new_oid))
                        error("unable to delete '%s': remote ref does not exist",
                              dst_value);
 -              else if ((dst_guess = guess_ref(dst_value, matched_src)))
 +              else if ((dst_guess = guess_ref(dst_value, matched_src))) {
                        matched_dst = make_linked_ref(dst_guess, dst_tail);
 -              else
 +                      free(dst_guess);
 +              } else
                        error("unable to push to unqualified destination: %s\n"
                              "The destination refspec neither matches an "
                              "existing ref on the remote nor\n"
@@@ -1725,6 -1721,9 +1730,6 @@@ static const char *branch_get_push_1(st
  {
        struct remote *remote;
  
 -      if (!branch)
 -              return error_buf(err, _("HEAD does not point to a branch"));
 -
        remote = remote_get(pushremote_for_branch(branch, NULL));
        if (!remote)
                return error_buf(err,
  
  const char *branch_get_push(struct branch *branch, struct strbuf *err)
  {
 +      if (!branch)
 +              return error_buf(err, _("HEAD does not point to a branch"));
 +
        if (!branch->push_tracking_ref)
                branch->push_tracking_ref = branch_get_push_1(branch, err);
        return branch->push_tracking_ref;
@@@ -2280,7 -2276,7 +2285,7 @@@ static struct push_cas *add_cas_entry(s
        return entry;
  }
  
 -int parse_push_cas_option(struct push_cas_option *cas, const char *arg, int unset)
 +static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, int unset)
  {
        const char *colon;
        struct push_cas *entry;