checkout: allow dwim for branch creation for "git checkout $branch --"
[gitweb.git] / wrapper.c
index b40c7e73daa239ee3b78b35875b46e57c40e8ede..dd7ecbb115edd979f657e2e209126d364e6ccfac 100644 (file)
--- a/wrapper.c
+++ b/wrapper.c
@@ -229,7 +229,7 @@ int xmkstemp(char *template)
                int saved_errno = errno;
                const char *nonrelative_template;
 
-               if (!template[0])
+               if (strlen(template) != strlen(origtemplate))
                        template = origtemplate;
 
                nonrelative_template = absolute_path(template);
@@ -403,11 +403,30 @@ int remove_or_warn(unsigned int mode, const char *file)
        return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file);
 }
 
-int access_or_warn(const char *path, int mode)
+void warn_on_inaccessible(const char *path)
+{
+       warning(_("unable to access '%s': %s"), path, strerror(errno));
+}
+
+static int access_error_is_ok(int err, unsigned flag)
+{
+       return err == ENOENT || err == ENOTDIR ||
+               ((flag & ACCESS_EACCES_OK) && err == EACCES);
+}
+
+int access_or_warn(const char *path, int mode, unsigned flag)
+{
+       int ret = access(path, mode);
+       if (ret && !access_error_is_ok(errno, flag))
+               warn_on_inaccessible(path);
+       return ret;
+}
+
+int access_or_die(const char *path, int mode, unsigned flag)
 {
        int ret = access(path, mode);
-       if (ret && errno != ENOENT)
-               warning(_("unable to access '%s': %s"), path, strerror(errno));
+       if (ret && !access_error_is_ok(errno, flag))
+               die_errno(_("unable to access '%s'"), path);
        return ret;
 }