From 42dcac241fe65b19b10f99957224da6858910f07 Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 5 Dec 2014 16:19:09 +0100 Subject: [PATCH 1/2] Manually checks out the branch/tag after git clone. --- src/nimblepkg/download.nim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/nimblepkg/download.nim b/src/nimblepkg/download.nim index 230ecde..e1adbc7 100644 --- a/src/nimblepkg/download.nim +++ b/src/nimblepkg/download.nim @@ -49,6 +49,12 @@ proc doClone(meth: TDownloadMethod, url, downloadDir: string, branch = "", tip = # TODO: Get rid of the annoying 'detached HEAD' message somehow? doCmd("git clone --recursive " & depthArg & branchArg & url & " " & downloadDir) + # Some git versions (e.g. 1.7.9.5) don't check out the correct branch/tag + # directly during clone, so we enter the download directory and forecefully + # check it out just in case. + cd downloadDir: + doCmd("git checkout --force " & branch) + doCmd("git submodule update --init --recursive") of TDownloadMethod.Hg: let tipArg = if tip: "-r tip " else: "" doCmd("hg clone " & tipArg & branchArg & url & " " & downloadDir) From a0fb2c173bc04baa67d4959bde37695bf44c184a Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Fri, 5 Dec 2014 17:43:32 +0100 Subject: [PATCH 2/2] Improves cloning of git repositories. Refs #70. --- src/nimblepkg/download.nim | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/nimblepkg/download.nim b/src/nimblepkg/download.nim index e1adbc7..4768a71 100644 --- a/src/nimblepkg/download.nim +++ b/src/nimblepkg/download.nim @@ -42,21 +42,28 @@ proc doPull(meth: TDownloadMethod, downloadDir: string) = doCmd("hg pull") proc doClone(meth: TDownloadMethod, url, downloadDir: string, branch = "", tip = true) = - let branchArg = if branch == "": "" else: "-b " & branch & " " case meth of TDownloadMethod.Git: - let depthArg = if tip: "--depth 1 " else: "" - # TODO: Get rid of the annoying 'detached HEAD' message somehow? - doCmd("git clone --recursive " & depthArg & branchArg & url & - " " & downloadDir) + let + depthArg = if tip: "--depth 1 " else: "" + branchArg = if branch == "": "-b origin/master" else: "-b " & branch & " " + branch = if branch == "": "master" else: branch # Some git versions (e.g. 1.7.9.5) don't check out the correct branch/tag - # directly during clone, so we enter the download directory and forecefully - # check it out just in case. - cd downloadDir: - doCmd("git checkout --force " & branch) + # directly during clone, so we enter the download directory and manually + # initi the git repo issuing several commands in sequence. Recipe taken + # from http://stackoverflow.com/a/3489576/172690. + downloadDir.createDir + downloadDir.cd: + doCmd("git init") + doCmd("git remote add origin " & url) + doCmd("git fetch origin " & depthArg & branch) + doCmd("git reset --hard FETCH_HEAD") + doCmd("git checkout --force " & branchArg) doCmd("git submodule update --init --recursive") of TDownloadMethod.Hg: - let tipArg = if tip: "-r tip " else: "" + let + tipArg = if tip: "-r tip " else: "" + branchArg = if branch == "": "" else: "-b " & branch & " " doCmd("hg clone " & tipArg & branchArg & url & " " & downloadDir) proc getTagsList(dir: string, meth: TDownloadMethod): seq[string] =