From 60d429070355922d7bcf7261009c98c97196a1c9 Mon Sep 17 00:00:00 2001
From: cdryzun <yangzun@treesir.pub>
Date: Sat, 23 Dec 2023 21:28:11 +0800
Subject: [PATCH] add branch arg

---
 README.md  | 5 ++++-
 cmd/raw.go | 6 +++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 290a57a..27c5f98 100644
--- a/README.md
+++ b/README.md
@@ -3,4 +3,7 @@
 
 # Release Notes
 v0.1.0
- - Add gitlab to get the content of a specified file in the repository and save it locally.
\ No newline at end of file
+ - Add gitlab to get the content of a specified file in the repository and save it locally.
+
+v0.1.1
+ - Add branch argument to specify the branch of the repository.
\ No newline at end of file
diff --git a/cmd/raw.go b/cmd/raw.go
index 561276f..8a5667f 100644
--- a/cmd/raw.go
+++ b/cmd/raw.go
@@ -14,6 +14,7 @@ var (
 	url            string
 	getFilePath    string
 	outputfilePath string
+	branch         string
 )
 
 var rawCmd = &cobra.Command{
@@ -28,7 +29,7 @@ var rawCmd = &cobra.Command{
 		}
 
 		// 获取仓库中指定文件的内容
-		file, _, err := client.RepositoryFiles.GetRawFile(pid, getFilePath, nil)
+		file, _, err := client.RepositoryFiles.GetRawFile(pid, getFilePath, &gitlab.GetRawFileOptions{Ref: gitlab.String(branch)})
 		if err != nil {
 			log.Fatal(err)
 		}
@@ -47,9 +48,12 @@ func init() {
 	rawCmd.Flags().StringVarP(&url, "url", "u", "", "The url of gitlab.")
 	rawCmd.Flags().StringVarP(&getFilePath, "getfile-path", "g", "", "The getfile path.")
 	rawCmd.Flags().StringVarP(&outputfilePath, "outputfile-path", "o", "", "The outputfile path.")
+	rawCmd.Flags().StringVarP(&branch, "branch", "b", "main", "The project branch of gitlab.")
 	rawCmd.MarkFlagRequired("project-id")
 	rawCmd.MarkFlagRequired("token")
 	rawCmd.MarkFlagRequired("url")
 	rawCmd.MarkFlagRequired("outputfile-path")
 	rawCmd.MarkFlagRequired("getfile-path")
+	rawCmd.MarkFlagRequired("branch")
+
 }