[Frugalware-darcs] vmexam: dg: new push subcommand

VMiklos vmiklos at frugalware.org
Thu Jun 14 20:25:17 CEST 2007


Darcsweb-Url: http://darcs.frugalware.org/darcsweb/darcsweb.cgi?r=vmexam;a=darcs_commitdiff;h=20070614182212-e2957-dbfe6af451b86ee08f713d515b2f598fe75e2d60.gz;

[dg: new push subcommand
VMiklos <vmiklos at frugalware.org>**20070614182212
 the goal of it is that it tries to find out what will be pushed
] {
hunk ./python/dg.py 428
+def push(argv):
+	def usage(ret):
+		print """Usage: darcs-git push [OPTION]... [GIT OPTIONS]...
+Copy and apply patches from this repository to another one.
+
+Options:
+  -a         --all                 answer yes to all questions
+  -h         --help                shows brief description of command and its arguments"""
+		sys.exit(ret)
+
+	class Options:
+		def __init__(self):
+			self.all = False
+			self.help = False
+			self.gitopts = ""
+	options = Options()
+
+	try:
+		opts, args = getopt.getopt(argv, "ah", ["all", "help"])
+	except getopt.GetoptError:
+		usage(1)
+	optind = 0
+	for opt, arg in opts:
+		if opt in ("-a", "--all"):
+			options.all = True
+		elif opt in ("-h", "--help"):
+			options.help = True
+		optind += 1
+	if optind < len(argv):
+		options.gitopts = " ".join(argv[optind:])
+	if options.help:
+		usage(0)
+	sock = os.popen("git log $(git ls-remote $(git config --get remote.origin.url) master|sed 's/\t.*//').. 2>&1")
+	lines = sock.readlines()
+	ret = sock.close()
+	if not len(lines):
+		print "No recorded local changes to push!"
+		return
+	print "".join(lines)
+	if ret:
+		print "Maybe you are not up-to-date and need to pull first?"
+		return
+	if not options.all:
+		while True:
+			ret = ask("Do you want to push these patches? [ynq]")
+			if ret == "y":
+				break
+			if ret in ("n", "q"):
+				sys.exit(0)
+			print "Invalid response, try again!"
+	os.system("git push %s" % options.gitopts)
+
hunk ./python/dg.py 560
+		elif sys.argv[1] == "push":
+			push(argv[1:])
}


More information about the Frugalware-darcs mailing list