コード例 #1
0
ファイル: main.go プロジェクト: sbinet/go-svn2git
func main() {
	flag.Parse()

	if *g_help {
		git_svn_usage()
		os.Exit(1)
	}

	ctx := svn.NewContextFrom(
		g_url,
		*g_verbose,
		*g_metadata,
		*g_no_minimize_url,
		*g_root_is_trunk,
		*g_rebase,
		*g_username,
		*g_trunk,
		*g_branches,
		*g_tags,
		*g_exclude,
		*g_revision,
		*g_no_trunk,
		*g_no_branches,
		*g_no_tags,
		*g_authors,
	)

	if ctx.RootIsTrunk {
		ctx.Trunk = ""
		ctx.Branches = ""
		ctx.Tags = ""
	}

	if ctx.NoTrunk {
		ctx.Trunk = ""
	}

	if ctx.NoBranches {
		ctx.Branches = ""
	}

	if ctx.NoTags {
		ctx.Tags = ""
	}

	if ctx.Verbose {
		fmt.Printf("==go-svn2git...\n")
		fmt.Printf(" verbose:  %v\n", ctx.Verbose)
		fmt.Printf(" rebase:   %v\n", ctx.Rebase)
		fmt.Printf(" username: %q\n", ctx.UserName)
		fmt.Printf(" trunk:    %q\n", ctx.Trunk)
		fmt.Printf(" branches: %q\n", ctx.Branches)
		fmt.Printf(" tags:     %q\n", ctx.Tags)
		fmt.Printf(" authors:  %q\n", ctx.Authors)
		fmt.Printf(" root-is-trunk: %v\n", ctx.RootIsTrunk)
		fmt.Printf(" exclude:  %q\n", ctx.Exclude)
	}

	if ctx.Rebase {
		if flag.NArg() > 0 {
			fmt.Printf("** too many arguments\n")
			fmt.Printf("** \"%s -rebase\" takes no argument\n", os.Args[0])
			//git_svn_usage()
			err := verify_working_tree_is_clean()
			if err != nil {
				os.Exit(1)
			}
		}
	} else {
		ok := true
		switch flag.NArg() {
		case 0:
			fmt.Printf("** missing SVN_URL parameter\n")
			ok = false
		case 1:
			/*noop*/
		default:
			fmt.Printf("** too many arguments: %v\n", flag.Args())
			fmt.Printf("** did you pass an option *after* the url ?\n")
			ok = false
		}
		if !ok {
			fmt.Printf("** run \"%s -help\" for help\n", os.Args[0])
			os.Exit(1)
		}
		ctx.Url = flag.Arg(0)
	}

	err := ctx.Run()
	if err != nil {
		fmt.Printf("**error** %v\n", err)
		os.Exit(1)
	}
}
コード例 #2
0
func hwaf_run_cmd_git_svn_clone(cmd *commander.Command, args []string) {
	var err error
	n := "hwaf-" + cmd.Name()

	ctx := svn.NewContextFrom(
		"no-url",
		cmd.Flag.Lookup("verbose").Value.Get().(bool),
		cmd.Flag.Lookup("metadata").Value.Get().(bool),
		cmd.Flag.Lookup("no-minimize-url").Value.Get().(bool),
		cmd.Flag.Lookup("root-is-trunk").Value.Get().(bool),
		cmd.Flag.Lookup("rebase").Value.Get().(bool),
		cmd.Flag.Lookup("username").Value.Get().(string),
		cmd.Flag.Lookup("trunk").Value.Get().(string),
		cmd.Flag.Lookup("branches").Value.Get().(string),
		cmd.Flag.Lookup("tags").Value.Get().(string),
		cmd.Flag.Lookup("exclude").Value.Get().(string),
		cmd.Flag.Lookup("revision").Value.Get().(string),
		cmd.Flag.Lookup("no-trunk").Value.Get().(bool),
		cmd.Flag.Lookup("no-branches").Value.Get().(bool),
		cmd.Flag.Lookup("no-tags").Value.Get().(bool),
		cmd.Flag.Lookup("authors").Value.Get().(string),
	)

	if ctx.RootIsTrunk {
		ctx.Trunk = ""
		ctx.Branches = ""
		ctx.Tags = ""
	}

	if ctx.NoTrunk {
		ctx.Trunk = ""
	}

	if ctx.NoBranches {
		ctx.Branches = ""
	}

	if ctx.NoTags {
		ctx.Tags = ""
	}

	if ctx.Verbose {
		fmt.Printf("==go-svn2git...\n")
		fmt.Printf(" verbose:  %v\n", ctx.Verbose)
		fmt.Printf(" rebase:   %v\n", ctx.Rebase)
		fmt.Printf(" username: %q\n", ctx.UserName)
		fmt.Printf(" trunk:    %q\n", ctx.Trunk)
		fmt.Printf(" branches: %q\n", ctx.Branches)
		fmt.Printf(" tags:     %q\n", ctx.Tags)
		fmt.Printf(" authors:  %q\n", ctx.Authors)
		fmt.Printf(" root-is-trunk: %v\n", ctx.RootIsTrunk)
		fmt.Printf(" exclude:  %q\n", ctx.Exclude)
	}

	if ctx.Rebase {
		if len(args) > 0 {
			fmt.Printf("%s: too many arguments\n", n)
			fmt.Printf("%s: \"-rebase\" takes no argument\n", n)
			//git_svn_usage()
			git := exec.Command("git", "status", "--porcelain", "--untracked-files=no")
			out, err := git.CombinedOutput()
			if len(out) != 0 {
				fmt.Printf("%s: you have pending changes. The working tree must be clean in order to continue.\n", n)
			}
			handle_err(err)
		}
	} else {
		ok := true
		switch len(args) {
		case 0:
			fmt.Printf("%s: missing SVN_URL parameter\n", n)
			ok = false
		case 1:
			/*noop*/
		default:
			fmt.Printf("%s: too many arguments: %v\n", n, args)
			fmt.Printf("%s: did you pass an option *after* the url ?\n", n)
			ok = false
		}
		if !ok {
			fmt.Printf("%s: \"-help\" for help\n", n)
			os.Exit(1)
		}
		ctx.Url = args[0]
	}

	err = ctx.Run()
	handle_err(err)
}