]> git.e2factory.org Git - e2factory.git/commitdiff
Unify indentation
authorTobias Ulmer <tu@emlix.com>
Tue, 7 Aug 2012 07:44:29 +0000 (09:44 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 8 Aug 2012 12:44:00 +0000 (14:44 +0200)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/generic_git.lua

index aec79a429e8d5da84341dee44e32cba8b0221a4c..5ab427af51cb1cc43023471673adc2671c857b2f 100644 (file)
@@ -38,31 +38,31 @@ local cache = require("cache")
 -- @return true on success, false on error
 -- @return nil, an error object on failure
 function generic_git.git_clone_url1(surl, location, destdir, skip_checkout)
-  if (not surl) or (not location) or (not destdir) then
-    e2lib.abort("git_clone_url1(): missing parameter")
-  end
-  local rc, re
-  local e = new_error("cloning git repository")
-  local full_url = string.format("%s/%s", surl, location)
-  local u, re = url.parse(full_url)
-  if not u then
-    return false, e:cat(re)
-  end
-  local src, re = generic_git.git_url1(u)
-  if not src then
-    return false, e:cat(re)
-  end
-  local flags = ""
-  if skip_checkout then
-    flags = "-n"
-  end
-  local cmd = string.format("git clone %s --quiet %s %s", flags,
-       e2lib.shquote(src), e2lib.shquote(destdir))
-  local rc, re = e2lib.callcmd_log(cmd)
-  if rc ~= 0 then
-    return false, e:cat(re)
-  end
-  return true, nil
+    if (not surl) or (not location) or (not destdir) then
+        e2lib.abort("git_clone_url1(): missing parameter")
+    end
+    local rc, re
+    local e = new_error("cloning git repository")
+    local full_url = string.format("%s/%s", surl, location)
+    local u, re = url.parse(full_url)
+    if not u then
+        return false, e:cat(re)
+    end
+    local src, re = generic_git.git_url1(u)
+    if not src then
+        return false, e:cat(re)
+    end
+    local flags = ""
+    if skip_checkout then
+        flags = "-n"
+    end
+    local cmd = string.format("git clone %s --quiet %s %s", flags,
+    e2lib.shquote(src), e2lib.shquote(destdir))
+    local rc, re = e2lib.callcmd_log(cmd)
+    if rc ~= 0 then
+        return false, e:cat(re)
+    end
+    return true, nil
 end
 
 --- git branch wrapper
@@ -73,21 +73,21 @@ end
 -- @return bool
 -- @return nil, an error object on failure
 function generic_git.git_branch_new1(gitwc, track, branch, start_point)
-  -- git branch [--track|--no-track] <branch> <start_point>
-  local f_track = nil
-  if track == true then
-    f_track = "--track"
-  else
-    f_track = "--no-track"
-  end
-  local cmd = string.format( "cd %s && git branch %s %s %s",
+    -- git branch [--track|--no-track] <branch> <start_point>
+    local f_track = nil
+    if track == true then
+        f_track = "--track"
+    else
+        f_track = "--no-track"
+    end
+    local cmd = string.format( "cd %s && git branch %s %s %s",
     e2lib.shquote(gitwc), f_track, e2lib.shquote(branch),
     e2lib.shquote(start_point))
-  local rc = e2lib.callcmd_capture(cmd)
-  if rc ~= 0 then
-    return false, new_error("creating new branch failed")
-  end
-  return true, nil
+    local rc = e2lib.callcmd_capture(cmd)
+    if rc ~= 0 then
+        return false, new_error("creating new branch failed")
+    end
+    return true, nil
 end
 
 --- git checkout wrapper
@@ -96,15 +96,15 @@ end
 -- @return bool
 -- @return an error object on failure
 function generic_git.git_checkout1(gitwc, branch)
-  e2lib.log(3, string.format("checking out branch: %s", branch))
-  -- git checkout <branch>
-  local cmd = string.format("cd %s && git checkout %s", e2lib.shquote(gitwc),
+    e2lib.log(3, string.format("checking out branch: %s", branch))
+    -- git checkout <branch>
+    local cmd = string.format("cd %s && git checkout %s", e2lib.shquote(gitwc),
     e2lib.shquote(branch))
-  local rc = e2lib.callcmd_capture(cmd)
-  if rc ~= 0 then
-    return false, new_error("git checkout failed")
-  end
-  return true, nil
+    local rc = e2lib.callcmd_capture(cmd)
+    if rc ~= 0 then
+        return false, new_error("git checkout failed")
+    end
+    return true, nil
 end
 
 --- git rev-list wrapper function
@@ -113,32 +113,32 @@ end
 -- @return string: the commit id matching the ref parameter, or nil on error
 -- @return an error object on failure
 function generic_git.git_rev_list1(gitdir, ref)
-  e2lib.log(4, string.format("git_rev_list(): %s %s",
-                                       tostring(gitdir), tostring(ref)))
-  local e = new_error("git rev-list failed")
-  local rc, re
-  local tmpfile = e2lib.mktempfile()
-  local args = string.format("--max-count=1 '%s' -- >'%s'", ref, tmpfile)
-  rc, re = e2lib.git(gitdir, "rev-list", args)
-  if not rc then
-    return false, e -- do not include the low-level error here
-  end
-  local f, msg = io.open(tmpfile, "r")
-  if not f then
-    return nil, e:cat(msg)
-  end
-  local rev = f:read()
-  f:close()
-  e2lib.rmtempfile(tmpfile)
-  if (not rev) or (not rev:match("^%S+$")) then
-    return nil, new_error("can't parse git rev-list output")
-  end
-  if rev then
-    e2lib.log(4, string.format("git_rev_list: %s", rev))
-  else
-    e2lib.log(4, string.format("git_rev_list: unknown ref: %s", ref))
-  end
-  return rev, nil
+    e2lib.log(4, string.format("git_rev_list(): %s %s",
+    tostring(gitdir), tostring(ref)))
+    local e = new_error("git rev-list failed")
+    local rc, re
+    local tmpfile = e2lib.mktempfile()
+    local args = string.format("--max-count=1 '%s' -- >'%s'", ref, tmpfile)
+    rc, re = e2lib.git(gitdir, "rev-list", args)
+    if not rc then
+        return false, e -- do not include the low-level error here
+    end
+    local f, msg = io.open(tmpfile, "r")
+    if not f then
+        return nil, e:cat(msg)
+    end
+    local rev = f:read()
+    f:close()
+    e2lib.rmtempfile(tmpfile)
+    if (not rev) or (not rev:match("^%S+$")) then
+        return nil, new_error("can't parse git rev-list output")
+    end
+    if rev then
+        e2lib.log(4, string.format("git_rev_list: %s", rev))
+    else
+        e2lib.log(4, string.format("git_rev_list: unknown ref: %s", ref))
+    end
+    return rev, nil
 end
 
 --- initialize a git repository
@@ -146,35 +146,35 @@ end
 -- @return bool
 -- @return an error object on failure
 function generic_git.git_init_db1(rurl)
-  if (not rurl) then
-    e2lib.abort("git_init_db1(): missing parameter")
-  end
-  local e = new_error("running git_init_db")
-  local rc, re
-  local u, re = url.parse(rurl)
-  if not u then
-    return false, e:cat(re)
-  end
-  local rc = false
-  local cmd = nil
-  local gitdir = string.format("/%s", u.path)
-  local gitcmd = string.format("mkdir -p %s && GIT_DIR=%s git init-db --shared",
+    if (not rurl) then
+        e2lib.abort("git_init_db1(): missing parameter")
+    end
+    local e = new_error("running git_init_db")
+    local rc, re
+    local u, re = url.parse(rurl)
+    if not u then
+        return false, e:cat(re)
+    end
+    local rc = false
+    local cmd = nil
+    local gitdir = string.format("/%s", u.path)
+    local gitcmd = string.format("mkdir -p %s && GIT_DIR=%s git init-db --shared",
     e2lib.shquote(gitdir), e2lib.shquote(gitdir))
-  if u.transport == "ssh" or u.transport == "scp" or
-     u.transport == "rsync+ssh" then
-    local ssh = tools.get_tool("ssh")
-    cmd = string.format("%s %s %s", e2lib.shquote(ssh), e2lib.shquote(u.server),
-      e2lib.shquote(gitcmd))
-  elseif u.transport == "file" then
-    cmd = gitcmd
-  else
-    return false, e:append("transport not supported: %s", u.transport)
-  end
-  rc = e2lib.callcmd_capture(cmd)
-  if rc ~= 0 then
-    return false, e:append("error running git init-db")
-  end
-  return true, nil
+    if u.transport == "ssh" or u.transport == "scp" or
+        u.transport == "rsync+ssh" then
+        local ssh = tools.get_tool("ssh")
+        cmd = string.format("%s %s %s", e2lib.shquote(ssh), e2lib.shquote(u.server),
+        e2lib.shquote(gitcmd))
+    elseif u.transport == "file" then
+        cmd = gitcmd
+    else
+        return false, e:append("transport not supported: %s", u.transport)
+    end
+    rc = e2lib.callcmd_capture(cmd)
+    if rc ~= 0 then
+        return false, e:append("error running git init-db")
+    end
+    return true, nil
 end
 
 --- do a git push
@@ -184,27 +184,27 @@ end
 -- @return bool
 -- @return an error object on failure
 function generic_git.git_push1(gitdir, rurl, refspec)
-  if (not rurl) or (not gitdir) or (not refspec) then
-    e2lib.abort("git_push1(): missing parameter")
-  end
-  local rc, re
-  local e = new_error("git push failed")
-  local u, re = url.parse(rurl)
-  if not u then
-    return false, e:cat(re)
-  end
-  local remote_git_url, re = generic_git.git_url1(u)
-  if not remote_git_url then
-    return false, e:cat(re)
-  end
-  -- GIT_DIR=gitdir git push remote_git_url refspec
-  local cmd = string.format("GIT_DIR=%s git push %s %s", e2lib.shquote(gitdir),
+    if (not rurl) or (not gitdir) or (not refspec) then
+        e2lib.abort("git_push1(): missing parameter")
+    end
+    local rc, re
+    local e = new_error("git push failed")
+    local u, re = url.parse(rurl)
+    if not u then
+        return false, e:cat(re)
+    end
+    local remote_git_url, re = generic_git.git_url1(u)
+    if not remote_git_url then
+        return false, e:cat(re)
+    end
+    -- GIT_DIR=gitdir git push remote_git_url refspec
+    local cmd = string.format("GIT_DIR=%s git push %s %s", e2lib.shquote(gitdir),
     e2lib.shquote(remote_git_url), e2lib.shquote(refspec))
-  local rc = e2lib.callcmd_capture(cmd)
-  if rc ~= 0 then
-    return false, e
-  end
-  return true, nil
+    local rc = e2lib.callcmd_capture(cmd)
+    if rc ~= 0 then
+        return false, e
+    end
+    return true, nil
 end
 
 --- do a git remote-add
@@ -214,31 +214,31 @@ end
 -- @return bool
 -- @return an error object on failure
 function generic_git.git_remote_add1(lurl, rurl, name)
-  if (not lurl) or (not rurl) or (not name) then
-    e2lib.abort("missing parameter")
-  end
-  local rc, re
-  local e = new_error("git remote-add failed")
-  local lrepo, re = url.parse(lurl)
-  if not lrepo then
-    return false, e:cat(re)
-  end
-  local rrepo, re = url.parse(rurl)
-  if not rrepo then
-    return false, e:cat(re)
-  end
-  local giturl, re = generic_git.git_url1(rrepo)
-  if not giturl then
-    return false, e:cat(re)
-  end
-  -- git remote add <name> <giturl>
-  local cmd = string.format("cd %s && git remote add %s %s",
+    if (not lurl) or (not rurl) or (not name) then
+        e2lib.abort("missing parameter")
+    end
+    local rc, re
+    local e = new_error("git remote-add failed")
+    local lrepo, re = url.parse(lurl)
+    if not lrepo then
+        return false, e:cat(re)
+    end
+    local rrepo, re = url.parse(rurl)
+    if not rrepo then
+        return false, e:cat(re)
+    end
+    local giturl, re = generic_git.git_url1(rrepo)
+    if not giturl then
+        return false, e:cat(re)
+    end
+    -- git remote add <name> <giturl>
+    local cmd = string.format("cd %s && git remote add %s %s",
     e2lib.shquote("/"..lrepo.path), e2lib.shquote(name), e2lib.shquote(giturl))
-  local rc = e2lib.callcmd_capture(cmd)
-  if rc ~= 0 then
-    return false, e
-  end
-  return true, nil
+    local rc = e2lib.callcmd_capture(cmd)
+    if rc ~= 0 then
+        return false, e
+    end
+    return true, nil
 end
 
 --- translate a url to a git url
@@ -246,17 +246,17 @@ end
 -- @return string: the git url
 -- @return an error object on failure
 function generic_git.git_url1(u)
-  e2lib.log(4, string.format("git_url(%s)", tostring(u)))
-  local giturl
-  if u.transport == "ssh" or u.transport == "scp" or
-     u.transport == "rsync+ssh" then
-    giturl = string.format("git+ssh://%s/%s", u.server, u.path)
-  elseif u.transport == "file" then
-    giturl = string.format("/%s", u.path)
-  else
-    return nil, new_error("transport not supported: %s", u.transport)
-  end
-  return giturl, nil
+    e2lib.log(4, string.format("git_url(%s)", tostring(u)))
+    local giturl
+    if u.transport == "ssh" or u.transport == "scp" or
+        u.transport == "rsync+ssh" then
+        giturl = string.format("git+ssh://%s/%s", u.server, u.path)
+    elseif u.transport == "file" then
+        giturl = string.format("/%s", u.path)
+    else
+        return nil, new_error("transport not supported: %s", u.transport)
+    end
+    return giturl, nil
 end
 
 --- clone a git repository by server and location
@@ -268,18 +268,18 @@ end
 -- @return bool
 -- @return an error object on failure
 function generic_git.git_clone_from_server(c, server, location, destdir,
-                                                               skip_checkout)
-  local rc, re
-  local e = new_error("cloning git repository")
-  local surl, re = cache.remote_url(c, server, location)
-  if not surl then
-    return false, e:cat(re)
-  end
-  local rc, re = generic_git.git_clone_url1(surl, "", destdir, skip_checkout)
-  if not rc then
-    return false, re
-  end
-  return true, nil
+    skip_checkout)
+    local rc, re
+    local e = new_error("cloning git repository")
+    local surl, re = cache.remote_url(c, server, location)
+    if not surl then
+        return false, e:cat(re)
+    end
+    local rc, re = generic_git.git_clone_url1(surl, "", destdir, skip_checkout)
+    if not rc then
+        return false, re
+    end
+    return true, nil
 end
 
 --- initialize a git repository
@@ -289,17 +289,17 @@ end
 -- @return bool
 -- @return an error object on failure
 function generic_git.git_init_db(c, server, location)
-  local rc, re
-  local e = new_error("initializing git repository")
-  local rurl, re = cache.remote_url(c, server, location)
-  if not rurl then
-    return false, e:cat(re)
-  end
-  local rc, re = generic_git.git_init_db1(rurl)
-  if not rc then
-    return false, re
-  end
-  return true, nil
+    local rc, re
+    local e = new_error("initializing git repository")
+    local rurl, re = cache.remote_url(c, server, location)
+    if not rurl then
+        return false, e:cat(re)
+    end
+    local rc, re = generic_git.git_init_db1(rurl)
+    if not rc then
+        return false, re
+    end
+    return true, nil
 end
 
 --- do a git push
@@ -311,13 +311,13 @@ end
 -- @return bool
 -- @return an error object on failure
 function generic_git.git_push(c, gitdir, server, location, refspec)
-  local rc, re
-  local e = new_error("git push failed")
-  local rurl, re = cache.remote_url(c, server, location)
-  if not rurl then
-    return false, e:cat(re)
-  end
-  return generic_git.git_push1(gitdir, rurl, refspec)
+    local rc, re
+    local e = new_error("git push failed")
+    local rurl, re = cache.remote_url(c, server, location)
+    if not rurl then
+        return false, e:cat(re)
+    end
+    return generic_git.git_push1(gitdir, rurl, refspec)
 end
 
 --- do a git config query
@@ -326,22 +326,22 @@ end
 -- @return string: the value printed to stdout by git config, or nil
 -- @return an error object on failure
 function generic_git.git_config(gitdir, query)
-  local rc, re
-  local e = new_error("running git config")
-  local tmpfile = e2lib.mktempfile()
-  local cmd = string.format("GIT_DIR=%s git config %s > %s",
+    local rc, re
+    local e = new_error("running git config")
+    local tmpfile = e2lib.mktempfile()
+    local cmd = string.format("GIT_DIR=%s git config %s > %s",
     e2lib.shquote(gitdir), e2lib.shquote(query), e2lib.shquote(tmpfile))
-  local rc, re = e2lib.callcmd_log(cmd)
-  if rc ~= 0 then
-    e:append("git config failed")
-    return nil, e
-  end
-  local git_output = e2lib.read_line(tmpfile)
-  if not git_output then
-    return nil, e:append("can't read git output from temporary file")
-  end
-  e2lib.rmtempfile(tmpfile)
-  return git_output, nil
+    local rc, re = e2lib.callcmd_log(cmd)
+    if rc ~= 0 then
+        e:append("git config failed")
+        return nil, e
+    end
+    local git_output = e2lib.read_line(tmpfile)
+    if not git_output then
+        return nil, e:append("can't read git output from temporary file")
+    end
+    e2lib.rmtempfile(tmpfile)
+    return git_output, nil
 end
 
 --- do a git add
@@ -350,18 +350,18 @@ end
 -- @return bool
 -- @return an error object on failure
 function generic_git.git_add(gitdir, args)
-  local rc, re
-  local e = new_error("running git add")
-  if not gitdir then
-       gitdir = ".git"
-  end
-  local cmd = string.format("GIT_DIR=%s git add %s",
+    local rc, re
+    local e = new_error("running git add")
+    if not gitdir then
+        gitdir = ".git"
+    end
+    local cmd = string.format("GIT_DIR=%s git add %s",
     e2lib.shquote(gitdir), e2lib.shquote(args))
-  local rc, re = e2lib.callcmd_log(cmd)
-  if rc ~= 0 then
-    return nil, e:cat(re)
-  end
-  return true, nil
+    local rc, re = e2lib.callcmd_log(cmd)
+    if rc ~= 0 then
+        return nil, e:cat(re)
+    end
+    return true, nil
 end
 
 --- do a git commit
@@ -370,9 +370,9 @@ end
 -- @return bool
 -- @return an error object on failure
 function generic_git.git_commit(gitdir, args)
-  local rc, re
-  local e = new_error("git commit failed")
-  return e2lib.git("commit", gitdir, args)
+    local rc, re
+    local e = new_error("git commit failed")
+    return e2lib.git("commit", gitdir, args)
 end
 
 --- compare a local tag and the remote tag with the same name
@@ -381,50 +381,50 @@ end
 -- @return bool, or nil on error
 -- @return an error object on failure
 function generic_git.verify_remote_tag(gitdir, tag)
-  e2lib.logf(4, "generic_git.verify_remote_tag(%s, %s)", tostring(gitdir),
-                                                       tostring(tag))
-  local e = new_error("verifying remote tag")
-  local rc, re
-
-  -- fetch the remote tag
-  -- TODO: escape args, tag, rtag
-  local rtag = string.format("%s.remote", tag)
-  local args = string.format("origin refs/tags/%s:refs/tags/%s",
-                                                               tag, rtag)
-  rc, re = e2lib.git(gitdir, "fetch", args)
-  if not rc then
-    return false, new_error("remote tag is not available: %s", tag)
-  end
-
-  -- store commit ids for use in the error message, if any
-  local lrev = generic_git.git_rev_list1(gitdir, tag)
-  if not lrev then
-    return nil, e:cat(re)
-  end
-  local rrev = generic_git.git_rev_list1(gitdir, rtag)
-  if not rrev then
-    return nil, e:cat(re)
-  end
-
-  -- check that local and remote tags point to the same revision
-  local args = string.format("--quiet '%s' '%s'", rtag, tag)
-  local equal, re = e2lib.git(gitdir, "diff", args)
-
-  -- delete the remote tag again, before evaluating the return code
-  -- of 'git diff'
-  local args = string.format("-d '%s'", rtag)
-  rc, re = e2lib.git(gitdir, "tag", args)
-  if not rc then
-    return nil, e:cat(re)
-  end
-  if not equal then
-    return false, e:append(
-      "local tag differs from remote tag\n"..
-      "tag name: %s\n"..
-      "local:  %s\n"..
-      "remote: %s\n", tag, lrev, rrev)
-  end
-  return true, nil
+    e2lib.logf(4, "generic_git.verify_remote_tag(%s, %s)", tostring(gitdir),
+    tostring(tag))
+    local e = new_error("verifying remote tag")
+    local rc, re
+
+    -- fetch the remote tag
+    -- TODO: escape args, tag, rtag
+    local rtag = string.format("%s.remote", tag)
+    local args = string.format("origin refs/tags/%s:refs/tags/%s",
+    tag, rtag)
+    rc, re = e2lib.git(gitdir, "fetch", args)
+    if not rc then
+        return false, new_error("remote tag is not available: %s", tag)
+    end
+
+    -- store commit ids for use in the error message, if any
+    local lrev = generic_git.git_rev_list1(gitdir, tag)
+    if not lrev then
+        return nil, e:cat(re)
+    end
+    local rrev = generic_git.git_rev_list1(gitdir, rtag)
+    if not rrev then
+        return nil, e:cat(re)
+    end
+
+    -- check that local and remote tags point to the same revision
+    local args = string.format("--quiet '%s' '%s'", rtag, tag)
+    local equal, re = e2lib.git(gitdir, "diff", args)
+
+    -- delete the remote tag again, before evaluating the return code
+    -- of 'git diff'
+    local args = string.format("-d '%s'", rtag)
+    rc, re = e2lib.git(gitdir, "tag", args)
+    if not rc then
+        return nil, e:cat(re)
+    end
+    if not equal then
+        return false, e:append(
+        "local tag differs from remote tag\n"..
+        "tag name: %s\n"..
+        "local:  %s\n"..
+        "remote: %s\n", tag, lrev, rrev)
+    end
+    return true, nil
 end
 
 --- verify that the working copy is clean and matches HEAD
@@ -432,68 +432,68 @@ end
 -- @return bool, or nil on error
 -- @return an error object on failure
 function generic_git.verify_clean_repository(gitwc)
-  e2lib.logf(4, "generic_git.verify_clean_repository(%s)", tostring(gitwc))
-  gitwc = gitwc or "."
-  local e = new_error("verifying that repository is clean")
-  local rc, re
-  local tmp = e2lib.mktempfile()
-  rc, re = e2lib.chdir(gitwc)
-  if not rc then
-    return nil, e:cat(re)
-  end
-  -- check for unknown files in the filesystem
-  local args = string.format(
-                       "--exclude-standard --directory --others >%s", tmp)
-  rc, re = e2lib.git(nil, "ls-files", args)
-  if not rc then
-    return nil, e:cat(re)
-  end
-  local x, msg = io.open(tmp, "r")
-  if not x then
-    return nil, e:cat(msg)
-  end
-  local files = x:read("*a")
-  x:close()
-  if #files > 0 then
-    local msg = "the following files are not checked into the repository:\n"
-    msg = msg .. files
-    return false, new_error("%s", msg)
-  end
-  -- verify that the working copy matches HEAD
-  local args = string.format("--name-only HEAD >%s", tmp)
-  rc, re = e2lib.git(nil, "diff-index", args)
-  if not rc then
-    return nil, e:cat(re)
-  end
-  local x, msg = io.open(tmp, "r")
-  if not x then
-    return nil, e:cat(msg)
-  end
-  local files = x:read("*a")
-  x:close()
-  if #files > 0 then
-    msg = "the following files are modified:\n"
-    msg = msg..files
-    return false, new_error("%s", msg)
-  end
-  -- verify that the index matches HEAD
-  local args = string.format("--name-only --cached HEAD >%s", tmp)
-  rc, re = e2lib.git(nil, "diff-index", args)
-  if not rc then
-    return nil, e:cat(re)
-  end
-  local x, msg = io.open(tmp, "r")
-  if not x then
-    return nil, e:cat(msg)
-  end
-  local files = x:read("*a")
-  x:close()
-  if #files > 0 then
-    msg = "the following files in index are modified:\n"
-    msg = msg..files
-    return false, new_error("%s", msg)
-  end
-  return true
+    e2lib.logf(4, "generic_git.verify_clean_repository(%s)", tostring(gitwc))
+    gitwc = gitwc or "."
+    local e = new_error("verifying that repository is clean")
+    local rc, re
+    local tmp = e2lib.mktempfile()
+    rc, re = e2lib.chdir(gitwc)
+    if not rc then
+        return nil, e:cat(re)
+    end
+    -- check for unknown files in the filesystem
+    local args = string.format(
+    "--exclude-standard --directory --others >%s", tmp)
+    rc, re = e2lib.git(nil, "ls-files", args)
+    if not rc then
+        return nil, e:cat(re)
+    end
+    local x, msg = io.open(tmp, "r")
+    if not x then
+        return nil, e:cat(msg)
+    end
+    local files = x:read("*a")
+    x:close()
+    if #files > 0 then
+        local msg = "the following files are not checked into the repository:\n"
+        msg = msg .. files
+        return false, new_error("%s", msg)
+    end
+    -- verify that the working copy matches HEAD
+    local args = string.format("--name-only HEAD >%s", tmp)
+    rc, re = e2lib.git(nil, "diff-index", args)
+    if not rc then
+        return nil, e:cat(re)
+    end
+    local x, msg = io.open(tmp, "r")
+    if not x then
+        return nil, e:cat(msg)
+    end
+    local files = x:read("*a")
+    x:close()
+    if #files > 0 then
+        msg = "the following files are modified:\n"
+        msg = msg..files
+        return false, new_error("%s", msg)
+    end
+    -- verify that the index matches HEAD
+    local args = string.format("--name-only --cached HEAD >%s", tmp)
+    rc, re = e2lib.git(nil, "diff-index", args)
+    if not rc then
+        return nil, e:cat(re)
+    end
+    local x, msg = io.open(tmp, "r")
+    if not x then
+        return nil, e:cat(msg)
+    end
+    local files = x:read("*a")
+    x:close()
+    if #files > 0 then
+        msg = "the following files in index are modified:\n"
+        msg = msg..files
+        return false, new_error("%s", msg)
+    end
+    return true
 end
 
 --- verify that HEAD matches the given tag
@@ -502,46 +502,46 @@ end
 -- @return bool, or nil on error
 -- @return an error object on failure
 function generic_git.verify_head_match_tag(gitwc, verify_tag)
-  e2lib.logf(4, "generic_git.verify_head_match_tag(%s, %s)", tostring(gitwc),
-                                                       tostring(verify_tag))
-  assert(verify_tag)
-  gitwc = gitwc or "."
-  local e = new_error("verifying that HEAD matches 'refs/tags/%s'", verify_tag)
-  local rc, re
-  local tmp = e2lib.mktempfile()
-  local args = string.format("--tags --match '%s' >%s", verify_tag, tmp)
-  rc, re = e2lib.chdir(gitwc)
-  if not rc then
-    return nil, e:cat(re)
-  end
-  rc, re = e2lib.git(nil, "describe", args)
-  if not rc then
-    return nil, e:cat(re)
-  end
-  local x, msg = io.open(tmp, "r")
-  if not x then
-    return nil, e:cat(msg)
-  end
-  local tag, msg = x:read()
-  x:close()
-  if tag == nil then
-    return nil, e:cat(msg)
-  end
-  if tag ~= verify_tag then
-    return false
-  end
-  return true
+    e2lib.logf(4, "generic_git.verify_head_match_tag(%s, %s)", tostring(gitwc),
+    tostring(verify_tag))
+    assert(verify_tag)
+    gitwc = gitwc or "."
+    local e = new_error("verifying that HEAD matches 'refs/tags/%s'", verify_tag)
+    local rc, re
+    local tmp = e2lib.mktempfile()
+    local args = string.format("--tags --match '%s' >%s", verify_tag, tmp)
+    rc, re = e2lib.chdir(gitwc)
+    if not rc then
+        return nil, e:cat(re)
+    end
+    rc, re = e2lib.git(nil, "describe", args)
+    if not rc then
+        return nil, e:cat(re)
+    end
+    local x, msg = io.open(tmp, "r")
+    if not x then
+        return nil, e:cat(msg)
+    end
+    local tag, msg = x:read()
+    x:close()
+    if tag == nil then
+        return nil, e:cat(msg)
+    end
+    if tag ~= verify_tag then
+        return false
+    end
+    return true
 end
 
 function generic_git.sourceset2ref(sourceset, branch, tag)
-       if sourceset == "branch" or
-          (sourceset == "lazytag" and tag == "^") then
-               return string.format("refs/heads/%s", branch)
-       elseif sourceset == "tag" or
-         (sourceset == "lazytag" and tag ~= "^") then
-               return string.format("refs/tags/%s", tag)
-       end
-       return nil, "invalid sourceset"
+    if sourceset == "branch" or
+        (sourceset == "lazytag" and tag == "^") then
+        return string.format("refs/heads/%s", branch)
+    elseif sourceset == "tag" or
+        (sourceset == "lazytag" and tag ~= "^") then
+        return string.format("refs/tags/%s", tag)
+    end
+    return nil, "invalid sourceset"
 end
 
 --- create a new git source repository
@@ -554,48 +554,50 @@ end
 -- @return bool
 -- @return nil, or an error string on error
 function generic_git.new_repository(c, lserver, llocation, rserver, rlocation, flags)
-  local rc, re
-  local e = new_error("setting up new git repository failed")
-  local lserver_url, re = cache.remote_url(c, lserver, llocation)
-  if not lserver_url then
-    return false, e:cat(re)
-  end
-  local lurl, re = url.parse(lserver_url)
-  if not lurl then
-    return false, e:cat(re)
-  end
-  local rc = e2lib.mkdir(string.format("/%s", lurl.path), "-p")
-  if not rc then
-    return false, e:cat("can't create path to local git repository")
-  end
-  rc = generic_git.git_init_db(c, lserver, llocation)
-  if not rc then
-    return false, e:cat("can't initialize local git repository")
-  end
-  rc = git.git_remote_add(c, lserver, llocation, "origin",
-                                               rserver, rlocation)
-  if not rc then
-    return false, e:cat("git remote add failed")
-  end
-  rc = e2lib.chdir("/"..lurl.path)
-  if not rc then
-    return false, e:cat(re)
-  end
-  local targs = {
-       string.format("'branch.master.remote' 'origin'"),
-       string.format("'branch.master.merge' 'refs/heads/master'"),
-  }
-  for _,args in ipairs(targs) do
-    rc, re = e2lib.git(".", "config", args)
+    local rc, re
+    local e = new_error("setting up new git repository failed")
+    local lserver_url, re = cache.remote_url(c, lserver, llocation)
+    if not lserver_url then
+        return false, e:cat(re)
+    end
+    local lurl, re = url.parse(lserver_url)
+    if not lurl then
+        return false, e:cat(re)
+    end
+    local rc = e2lib.mkdir(string.format("/%s", lurl.path), "-p")
+    if not rc then
+        return false, e:cat("can't create path to local git repository")
+    end
+    rc = generic_git.git_init_db(c, lserver, llocation)
+    if not rc then
+        return false, e:cat("can't initialize local git repository")
+    end
+    rc = git.git_remote_add(c, lserver, llocation, "origin",
+    rserver, rlocation)
+    if not rc then
+        return false, e:cat("git remote add failed")
+    end
+    rc = e2lib.chdir("/"..lurl.path)
     if not rc then
-      return false, e:cat(re)
-    end
-  end
-  rc = generic_git.git_init_db(c, rserver, rlocation)
-  if not rc then
-    return false, e:cat("can't initialize remote git repository")
-  end
-  return true, nil
+        return false, e:cat(re)
+    end
+    local targs = {
+        string.format("'branch.master.remote' 'origin'"),
+        string.format("'branch.master.merge' 'refs/heads/master'"),
+    }
+    for _,args in ipairs(targs) do
+        rc, re = e2lib.git(".", "config", args)
+        if not rc then
+            return false, e:cat(re)
+        end
+    end
+    rc = generic_git.git_init_db(c, rserver, rlocation)
+    if not rc then
+        return false, e:cat("can't initialize remote git repository")
+    end
+    return true, nil
 end
 
 return generic_git
+
+-- vim:sw=4:sts=4:et: