gitx

package
v0.0.0-...-de7e16a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UpdateNoPush = &gcli.Command{
		Name: "update",
		Desc: "Update codes from origin and main remote repositories",
		Func: handleUpdatePush,

		Aliases: []string{"up"},
		Config: func(c *gcli.Command) {
			c.BoolOpt(&gfUpOpts.push, "push", "p", false, "Push to origin remote after update")
		},
	}

	UpdateAndPush = &gcli.Command{
		Name: "update-push",
		Desc: "Update codes from origin and main remote repositories, then push to remote",
		Func: handleUpdatePush,

		Aliases: []string{"upp", "up-push"},
	}
)
View Source
var AddCommitNotPush = &gcli.Command{
	Name: "ac",
	Desc: "run git add/commit at once command",
	Func: acpHandleFunc,
	Config: func(c *gcli.Command) {
		bindCommonFlags(c)

		c.BoolOpt(&confirm, "interactive", "i", false, "confirm ask before executing command")
		c.StrOpt(&acpOpts.message, "message", "m", "", "the commit message")
		c.Required("message")

		c.BindArg(&gcli.CliArg{
			Name:    "files",
			Desc:    "Only add special files. default will add all changed files",
			Arrayed: true,
		})
	},
}

AddCommitNotPush command

View Source
var AddCommitPush = &gcli.Command{
	Name: "acp",
	Desc: "run `git add/commit/push` at once command",
	Func: acpHandleFunc,
	Config: func(c *gcli.Command) {
		AddCommitNotPush.Config(c)

		c.BoolOpt(&acpOpts.notPush, "not-push", "np", false, "dont execute git push")
	},
}

AddCommitPush command

View Source
var BatchPull = &gcli.Command{
	Name:    "bpull",
	Desc:    "batch pull multi git directory by `git pull`",
	Aliases: []string{"bp", "bpul", "batch-pull"},
	Config: func(c *gcli.Command) {
		c.
			AddArg("baseDir", "base directory for run batch pull, default is work dir").
			WithValue("./")

		c.VarOpt(&bpullOpts.dirs, "dirs", "", "limit update the given dir names")
	},
	Func: func(c *gcli.Command, args []string) error {
		baseDir := c.Arg("baseDir").String()
		absDir, err := filepath.Abs(baseDir)
		if err != nil {
			return err
		}

		dirNames := bpullOpts.dirs.Split(",")

		dump.P(dirNames, baseDir, absDir)

		return nil
	},
}
View Source
var BranchOperateEx = &gcli.Command{
	Name:    "branch",
	Desc:    "checkout an new branch for development from `dist` remote",
	Aliases: []string{"br"},

	Subs: []*gcli.Command{
		DeleteBranch,
		CreateBranch,
	},
}
View Source
var (
	Changelog = &gcli.Command{
		Name:    "chlog",
		Desc:    "batch pull multi git directory by `git pull`",
		Aliases: []string{"cl", "clog", "changelog"},
		Examples: `
  {$binWithCmd} last head
  {$binWithCmd} last head --style gh-release --no-merges
  {$binWithPath} v2.0.9 v2.0.10 --no-merges --style gh-release --exclude "cs-fixer,format codes"
`,
		Config: func(c *gcli.Command) {
			c.AddArg("oldVersion", `The old version. eg: v1.0.2, 349238b
- keywords 'last/latest' will auto use latest tag
- keywords 'prev/previous' will auto use previous tag`).
				WithFn(func(arg *gcli.Argument) {
					arg.Required = true
				})

			c.AddArg("newVersion", `The new version. eg: v1.2.2, 66c0df1
- keywords 'head' will auto use Head commit`).
				WithFn(func(arg *gcli.Argument) {
					arg.Required = true
				})

			c.VarOpt(&chlogOpts.limit, "limit", "", "limit update the given dir names")
			c.StrOpt(&chlogOpts.dstFile, "file", "", "", "Export changelog message to the file, default dump to stdout")
			c.StrOpt(&chlogOpts.repoUrl, "repo-url", "", "", `
The git repo URL address. eg: https://github.com/inhere/kite
 default will auto use current git origin remote url
`)
			c.StrOpt(&chlogOpts.style, "style", "s", "default", `
The style for generate for changelog.
 allow: markdown(md), simple, gh-release(ghr)
`)
			c.BoolOpt(&chlogOpts.fetchTags, "fetch-tags", "", false, "Update repo tags list by 'git fetch --tags'")
			c.BoolOpt(&chlogOpts.noMerges, "no-merges", "", false, "dont contains merge request logs")
			c.BoolOpt(&chlogOpts.unShallow, "unshallow", "", false, "Convert to a complete warehouse, useful on GitHub Action.")
		},
		Func: func(c *gcli.Command, args []string) error {
			baseDir := c.Arg("baseDir").String()
			absDir, err := filepath.Abs(baseDir)
			if err != nil {
				return err
			}

			repo := gitw.NewRepo(absDir)
			dump.P(repo.DefaultRemoteInfo())

			cl := chlog.New()
			cl.Formatter = &chlog.MarkdownFormatter{
				RepoURL: "https://github.com/gookit/gitw",
			}

			cl.WithConfigFn(func(c *chlog.Config) {
				c.GroupPrefix = "\n### "
				c.GroupSuffix = "\n"
			})

			chlogOpts.sha1 = c.Arg("oldVersion").String()
			chlogOpts.sha2 = c.Arg("newVersion").String()
			dump.P(chlogOpts)

			cl.FetchGitLog(chlogOpts.sha1, chlogOpts.sha2, "--no-merges")

			if err = cl.Generate(); err != nil {
				return err
			}

			dump.P(cl.Changelog())

			return nil
		},
	}
)
View Source
var CreateBranch = &gcli.Command{
	Name:    "new",
	Desc:    "checkout an new branch for development from `dist` remote",
	Aliases: []string{"n", "create"},
}
View Source
var CreatePRLink = &gcli.Command{
	Name:    "pr-link",
	Desc:    "create pull request link for current project",
	Aliases: []string{"pr"},
}
View Source
var DeleteBranch = &gcli.Command{
	Name:    "del",
	Desc:    "checkout an new branch for development from `dist` remote",
	Aliases: []string{"d", "rm", "delete"},
}
View Source
var GitCommands = &gcli.Command{
	Name:    "git",
	Desc:    "tools for quick use `git` commands",
	Aliases: []string{"g"},
	Subs: []*gcli.Command{
		StatusInfo,
		RemoteInfo,
		AddCommitPush,
		AddCommitNotPush,
		TagCmd,
		UpdateCmd,
		gituse.OpenRemoteRepo,
		CreatePRLink,
		BatchPull,
		Changelog,
		ShowLog,
	},
	Config: func(c *gcli.Command) {
		addListener(c)

		c.BoolOpt(&dryRun, "dry-run", "", false, "Dry-run the workflow, dont real execute")
		c.BoolOpt(&yesRun, "yes", "y", false, "Direct execution without confirmation")
	},
}

