[Frugalware-darcs] vmexam: dg: support for pull --dry-run

VMiklos vmiklos at frugalware.org
Thu Jun 28 02:05:23 CEST 2007


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

[dg: support for pull --dry-run
VMiklos <vmiklos at frugalware.org>**20070628000350
 finally managed to figure out how to do so :-)
] {
hunk ./python/dg.py 500
-	sock = os.popen("git log $(git ls-remote $(git config --get remote.origin.url) master|sed 's/\t.*//').. --no-merges 2>&1")
+	sock = os.popen("git log origin/master..master --no-merges 2>&1")
hunk ./python/dg.py 507
-	if ret:
-		print "Maybe you are not up-to-date and need to pull first?"
-		return
hunk ./python/dg.py 517
+def pull(argv):
+	def usage(ret):
+		print """Usage: darcs-git pull [OPTION]... [GIT OPTIONS]...
+Copy and apply patches to this repository from 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)
+	os.system("git fetch")
+	sock = os.popen("git log master..origin/master --no-merges 2>&1")
+	lines = sock.readlines()
+	ret = sock.close()
+	if not len(lines):
+		print "No remote changes to pull!"
+		return
+	print "".join(lines)
+	if not options.all:
+		while True:
+			ret = ask("Do you want to pull these patches? [ynq]")
+			if ret == "y":
+				break
+			if ret in ("n", "q"):
+				sys.exit(0)
+			print "Invalid response, try again!"
+	os.system("git pull %s" % options.gitopts)
+
hunk ./python/dg.py 722
-  W pull          Copy and apply patches from another repository to this one.
+  Y pull          Copy and apply patches from another repository to this one.
hunk ./python/dg.py 754
+		elif sys.argv[1] == "pull":
+			pull(argv[1:])
}


More information about the Frugalware-darcs mailing list