git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clone: Warn if clone lacks LICENSE or COPYING file
@ 2015-03-21 18:06 David A. Wheeler
  2015-03-21 20:21 ` Dennis Kaarsemaker
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: David A. Wheeler @ 2015-03-21 18:06 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.
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 | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/builtin/clone.c b/builtin/clone.c
index 9572467..9863b04 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -748,6 +748,41 @@ 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 contains_license(void)
+{
+	DIR *dir = opendir("."); /* Examine current directory for license. */
+	struct dirent *e;
+	struct stat st;
+	int ret = 0;
+
+	if (!dir)
+		return 0;
+
+	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))
+				continue;
+			if (st.st_size > 1) {
+				ret = 1;
+				break;
+			}
+		}
+
+	closedir(dir);
+	return ret;
+}
+
+
 int cmd_clone(int argc, const char **argv, const char *prefix)
 {
 	int is_bundle = 0, is_local;
@@ -1016,6 +1051,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 	junk_mode = JUNK_LEAVE_REPO;
 	err = checkout();
 
+	if (!option_no_checkout && !contains_license())
+		warning(_("Repository has no LICENSE or COPYING file with content."));
+
 	strbuf_release(&reflog_msg);
 	strbuf_release(&branch_top);
 	strbuf_release(&key);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-04-03 21:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-21 18:06 [PATCH] clone: Warn if clone lacks LICENSE or COPYING file David A. Wheeler
2015-03-21 20:21 ` Dennis Kaarsemaker
2015-03-22  4:20   ` Stefan Beller
2015-03-22  4:59     ` Junio C Hamano
2015-03-23 16:46       ` David A. Wheeler
2015-03-23 21:00         ` Ævar Arnfjörð Bjarmason
2015-03-22 17:56 ` Ævar Arnfjörð Bjarmason
2015-04-03 21:18   ` David A. Wheeler
2015-04-03 21:26   ` Junio C Hamano
2015-03-26 16:56 ` Kevin D

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).