GitCommands commands for use git

View Source
var GitFlow = &gcli.Command{
	Name: "gitflow",
	Desc: "tool commands for git-flow development",
	Subs: []*gcli.Command{
		InitFlow,
		CreatePRLink,
		UpdateNoPush,
		UpdateAndPush,
		BranchOperateEx,
	},

	Aliases: []string{"gflow", "gf"},
	Config: func(c *gcli.Command) {
		c.BoolOpt(&dryRun, "dry-run", "", false, "Dry-run the workflow, dont real execute")
		c.BoolOpt(&yesRun, "yes", "y", false, "Direct execution without confirmation")
	},
}
View Source
var InitFlow = &gcli.Command{
	Name: "init",
	Desc: "init repo remote and other info for current project",
}
View Source
var RemoteInfo = &gcli.Command{
	Name:    "remote",
	Aliases: []string{"rmt"},
	Desc:    "git remote command",
	Func: func(c *gcli.Command, args []string) error {
		err := gitw.New("remote", "-v").Run()
		if err != nil {
			return err
		}

		return nil
	},
}
View Source
var (
	ShowLog = &gcli.Command{
		Name: "log",
		Desc: "display recently git commits information by `git log`",

		Config: func(c *gcli.Command) {
			c.UseSimpleRule()

			goutil.PanicIfErr(c.FromStruct(&logOpts))

			c.StrOpt(&logOpts.Format, "format", "", "",
				"The git log option '--pretty' value.\n"+
					"can be one of oneline, short, medium, full, fuller, reference, email, raw, format:string and tformat:string.",
			)

			c.AddArg("maxCommit", "Max display how many commits")
		},
		Func: func(c *gcli.Command, args []string) error {
			maxNum := c.Arg("maxCommit").Int()

			gitLog := gitw.New("log", "--graph")
			gitLog.OnBeforeExec(gitw.PrintCmdline)

			gitLog.Argf("-%d", maxNum)
			gitLog.ArgIf("--color", !logOpts.NoColor)
			gitLog.ArgIf("--no-merges", logOpts.NoMerges)
			gitLog.ArgIf("--abbrev-commit", logOpts.Abbrev)
			gitLog.Add(`--pretty=format:%Cred%h%Creset:%C(ul yellow)%d%Creset %s (%Cgreen%cr%Creset, %C(bold blue)%an%Creset)`)

			return gitLog.Run()
		},
	}
)
View Source
var StatusInfo = &gcli.Command{
	Name:    "status",
	Aliases: []string{"st"},
	Desc:    "git status command",
	Func: func(c *gcli.Command, args []string) error {
		return cmdr.NewGitCmd("status").Run()
	},
}
View Source
var TagCmd = &gcli.Command{
	Name: "tag",
	Desc: "git tag commands",
	Subs: []*gcli.Command{
		TagCreate,
		TagDelete,
	},
}
View Source
var TagCreate = &gcli.Command{
	Name:    "create",
	Aliases: []string{"new"},
	Desc:    "create new tag by `git tag`",
	Func: func(c *gcli.Command, args []string) error {
		return errors.New("TODO")
	},
}
View Source
var TagDelete = &gcli.Command{
	Name:    "delete",
	Aliases: []string{"del", "rm", "remove"},
	Desc:    "delete exists tags by `git tag`",
	Func: func(c *gcli.Command, args []string) error {
		return errors.New("TODO")
	},
}
View Source
var UpdateCmd = &gcli.Command{
	Name:    "update",
	Desc:    "Update codes from git remote repositories",
	Aliases: []string{"up", "pul", "pull"},
	Config: func(c *gcli.Command) {
		bindCommonFlags(c)
	},
	Func: func(c *gcli.Command, args []string) error {
		pull := gitw.NewWithArgs("pull", args...)
		pull.WithWorkDir(workdir)

		return pull.Run()
	},
}

UpdateCmd command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL