#429 Depth param for clone
Merged 5 years ago by onosek. Opened 5 years ago by onosek.
onosek/rpkg clone_depth  into  master

file modified
+11 -3
@@ -1474,7 +1474,7 @@ 

          return

  

      def clone(self, repo, path=None, branch=None, bare_dir=None,

-               anon=False, target=None):

+               anon=False, target=None, depth=None):

          """Clone a repo, optionally check out a specific branch.

  

          :param str repo: the name of the repository to clone.
@@ -1487,6 +1487,8 @@ 

              `False`.

          :param str target: an optional name of the folder in which to clone the

              repo.

+         :param int depth: create a shallow clone with a history truncated

+             to the specified number of commits.

          """

  

          if not path:
@@ -1503,6 +1505,10 @@ 

          cmd = ['git', 'clone']

          if self.quiet:

              cmd.append('-q')

+         if depth:

+             # argument '--depth' goes with '--no-single-branch' together

+             # to apply history truncation to all cloned branches

+             cmd.extend(['--depth', depth, "--no-single-branch"])

          # do the clone

          if branch and bare_dir:

              raise rpkgError('Cannot combine bare cloning with a branch')
@@ -1548,7 +1554,7 @@ 

              return repo.split("/")[-1]

          return repo

  

-     def clone_with_dirs(self, repo, anon=False, target=None):

+     def clone_with_dirs(self, repo, anon=False, target=None, depth=None):

          """Clone a repo old style with subdirs for each branch.

  

          :param str repo: name of the repository to clone.
@@ -1556,6 +1562,8 @@ 

              `False`.

          :param str target: an optional name of the folder in which to clone the

              repo.

+         :param int depth: create a shallow clone with a history truncated

+             to the specified number of commits.

          """

  

          self._push_url = None
@@ -1581,7 +1589,7 @@ 

  

          # Create a bare clone first. This gives us a good list of branches

          try:

-             self.clone(repo, top_path, bare_dir=repo_path, anon=anon)

+             self.clone(repo, top_path, bare_dir=repo_path, anon=anon, depth=depth)

          except Exception as e:

              # Clean out our directory

              shutil.rmtree(top_path)

file modified
+16 -2
@@ -644,6 +644,18 @@ 

          clone_parser.add_argument(

              "clone_target", default=None, nargs="?",

              help='Directory in which to clone the repository')

+ 

+         def validator_integer_string(raw_value):

+             """checks if input is string that contains integer number"""

+             try:

+                 value = str(int(raw_value))

+             except (ValueError, TypeError):

+                 raise argparse.ArgumentTypeError("argument has to be a number")

+             return value

+         clone_parser.add_argument(

+             '--depth', type=validator_integer_string,

+             help='Create a shallow clone with a history truncated '

+                  'to the specified number of commits')

          clone_parser.set_defaults(command=self.clone)

  

          # Add an alias for historical reasons
@@ -1762,12 +1774,14 @@ 

          if self.args.branches:

              self.cmd.clone_with_dirs(self.args.repo[0],

                                       anon=self.args.anonymous,

-                                      target=self.args.clone_target)

+                                      target=self.args.clone_target,

+                                      depth=self.args.depth)

          else:

              self.cmd.clone(self.args.repo[0],

                             branch=self.args.branch,

                             anon=self.args.anonymous,

-                            target=self.args.clone_target)

+                            target=self.args.clone_target,

+                            depth=self.args.depth)

  

      def commit(self):

          if self.args.with_changelog and not self.args.message:

Added '--depth' argument for 'git clone' command. It creates a shallow clone
with a history truncated to the specified number of commits. Additional
parameter '--no-single-branch' is added together with '--depth' to apply
history truncation to all cloned branches.

JIRA: COMPOSE-2812
Fixes: #363

Signed-off-by: Ondrej Nosek onosek@redhat.com

Is this needed? As I understand it, when cloning with branches, rpkg will do one clone from dist-git (via self.clone) to a local location, and then for each branch create a new clone from this local copy. So there should be no history to clone even without --depth, no?

argument has to be a number

rebased onto 39fc691a3030fd9b8eb353a00aa4711c50cd9cf9

5 years ago

rebased onto 94b381f

5 years ago

Pull-Request has been merged by onosek

5 years ago