No Description

add.moon 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. config = require "locator_config"
  2. execute = (cmd, capture_exit_code=true) ->
  3. local handle
  4. if capture_exit_code
  5. handle = io.popen "#{cmd}\necho $?"
  6. else
  7. handle = io.popen cmd
  8. result = handle\read "*a"
  9. handle\close!
  10. exit_start, exit_end = result\find "(%d*)[%c]$"
  11. exit_code = tonumber result\sub(exit_start, exit_end)\sub 1, -2
  12. output = result\sub 1, exit_start - 1
  13. if exit_code == 0
  14. return output
  15. else
  16. error "sub-process '#{cmd}' returned status #{exit_code}.\n\n#{output}"
  17. list = execute "git remote"
  18. remotes = {}
  19. for line in list\gmatch "[^\n]+"
  20. remotes[line] = true
  21. for item in *config
  22. if item.remote and item.remote.fetch -- if configured to pull
  23. unless item.remote.branch
  24. item.remote.branch = "master"
  25. if item.remote.name -- if we want a named remote
  26. unless remotes[item.remote.name] -- add it if needed
  27. execute "git remote add -f #{item.remote.name} #{item.remote.fetch}"
  28. if item.remote.push and not ("boolean" == type item.remote.push)
  29. execute "git remote set-url --push #{item.remote.name} #{item.remote.push}"
  30. -- we actually ignore names with in-script usage..
  31. execute "git subtree add --prefix #{item.path\gsub "%.", "/"} #{item.remote.fetch} #{item.remote.branch} --squash"