* [PATCH] clone: Warn if LICENSE or COPYING file lacking and !clone.skiplicensecheck
@ 2015-03-22 0:16 David A. Wheeler
2015-03-22 8:23 ` Johannes Sixt
2015-03-22 9:45 ` Duy Nguyen
0 siblings, 2 replies; 3+ messages in thread
From: David A. Wheeler @ 2015-03-22 0:16 UTC (permalink / raw)
To: git
Warn cloners if there is no LICENSE* or COPYING* file that makes
the license clear. This is a useful warning, because if there is
no license somewhere, then local copyright laws (which forbid many uses)
and terms of service apply - and the cloner may not be expecting that.
Many projects accidentally omit a license, so this is common enough to note.
You can disable this warning by setting "clone.skiplicensecheck" to "true".
For more info on the issue, feel free to see:
http://choosealicense.com/no-license/
http://www.wired.com/2013/07/github-licenses/
https://twitter.com/stephenrwalli/status/247597785069789184
Signed-off-by: David A. Wheeler <dwheeler@dwheeler.com>
---
builtin/clone.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/builtin/clone.c b/builtin/clone.c
index 9572467..a3e8584 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -50,6 +50,7 @@ static int option_progress = -1;
static struct string_list option_config;
static struct string_list option_reference;
static int option_dissociate;
+static int skip_license_check;
static int opt_parse_reference(const struct option *opt, const char *arg, int unset)
{
@@ -748,6 +749,44 @@ static void dissociate_from_references(void)
die_errno(_("cannot unlink temporary alternates file"));
}
+static int starts_with_ignore_case(const char *str, const char *prefix)
+{
+ for (; ; str++, prefix++)
+ if (!*prefix)
+ return 1;
+ else if (tolower(*str) != tolower(*prefix))
+ return 0;
+}
+
+static int missing_license(void)
+{
+ DIR *dir = opendir("."); /* Examine current directory for license. */
+ struct dirent *e;
+ struct stat st;
+ int ret = 0;
+
+ if (!dir)
+ return 0; /* Empty directory, no need for license. */
+
+ while ((e = readdir(dir)) != NULL) {
+ if (starts_with_ignore_case(e->d_name, "license") ||
+ starts_with_ignore_case(e->d_name, "copyright")) {
+ if (stat(e->d_name, &st) || st.st_size < 2)
+ continue;
+ ret = 0;
+ break;
+ }
+ if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..") ||
+ !strcmp(e->d_name, ".git"))
+ continue;
+ ret = 1; /* Non-empty directory */
+ }
+
+ closedir(dir);
+ return ret;
+}
+
+
int cmd_clone(int argc, const char **argv, const char *prefix)
{
int is_bundle = 0, is_local;
@@ -1016,6 +1055,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
junk_mode = JUNK_LEAVE_REPO;
err = checkout();
+ git_config_get_bool("clone.skiplicensecheck", &skip_license_check);
+ if (!option_no_checkout && !skip_license_check &&
+ missing_license())
+ warning(_("Repository has no LICENSE or COPYING file with content."));
+
strbuf_release(&reflog_msg);
strbuf_release(&branch_top);
strbuf_release(&key);
--
2.3.3.221.g33aa87e.dirty
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] clone: Warn if LICENSE or COPYING file lacking and !clone.skiplicensecheck
2015-03-22 0:16 [PATCH] clone: Warn if LICENSE or COPYING file lacking and !clone.skiplicensecheck David A. Wheeler
@ 2015-03-22 8:23 ` Johannes Sixt
2015-03-22 9:45 ` Duy Nguyen
1 sibling, 0 replies; 3+ messages in thread
From: Johannes Sixt @ 2015-03-22 8:23 UTC (permalink / raw)
To: dwheeler, git
Am 22.03.2015 um 01:16 schrieb David A. Wheeler:
> Warn cloners if there is no LICENSE* or COPYING* file that makes
> the license clear. This is a useful warning, because if there is
> no license somewhere, then local copyright laws (which forbid many uses)
> and terms of service apply - and the cloner may not be expecting that.
> Many projects accidentally omit a license, so this is common enough to note.
>
> You can disable this warning by setting "clone.skiplicensecheck" to "true".
>
> For more info on the issue, feel free to see:
> http://choosealicense.com/no-license/
> http://www.wired.com/2013/07/github-licenses/
> https://twitter.com/stephenrwalli/status/247597785069789184
>
> Signed-off-by: David A. Wheeler <dwheeler@dwheeler.com>
The opt-out works only when placed in the system-wide or user
configuration. That places a maintenance burden on *ALL* existing
installations that do not want the warning.
If you really want to hard-code such a policy decision into Git, then
make it an opt-in so that members of the license squad can enable it.
I don't need it.
-- Hannes
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] clone: Warn if LICENSE or COPYING file lacking and !clone.skiplicensecheck
2015-03-22 0:16 [PATCH] clone: Warn if LICENSE or COPYING file lacking and !clone.skiplicensecheck David A. Wheeler
2015-03-22 8:23 ` Johannes Sixt
@ 2015-03-22 9:45 ` Duy Nguyen
1 sibling, 0 replies; 3+ messages in thread
From: Duy Nguyen @ 2015-03-22 9:45 UTC (permalink / raw)
To: dwheeler; +Cc: git
On Sun, Mar 22, 2015 at 7:16 AM, David A. Wheeler <dwheeler@dwheeler.com> wrote:
> Warn cloners if there is no LICENSE* or COPYING* file that makes
> the license clear. This is a useful warning, because if there is
> no license somewhere, then local copyright laws (which forbid many uses)
> and terms of service apply - and the cloner may not be expecting that.
> Many projects accidentally omit a license, so this is common enough to note.
>
> You can disable this warning by setting "clone.skiplicensecheck" to "true".
Perhaps make this a hook and maybe install by default on new clones,
e.g. templates/hooks--post-checkout.sample?
--
Duy
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-22 9:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-22 0:16 [PATCH] clone: Warn if LICENSE or COPYING file lacking and !clone.skiplicensecheck David A. Wheeler
2015-03-22 8:23 ` Johannes Sixt
2015-03-22 9:45 ` Duy Nguyen
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.