git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] clone: Warn if clone lacks LICENSE or COPYING file

From
David A. Wheeler <dwheeler@dwheeler.com>
Date
Mar 21, 2015, 18:06 UTC
Message-ID
<E1YZNn7-0002Lc-7O@rmm6prod02.runbox.com>

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
Next: Dennis Kaarsemaker
Message 1 of 10 in “clone: Warn if clone lacks LICENSE or COPYING file”
  1. clone: Warn if clone lacks LICENSE or COPYING fileDavid A. Wheeler, Mar 21, 2015
  2. Dennis KaarsemakerMar 21, 2015
  3. Stefan BellerMar 22, 2015
  4. Junio C HamanoMar 22, 2015
  5. David A. WheelerMar 23, 2015
  6. Ævar Arnfjörð BjarmasonMar 23, 2015
  7. Ævar Arnfjörð BjarmasonMar 22, 2015
  8. David A. WheelerApr 3, 2015
  9. Junio C HamanoApr 3, 2015
  10. Kevin DMar 26, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.